本文整理汇总了C++中nsACString::Length方法的典型用法代码示例。如果您正苦于以下问题:C++ nsACString::Length方法的具体用法?C++ nsACString::Length怎么用?C++ nsACString::Length使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nsACString
的用法示例。
在下文中一共展示了nsACString::Length方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Substring
// Is path1 a prefix, and thus a parent, of path2? Eg. "a/b" is a parent of
// "a/b/c", but "a/bb" is not.
static bool
isParent(const nsACString &path1, const nsACString &path2)
{
if (path1.Length() >= path2.Length())
return false;
const nsACString& subStr = Substring(path2, 0, path1.Length());
return subStr.Equals(path1) && path2[path1.Length()] == '/';
}
示例2: Substring
bool
StringEndsWith(const nsACString& aSource, const nsACString& aSubstring)
{
nsACString::size_type src_len = aSource.Length(),
sub_len = aSubstring.Length();
if (sub_len > src_len) {
return false;
}
return Substring(aSource, src_len - sub_len, sub_len).Equals(aSubstring);
}
示例3: decodeACE
nsresult nsIDNService::decodeACE(const nsACString& in, nsACString& out,
stringPrepFlag flag)
{
bool isAce;
IsACE(in, &isAce);
if (!isAce) {
out.Assign(in);
return NS_OK;
}
nsAutoString utf16;
#ifdef IDNA2008
nsresult result = IDNA2008ToUnicode(in, utf16);
NS_ENSURE_SUCCESS(result, result);
#else
// RFC 3490 - 4.2 ToUnicode
// The ToUnicode output never contains more code points than its input.
punycode_uint output_length = in.Length() - kACEPrefixLen + 1;
punycode_uint *output = new punycode_uint[output_length];
NS_ENSURE_TRUE(output, NS_ERROR_OUT_OF_MEMORY);
enum punycode_status status = punycode_decode(in.Length() - kACEPrefixLen,
PromiseFlatCString(in).get() + kACEPrefixLen,
&output_length,
output,
nullptr);
if (status != punycode_success) {
delete [] output;
return NS_ERROR_FAILURE;
}
// UCS4 -> UTF8
output[output_length] = 0;
ucs4toUtf16(output, utf16);
delete [] output;
#endif
if (flag != eStringPrepForUI || isLabelSafe(utf16)) {
CopyUTF16toUTF8(utf16, out);
} else {
out.Assign(in);
return NS_OK;
}
// Validation: encode back to ACE and compare the strings
nsAutoCString ace;
nsresult rv = UTF8toACE(out, ace, flag);
NS_ENSURE_SUCCESS(rv, rv);
if (flag == eStringPrepForDNS &&
!ace.Equals(in, nsCaseInsensitiveCStringComparator())) {
return NS_ERROR_FAILURE;
}
return NS_OK;
}
示例4: SendSocketData
bool
BluetoothSocket::SendSocketData(const nsACString& aStr)
{
if (aStr.Length() > MAX_READ_SIZE) {
return false;
}
SendSocketData(new UnixSocketRawData(aStr.BeginReading(), aStr.Length()));
return true;
}
示例5: printf
NS_IMETHODIMP
nsMimeBaseEmitter::Write(const nsACString &buf, PRUint32 *amountWritten)
{
unsigned int written = 0;
nsresult rv = NS_OK;
PRUint32 needToWrite;
#ifdef DEBUG_BenB
// If you want to see libmime output...
printf("%s", buf);
#endif
PR_LOG(gMimeEmitterLogModule, PR_LOG_ALWAYS, (PromiseFlatCString(buf).get()));
//
// Make sure that the buffer we are "pushing" into has enough room
// for the write operation. If not, we have to buffer, return, and get
// it on the next time through
//
*amountWritten = 0;
needToWrite = mBufferMgr->GetSize();
// First, handle any old buffer data...
if (needToWrite > 0)
{
rv = WriteHelper(mBufferMgr->GetBuffer(), needToWrite, &written);
mTotalWritten += written;
mBufferMgr->ReduceBuffer(written);
*amountWritten = written;
// if we couldn't write all the old data, buffer the new data
// and return
if (mBufferMgr->GetSize() > 0)
{
mBufferMgr->IncreaseBuffer(buf.BeginReading(), buf.Length());
return rv;
}
}
// if we get here, we are dealing with new data...try to write
// and then do the right thing...
rv = WriteHelper(buf.BeginReading(), buf.Length(), &written);
*amountWritten = written;
mTotalWritten += written;
if (written < buf.Length()) {
const nsACString &remainder = Substring(buf, written);
mBufferMgr->IncreaseBuffer(remainder.BeginReading(), remainder.Length());
}
return rv;
}
示例6:
nsCString
PendingLookup::EscapeFingerprint(const nsACString& aFingerprint)
{
// Google's fingerprint doesn't have colons
nsCString escaped;
escaped.SetCapacity(aFingerprint.Length());
for (unsigned int i = 0; i < aFingerprint.Length(); ++i) {
if (aFingerprint.Data()[i] != ':') {
escaped.Append(aFingerprint.Data()[i]);
}
}
return escaped;
}
示例7:
NS_CStringGetMutableData(nsACString& aStr, uint32_t aDataLength, char** aData)
{
if (aDataLength != UINT32_MAX) {
aStr.SetLength(aDataLength);
if (aStr.Length() != aDataLength) {
*aData = nullptr;
return 0;
}
}
*aData = aStr.BeginWriting();
return aStr.Length();
}
示例8: decodeACE
nsresult nsIDNService::decodeACE(const nsACString& in, nsACString& out,
bool allowUnassigned, bool convertAllLabels)
{
bool isAce;
IsACE(in, &isAce);
if (!isAce) {
out.Assign(in);
return NS_OK;
}
// RFC 3490 - 4.2 ToUnicode
// The ToUnicode output never contains more code points than its input.
punycode_uint output_length = in.Length() - kACEPrefixLen + 1;
punycode_uint *output = new punycode_uint[output_length];
NS_ENSURE_TRUE(output, NS_ERROR_OUT_OF_MEMORY);
enum punycode_status status = punycode_decode(in.Length() - kACEPrefixLen,
PromiseFlatCString(in).get() + kACEPrefixLen,
&output_length,
output,
nullptr);
if (status != punycode_success) {
delete [] output;
return NS_ERROR_FAILURE;
}
// UCS4 -> UTF8
output[output_length] = 0;
nsAutoString utf16;
ucs4toUtf16(output, utf16);
delete [] output;
if (!convertAllLabels && !isLabelSafe(utf16)) {
out.Assign(in);
return NS_OK;
}
if (!isOnlySafeChars(utf16, mIDNBlacklist))
return NS_ERROR_FAILURE;
CopyUTF16toUTF8(utf16, out);
// Validation: encode back to ACE and compare the strings
nsAutoCString ace;
nsresult rv = UTF8toACE(out, ace, allowUnassigned, true);
NS_ENSURE_SUCCESS(rv, rv);
if (!ace.Equals(in, nsCaseInsensitiveCStringComparator()))
return NS_ERROR_FAILURE;
return NS_OK;
}
示例9: nsDependentCString
NS_CStringSetDataRange(nsACString& aStr,
uint32_t aCutOffset, uint32_t aCutLength,
const char* aData, uint32_t aDataLength)
{
if (aCutOffset == UINT32_MAX) {
// append case
if (aData) {
aStr.Append(aData, aDataLength);
}
return NS_OK; // XXX report errors
}
if (aCutLength == UINT32_MAX) {
aCutLength = aStr.Length() - aCutOffset;
}
if (aData) {
if (aDataLength == UINT32_MAX) {
aStr.Replace(aCutOffset, aCutLength, nsDependentCString(aData));
} else {
aStr.Replace(aCutOffset, aCutLength, Substring(aData, aDataLength));
}
} else {
aStr.Cut(aCutOffset, aCutLength);
}
return NS_OK; // XXX report errors
}
示例10: label
static nsresult
ToUTF8(const nsACString &aString, const char *aCharset,
bool aAllowSubstitution, nsACString &aResult)
{
nsresult rv;
if (!aCharset || !*aCharset)
return NS_ERROR_INVALID_ARG;
nsDependentCString label(aCharset);
nsAutoCString encoding;
if (!EncodingUtils::FindEncodingForLabelNoReplacement(label, encoding)) {
return NS_ERROR_UCONV_NOCONV;
}
nsCOMPtr<nsIUnicodeDecoder> unicodeDecoder =
EncodingUtils::DecoderForEncoding(encoding);
if (!aAllowSubstitution)
unicodeDecoder->SetInputErrorBehavior(nsIUnicodeDecoder::kOnError_Signal);
int32_t srcLen = aString.Length();
int32_t dstLen;
const nsAFlatCString& inStr = PromiseFlatCString(aString);
rv = unicodeDecoder->GetMaxLength(inStr.get(), srcLen, &dstLen);
NS_ENSURE_SUCCESS(rv, rv);
auto ustr = mozilla::MakeUnique<char16_t[]>(dstLen);
NS_ENSURE_TRUE(ustr, NS_ERROR_OUT_OF_MEMORY);
rv = unicodeDecoder->Convert(inStr.get(), &srcLen, ustr.get(), &dstLen);
if (NS_SUCCEEDED(rv)){
CopyUTF16toUTF8(Substring(ustr.get(), ustr.get() + dstLen), aResult);
}
return rv;
}
示例11: transaction
NS_IMETHODIMP
nsAnnotationService::SetAnnotationBinary(nsIURI* aURI,
const nsACString& aName,
const PRUint8 *aData,
PRUint32 aDataLen,
const nsACString& aMimeType,
PRInt32 aFlags, PRInt32 aExpiration)
{
if (aMimeType.Length() == 0)
return NS_ERROR_INVALID_ARG;
mozStorageTransaction transaction(mDBConn, PR_FALSE);
mozIStorageStatement* statement; // class var, not owned by this function
nsresult rv = StartSetAnnotation(aURI, aName, aFlags, aExpiration, &statement);
NS_ENSURE_SUCCESS(rv, rv);
mozStorageStatementScoper statementResetter(statement);
rv = statement->BindBlobParameter(kAnnoIndex_Content, aData, aDataLen);
NS_ENSURE_SUCCESS(rv, rv);
rv = statement->BindUTF8StringParameter(kAnnoIndex_MimeType, aMimeType);
NS_ENSURE_SUCCESS(rv, rv);
rv = statement->Execute();
NS_ENSURE_SUCCESS(rv, rv);
transaction.Commit();
// should reset the statement; observers may call our service back to get
// annotation values!
statement->Reset();
statementResetter.Abandon();
CallSetObservers(aURI, aName);
return NS_OK;
}
示例12: converter
bool
AppendUTF16toUTF8( const nsAString& aSource, nsACString& aDest,
const mozilla::fallible_t& )
{
nsAString::const_iterator source_start, source_end;
CalculateUTF8Size calculator;
copy_string(aSource.BeginReading(source_start),
aSource.EndReading(source_end), calculator);
uint32_t count = calculator.Size();
if (count)
{
uint32_t old_dest_length = aDest.Length();
// Grow the buffer if we need to.
if (!aDest.SetLength(old_dest_length + count, mozilla::fallible_t())) {
return false;
}
// All ready? Time to convert
ConvertUTF16toUTF8 converter(aDest.BeginWriting() + old_dest_length);
copy_string(aSource.BeginReading(source_start),
aSource.EndReading(source_end), converter);
NS_ASSERTION(converter.Size() == count,
"Unexpected disparity between CalculateUTF8Size and "
"ConvertUTF16toUTF8");
}
return true;
}
示例13: stringPrepAndACE
nsresult nsIDNService::stringPrepAndACE(const nsAString& in, nsACString& out)
{
nsresult rv = NS_OK;
out.Truncate();
if (in.Length() > kMaxDNSNodeLen) {
NS_ERROR("IDN node too large");
return NS_ERROR_FAILURE;
}
if (IsASCII(in))
LossyCopyUTF16toASCII(in, out);
else {
nsAutoString strPrep;
rv = stringPrep(in, strPrep);
if (NS_SUCCEEDED(rv)) {
if (IsASCII(strPrep))
LossyCopyUTF16toASCII(strPrep, out);
else
rv = encodeToACE(strPrep, out);
}
}
if (out.Length() > kMaxDNSNodeLen) {
NS_ERROR("IDN node too large");
return NS_ERROR_FAILURE;
}
return rv;
}
示例14:
NS_IMETHODIMP
nsUTF8ConverterService::ConvertURISpecToUTF8(const nsACString &aSpec,
const char *aCharset,
nsACString &aUTF8Spec)
{
// assume UTF-8 if the spec contains unescaped non-ASCII characters.
// No valid spec in Mozilla would break this assumption.
if (!IsASCII(aSpec)) {
aUTF8Spec = aSpec;
return NS_OK;
}
aUTF8Spec.Truncate();
nsAutoCString unescapedSpec;
// NS_UnescapeURL does not fill up unescapedSpec unless there's at least
// one character to unescape.
bool written = NS_UnescapeURL(PromiseFlatCString(aSpec).get(), aSpec.Length(),
esc_OnlyNonASCII, unescapedSpec);
if (!written) {
aUTF8Spec = aSpec;
return NS_OK;
}
// return if ASCII only or escaped UTF-8
if (IsASCII(unescapedSpec) || IsUTF8(unescapedSpec)) {
aUTF8Spec = unescapedSpec;
return NS_OK;
}
return ToUTF8(unescapedSpec, aCharset, true, aUTF8Spec);
}
示例15: switch
void
nsCertOverride::convertStringToBits(const nsACString& str,
/*out*/ OverrideBits& ob)
{
ob = OverrideBits::None;
for (uint32_t i = 0; i < str.Length(); i++) {
switch (str.CharAt(i)) {
case 'm':
case 'M':
ob |= OverrideBits::Mismatch;
break;
case 'u':
case 'U':
ob |= OverrideBits::Untrusted;
break;
case 't':
case 'T':
ob |= OverrideBits::Time;
break;
default:
break;
}
}
}