本文整理汇总了C++中nsAFlatCString::Length方法的典型用法代码示例。如果您正苦于以下问题:C++ nsAFlatCString::Length方法的具体用法?C++ nsAFlatCString::Length怎么用?C++ nsAFlatCString::Length使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nsAFlatCString
的用法示例。
在下文中一共展示了nsAFlatCString::Length方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
extern "C" NS_GFX_(void) NS_RGBToASCIIHex(nscolor aColor,
nsAFlatCString& aResult)
{
aResult.SetLength(7);
NS_ASSERTION(aResult.Length() == 7, "small SetLength failed, use an autostring instead!");
char *buf = aResult.BeginWriting();
PR_snprintf(buf, 8, "#%02x%02x%02x",
NS_GET_R(aColor), NS_GET_G(aColor), NS_GET_B(aColor));
}
示例2: 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;
}
示例3: 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;
}
示例4: validOperator
bool validOperator(nsAFlatCString& aString) {
bool result=false;
int len=aString.Length();
switch(len) {
case 1: return true;
case 3:
result=(aString.Equals(NS_LITERAL_CSTRING("<<=")) ||
aString.Equals(NS_LITERAL_CSTRING(">>=")));
break;
default:
switch(aString[0]) {
case '+': case '=':
case '&': case '|':
case '<': case '>':
if((aString[1]==aString[0]) || (aString[1]=='='))
result=true;
break;
case '-':
if((aString[1]==aString[0]) || (aString[1]=='>'))
result=true;
break;
case ':':
if((len==2) && (aString[1]==aString[0]))
result=true;
break;
case '*':
case '/':
case '^':
case '!':
case '~':
case '%':
if((aString[1]=='='))
result=true;
break;
case '(':
result=aString[1]==')'; break;
case '[':
result=aString[1]==']'; break;
default:
break;
}
break;
}
return result;
}
示例5:
static nsresult ConvertToUTF8(nsIUnicodeDecoder *aUnicodeDecoder,
nsAFlatCString& aString)
{
int32_t numberOfBytes = aString.Length();
int32_t outUnicodeLen;
nsAutoString buffer;
nsresult rv = aUnicodeDecoder->GetMaxLength(aString.get(), numberOfBytes,
&outUnicodeLen);
NS_ENSURE_SUCCESS(rv, rv);
if (!EnsureStringLength(buffer, outUnicodeLen))
return NS_ERROR_OUT_OF_MEMORY;
rv = aUnicodeDecoder->Convert(aString.get(), &numberOfBytes,
buffer.BeginWriting(), &outUnicodeLen);
NS_ENSURE_SUCCESS(rv, rv);
buffer.SetLength(outUnicodeLen);
CopyUTF16toUTF8(buffer, aString);
return NS_OK;
}
示例6: SetData
//----------------------------------------------------------------------------------------
void nsPersistentFileDescriptor::SetData(const nsAFlatCString& inData)
//----------------------------------------------------------------------------------------
{
mDescriptorString.CopyFrom(inData.get(), inData.Length());
}