本文整理汇总了C++中nsAFlatCString::IsEmpty方法的典型用法代码示例。如果您正苦于以下问题:C++ nsAFlatCString::IsEmpty方法的具体用法?C++ nsAFlatCString::IsEmpty怎么用?C++ nsAFlatCString::IsEmpty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nsAFlatCString
的用法示例。
在下文中一共展示了nsAFlatCString::IsEmpty方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: convertURItoUnicode
nsresult nsTextToSubURI::convertURItoUnicode(const nsAFlatCString &aCharset,
const nsAFlatCString &aURI,
bool aIRI,
nsAString &_retval)
{
nsresult rv = NS_OK;
// check for 7bit encoding the data may not be ASCII after we decode
bool isStatefulCharset = statefulCharset(aCharset.get());
if (!isStatefulCharset && IsASCII(aURI)) {
CopyASCIItoUTF16(aURI, _retval);
return rv;
}
if (!isStatefulCharset && aIRI) {
if (IsUTF8(aURI)) {
CopyUTF8toUTF16(aURI, _retval);
return rv;
}
}
// empty charset could indicate UTF-8, but aURI turns out not to be UTF-8.
NS_ENSURE_FALSE(aCharset.IsEmpty(), NS_ERROR_INVALID_ARG);
nsCOMPtr<nsICharsetConverterManager> charsetConverterManager;
charsetConverterManager = do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIUnicodeDecoder> unicodeDecoder;
rv = charsetConverterManager->GetUnicodeDecoder(aCharset.get(),
getter_AddRefs(unicodeDecoder));
NS_ENSURE_SUCCESS(rv, rv);
unicodeDecoder->SetInputErrorBehavior(nsIUnicodeDecoder::kOnError_Signal);
int32_t srcLen = aURI.Length();
int32_t dstLen;
rv = unicodeDecoder->GetMaxLength(aURI.get(), srcLen, &dstLen);
NS_ENSURE_SUCCESS(rv, rv);
char16_t *ustr = (char16_t *) NS_Alloc(dstLen * sizeof(char16_t));
NS_ENSURE_TRUE(ustr, NS_ERROR_OUT_OF_MEMORY);
rv = unicodeDecoder->Convert(aURI.get(), &srcLen, ustr, &dstLen);
if (NS_SUCCEEDED(rv))
_retval.Assign(ustr, dstLen);
NS_Free(ustr);
return rv;
}
示例2: convertURItoUnicode
nsresult nsTextToSubURI::convertURItoUnicode(const nsAFlatCString &aCharset,
const nsAFlatCString &aURI,
nsAString &_retval)
{
// check for 7bit encoding the data may not be ASCII after we decode
bool isStatefulCharset = statefulCharset(aCharset.get());
if (!isStatefulCharset) {
if (IsASCII(aURI)) {
CopyASCIItoUTF16(aURI, _retval);
return NS_OK;
}
if (IsUTF8(aURI)) {
CopyUTF8toUTF16(aURI, _retval);
return NS_OK;
}
}
// empty charset could indicate UTF-8, but aURI turns out not to be UTF-8.
NS_ENSURE_FALSE(aCharset.IsEmpty(), NS_ERROR_INVALID_ARG);
nsAutoCString encoding;
if (!EncodingUtils::FindEncodingForLabelNoReplacement(aCharset, encoding)) {
return NS_ERROR_UCONV_NOCONV;
}
nsCOMPtr<nsIUnicodeDecoder> unicodeDecoder =
EncodingUtils::DecoderForEncoding(encoding);
unicodeDecoder->SetInputErrorBehavior(nsIUnicodeDecoder::kOnError_Signal);
int32_t srcLen = aURI.Length();
int32_t dstLen;
nsresult rv = unicodeDecoder->GetMaxLength(aURI.get(), srcLen, &dstLen);
NS_ENSURE_SUCCESS(rv, rv);
char16_t *ustr = (char16_t *) moz_xmalloc(dstLen * sizeof(char16_t));
NS_ENSURE_TRUE(ustr, NS_ERROR_OUT_OF_MEMORY);
rv = unicodeDecoder->Convert(aURI.get(), &srcLen, ustr, &dstLen);
if (NS_SUCCEEDED(rv))
_retval.Assign(ustr, dstLen);
free(ustr);
return rv;
}