本文整理汇总了C++中nsACString::Truncate方法的典型用法代码示例。如果您正苦于以下问题:C++ nsACString::Truncate方法的具体用法?C++ nsACString::Truncate怎么用?C++ nsACString::Truncate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nsACString
的用法示例。
在下文中一共展示了nsACString::Truncate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
void
nsCertOverride::convertBitsToString(OverrideBits ob, nsACString &str)
{
str.Truncate();
if (ob & ob_Mismatch)
str.Append('M');
if (ob & ob_Untrusted)
str.Append('U');
if (ob & ob_Time_error)
str.Append('T');
}
示例2: InitXHDR
NS_IMETHODIMP
nsNNTPNewsgroupList::InitXHDR(nsACString &header)
{
if (++m_currentXHDRIndex >= m_filterHeaders.Length())
header.Truncate();
else
header.Assign(m_filterHeaders[m_currentXHDRIndex]);
// Don't include these in our XHDR bouts, as they are already provided through
// XOVER.
if (header.EqualsLiteral("message-id") ||
header.EqualsLiteral("references"))
return InitXHDR(header);
return NS_OK;
}
示例3: PrepareForNext
NS_IMETHODIMP
HttpBaseChannel::nsContentEncodings::GetNext(nsACString& aNextEncoding)
{
aNextEncoding.Truncate();
if (!mReady) {
nsresult rv = PrepareForNext();
if (NS_FAILED(rv)) {
return NS_ERROR_FAILURE;
}
}
const nsACString & encoding = Substring(mCurStart, mCurEnd);
nsACString::const_iterator start, end;
encoding.BeginReading(start);
encoding.EndReading(end);
bool haveType = false;
if (CaseInsensitiveFindInReadable(NS_LITERAL_CSTRING("gzip"), start, end)) {
aNextEncoding.AssignLiteral(APPLICATION_GZIP);
haveType = true;
}
if (!haveType) {
encoding.BeginReading(start);
if (CaseInsensitiveFindInReadable(NS_LITERAL_CSTRING("compress"), start, end)) {
aNextEncoding.AssignLiteral(APPLICATION_COMPRESS);
haveType = true;
}
}
if (!haveType) {
encoding.BeginReading(start);
if (CaseInsensitiveFindInReadable(NS_LITERAL_CSTRING("deflate"), start, end)) {
aNextEncoding.AssignLiteral(APPLICATION_ZIP);
haveType = true;
}
}
// Prepare to fetch the next encoding
mCurEnd = mCurStart;
mReady = false;
if (haveType)
return NS_OK;
NS_WARNING("Unknown encoding type");
return NS_ERROR_FAILURE;
}
示例4: AssembleCacheKey
nsresult _OldStorage::AssembleCacheKey(nsIURI *aURI,
nsACString const & aIdExtension,
nsACString & aCacheKey,
nsACString & aScheme)
{
// Copied from nsHttpChannel::AssembleCacheKey
aCacheKey.Truncate();
nsresult rv;
rv = aURI->GetScheme(aScheme);
NS_ENSURE_SUCCESS(rv, rv);
nsAutoCString uriSpec;
if (aScheme.EqualsLiteral("http") ||
aScheme.EqualsLiteral("https")) {
if (mLoadInfo->IsAnonymous()) {
aCacheKey.AssignLiteral("anon&");
}
if (!aIdExtension.IsEmpty()) {
aCacheKey.AppendPrintf("id=%s&", aIdExtension.BeginReading());
}
nsCOMPtr<nsIURI> noRefURI;
rv = aURI->CloneIgnoringRef(getter_AddRefs(noRefURI));
NS_ENSURE_SUCCESS(rv, rv);
rv = noRefURI->GetAsciiSpec(uriSpec);
NS_ENSURE_SUCCESS(rv, rv);
if (!aCacheKey.IsEmpty()) {
aCacheKey.AppendLiteral("uri=");
}
}
else if (aScheme.EqualsLiteral("wyciwyg")) {
rv = aURI->GetSpec(uriSpec);
NS_ENSURE_SUCCESS(rv, rv);
}
else {
rv = aURI->GetAsciiSpec(uriSpec);
NS_ENSURE_SUCCESS(rv, rv);
}
aCacheKey.Append(uriSpec);
return NS_OK;
}
示例5: ustr
/* ACString ConvertUTF8toACE (in AUTF8String input); */
NS_IMETHODIMP nsIDNService::ConvertUTF8toACE(const nsACString & input, nsACString & ace)
{
// protect against bogus input
NS_ENSURE_TRUE(IsUTF8(input), NS_ERROR_UNEXPECTED);
nsresult rv;
NS_ConvertUTF8toUCS2 ustr(input);
// map ideographic period to ASCII period etc.
normalizeFullStops(ustr);
PRUint32 len, offset;
len = 0;
offset = 0;
nsCAutoString encodedBuf;
nsAString::const_iterator start, end;
ustr.BeginReading(start);
ustr.EndReading(end);
ace.Truncate();
// encode nodes if non ASCII
while (start != end) {
len++;
if (*start++ == (PRUnichar)'.') {
rv = stringPrepAndACE(Substring(ustr, offset, len - 1), encodedBuf);
NS_ENSURE_SUCCESS(rv, rv);
ace.Append(encodedBuf);
ace.Append('.');
offset += len;
len = 0;
}
}
// add extra node for multilingual test bed
if (mMultilingualTestBed)
ace.AppendLiteral("mltbd.");
// encode the last node if non ASCII
if (len) {
rv = stringPrepAndACE(Substring(ustr, offset, len), encodedBuf);
NS_ENSURE_SUCCESS(rv, rv);
ace.Append(encodedBuf);
}
return NS_OK;
}
示例6: strlen
/**
* Given a string which contains a list of Header addresses, returns a
* comma-separated list of just the `mailbox' portions.
*/
NS_IMETHODIMP
nsMsgHeaderParser::ExtractHeaderAddressMailboxes(const nsACString &aLine,
nsACString &aResult)
{
if (aLine.IsEmpty())
{
aResult.Truncate();
return NS_OK;
}
char *addrs = 0;
int status = msg_parse_Header_addresses(PromiseFlatCString(aLine).get(),
NULL, &addrs);
if (status <= 0)
return NS_ERROR_OUT_OF_MEMORY;
char *s = addrs;
PRUint32 i, size = 0;
for (i = 0; (int) i < status; i++)
{
PRUint32 j = strlen(s);
s += j + 1;
size += j;
if ((int)(i + 1) < status)
size += 2;
}
nsCString result;
result.SetLength(size);
s = addrs;
char* out = result.BeginWriting();
for (i = 0; (int)i < status; i++)
{
PRUint32 j = strlen(s);
memcpy(out, s, j);
out += j;
if ((int)(i+1) < status)
{
*out++ = ',';
*out++ = ' ';
}
s += j + 1;
}
PR_Free(addrs);
aResult = result;
return NS_OK;
}
示例7: origLabel
nsresult nsIDNService::ACEtoUTF8(const nsACString & input, nsACString & _retval,
stringPrepFlag flag)
{
// RFC 3490 - 4.2 ToUnicode
// ToUnicode never fails. If any step fails, then the original input
// sequence is returned immediately in that step.
//
// Note that this refers to the decoding of a single label.
// ACEtoUTF8 may be called with a sequence of labels separated by dots;
// this test applies individually to each label.
uint32_t len = 0, offset = 0;
nsAutoCString decodedBuf;
nsACString::const_iterator start, end;
input.BeginReading(start);
input.EndReading(end);
_retval.Truncate();
// loop and decode nodes
while (start != end) {
len++;
if (*start++ == '.') {
nsDependentCSubstring origLabel(input, offset, len - 1);
if (NS_FAILED(decodeACE(origLabel, decodedBuf, flag))) {
// If decoding failed, use the original input sequence
// for this label.
_retval.Append(origLabel);
} else {
_retval.Append(decodedBuf);
}
_retval.Append('.');
offset += len;
len = 0;
}
}
// decode the last node
if (len) {
nsDependentCSubstring origLabel(input, offset, len);
if (NS_FAILED(decodeACE(origLabel, decodedBuf, flag))) {
_retval.Append(origLabel);
} else {
_retval.Append(decodedBuf);
}
}
return NS_OK;
}
示例8: GetSpec
NS_IMETHODIMP
RustURL::GetSpecIgnoringRef(nsACString & aSpecIgnoringRef)
{
nsresult rv = GetSpec(aSpecIgnoringRef);
if (NS_FAILED(rv)) {
return rv;
}
int32_t pos = aSpecIgnoringRef.FindChar('#');
if (pos == kNotFound) {
return NS_OK;
}
aSpecIgnoringRef.Truncate(pos);
return NS_OK;
}
示例9: GetUuid
NS_IMETHODIMP nsAbCardProperty::GetUuid(nsACString &uuid)
{
// If we have indeterminate sub-ids, return an empty uuid.
if (m_directoryId.Equals("") || m_localId.Equals(""))
{
uuid.Truncate();
return NS_OK;
}
nsresult rv;
nsCOMPtr<nsIAbManager> manager = do_GetService(NS_ABMANAGER_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
return manager->GenerateUUID(m_directoryId, m_localId, uuid);
}
示例10:
/**
Computes in the location specified by base64Out the SHA256 digest
of the DER Encoded subject Public Key Info for the given cert
*/
static nsresult
GetBase64HashSPKI(const CERTCertificate* cert, nsACString& hashSPKIDigest)
{
hashSPKIDigest.Truncate();
Digest digest;
nsresult rv = digest.DigestBuf(SEC_OID_SHA256, cert->derPublicKey.data,
cert->derPublicKey.len);
if (NS_FAILED(rv)) {
return rv;
}
return Base64Encode(nsDependentCSubstring(
reinterpret_cast<const char*>(digest.get().data),
digest.get().len),
hashSPKIDigest);
}
示例11:
nsresult
nsUnixSystemProxySettings::GetPACURI(nsACString& aResult)
{
if (mProxySettings) {
nsCString proxyMode;
// Check if mode is auto
nsresult rv = mProxySettings->GetString(NS_LITERAL_CSTRING("mode"), proxyMode);
if (rv == NS_OK && proxyMode.EqualsLiteral("auto")) {
return mProxySettings->GetString(NS_LITERAL_CSTRING("autoconfig-url"), aResult);
}
/* The org.gnome.system.proxy schema has been found, but auto mode is not set.
* Don't try the GConf and return empty string. */
aResult.Truncate();
return NS_OK;
}
if (mGConf && IsProxyMode("auto")) {
return mGConf->GetString(NS_LITERAL_CSTRING("/system/proxy/autoconfig_url"),
aResult);
}
// Return an empty string when auto mode is not set.
aResult.Truncate();
return NS_OK;
}
示例12: GetKey
/* static */
nsresult DocGroup::GetKey(nsIPrincipal* aPrincipal, nsACString& aKey) {
// Use GetBaseDomain() to handle things like file URIs, IP address URIs,
// etc. correctly.
nsresult rv = aPrincipal->GetBaseDomain(aKey);
if (NS_FAILED(rv)) {
// We don't really know what to do here. But we should be conservative,
// otherwise it would be possible to reorder two events incorrectly in the
// future if we interrupt at the DocGroup level, so to be safe, use an
// empty string to classify all such documents as belonging to the same
// DocGroup.
aKey.Truncate();
}
return rv;
}
示例13: stringPrepAndACE
nsresult nsIDNService::stringPrepAndACE(const nsAString& in, nsACString& out,
stringPrepFlag flag)
{
nsresult rv = NS_OK;
out.Truncate();
if (in.Length() > kMaxDNSNodeLen) {
NS_WARNING("IDN node too large");
return NS_ERROR_FAILURE;
}
if (IsASCII(in)) {
LossyCopyUTF16toASCII(in, out);
return NS_OK;
}
nsAutoString strPrep;
rv = stringPrep(in, strPrep, flag);
if (flag == eStringPrepForDNS) {
NS_ENSURE_SUCCESS(rv, rv);
}
if (IsASCII(strPrep)) {
LossyCopyUTF16toASCII(strPrep, out);
return NS_OK;
}
if (flag == eStringPrepForUI && NS_SUCCEEDED(rv) && isLabelSafe(in)) {
CopyUTF16toUTF8(strPrep, out);
return NS_OK;
}
rv = punycode(strPrep, out);
// Check that the encoded output isn't larger than the maximum length
// of a DNS node per RFC 1034.
// This test isn't necessary in the code paths above where the input
// is ASCII (since the output will be the same length as the input) or
// where we convert to UTF-8 (since the output is only used for
// display in the UI and not passed to DNS and can legitimately be
// longer than the limit).
if (out.Length() > kMaxDNSNodeLen) {
NS_WARNING("IDN node too large");
return NS_ERROR_FAILURE;
}
return rv;
}
示例14:
void
ICUUtils::LanguageTagIterForContent::GetNext(nsACString& aBCP47LangTag)
{
if (mCurrentFallbackIndex < 0) {
mCurrentFallbackIndex = 0;
// Try the language specified by a 'lang'/'xml:lang' attribute on mContent
// or any ancestor, if such an attribute is specified:
nsAutoString lang;
mContent->GetLang(lang);
if (!lang.IsEmpty()) {
aBCP47LangTag = NS_ConvertUTF16toUTF8(lang);
return;
}
}
if (mCurrentFallbackIndex < 1) {
mCurrentFallbackIndex = 1;
// Else try the language specified by any Content-Language HTTP header or
// pragma directive:
nsIDocument* doc = mContent->OwnerDoc();
nsAutoString lang;
doc->GetContentLanguage(lang);
if (!lang.IsEmpty()) {
aBCP47LangTag = NS_ConvertUTF16toUTF8(lang);
return;
}
}
if (mCurrentFallbackIndex < 2) {
mCurrentFallbackIndex = 2;
// Else try the user-agent's locale:
nsCOMPtr<nsIToolkitChromeRegistry> cr =
mozilla::services::GetToolkitChromeRegistryService();
nsAutoCString uaLangTag;
if (cr) {
cr->GetSelectedLocale(NS_LITERAL_CSTRING("global"), uaLangTag);
}
if (!uaLangTag.IsEmpty()) {
aBCP47LangTag = uaLangTag;
return;
}
}
// TODO: Probably not worth it, but maybe have a fourth fallback to using
// the OS locale?
aBCP47LangTag.Truncate(); // Signal iterator exhausted
}
示例15: ustr
nsresult nsIDNService::UTF8toACE(const nsACString & input, nsACString & ace, bool allowUnassigned, bool convertAllLabels)
{
nsresult rv;
NS_ConvertUTF8toUTF16 ustr(input);
// map ideographic period to ASCII period etc.
normalizeFullStops(ustr);
uint32_t len, offset;
len = 0;
offset = 0;
nsAutoCString encodedBuf;
nsAString::const_iterator start, end;
ustr.BeginReading(start);
ustr.EndReading(end);
ace.Truncate();
// encode nodes if non ASCII
while (start != end) {
len++;
if (*start++ == (char16_t)'.') {
rv = stringPrepAndACE(Substring(ustr, offset, len - 1), encodedBuf,
allowUnassigned, convertAllLabels);
NS_ENSURE_SUCCESS(rv, rv);
ace.Append(encodedBuf);
ace.Append('.');
offset += len;
len = 0;
}
}
// add extra node for multilingual test bed
if (mMultilingualTestBed)
ace.AppendLiteral("mltbd.");
// encode the last node if non ASCII
if (len) {
rv = stringPrepAndACE(Substring(ustr, offset, len), encodedBuf,
allowUnassigned, convertAllLabels);
NS_ENSURE_SUCCESS(rv, rv);
ace.Append(encodedBuf);
}
return NS_OK;
}