本文整理汇总了C++中nsAString::Append方法的典型用法代码示例。如果您正苦于以下问题:C++ nsAString::Append方法的具体用法?C++ nsAString::Append怎么用?C++ nsAString::Append使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nsAString
的用法示例。
在下文中一共展示了nsAString::Append方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: tempURI
void
nsHTMLContentSerializer::SerializeAttributes(nsIContent* aContent,
nsIAtom* aTagName,
nsAString& aStr)
{
nsresult rv;
PRUint32 index, count;
nsAutoString nameStr, valueStr;
count = aContent->GetAttrCount();
NS_NAMED_LITERAL_STRING(_mozStr, "_moz");
// Loop backward over the attributes, since the order they are stored in is
// the opposite of the order they were parsed in (see bug 213347 for reason).
// index is unsigned, hence index >= 0 is always true.
for (index = count; index > 0; ) {
--index;
const nsAttrName* name = aContent->GetAttrNameAt(index);
PRInt32 namespaceID = name->NamespaceID();
nsIAtom* attrName = name->LocalName();
// Filter out any attribute starting with [-|_]moz
const char* sharedName;
attrName->GetUTF8String(&sharedName);
if ((('_' == *sharedName) || ('-' == *sharedName)) &&
!nsCRT::strncmp(sharedName+1, kMozStr, PRUint32(sizeof(kMozStr)-1))) {
continue;
}
aContent->GetAttr(namespaceID, attrName, valueStr);
//
// Filter out special case of <br type="_moz"> or <br _moz*>,
// used by the editor. Bug 16988. Yuck.
//
if (aTagName == nsGkAtoms::br && attrName == nsGkAtoms::type &&
StringBeginsWith(valueStr, _mozStr)) {
continue;
}
if (mIsCopying && mIsFirstChildOfOL && (aTagName == nsGkAtoms::li) &&
(attrName == nsGkAtoms::value)) {
// This is handled separately in SerializeLIValueAttribute()
continue;
}
PRBool isJS = IsJavaScript(attrName, valueStr);
if (((attrName == nsGkAtoms::href) ||
(attrName == nsGkAtoms::src))) {
// Make all links absolute when converting only the selection:
if (mFlags & nsIDocumentEncoder::OutputAbsoluteLinks) {
// Would be nice to handle OBJECT and APPLET tags,
// but that gets more complicated since we have to
// search the tag list for CODEBASE as well.
// For now, just leave them relative.
nsCOMPtr<nsIURI> uri = aContent->GetBaseURI();
if (uri) {
nsAutoString absURI;
rv = NS_MakeAbsoluteURI(absURI, valueStr, uri);
if (NS_SUCCEEDED(rv)) {
valueStr = absURI;
}
}
}
// Need to escape URI.
nsAutoString tempURI(valueStr);
if (!isJS && NS_FAILED(EscapeURI(tempURI, valueStr)))
valueStr = tempURI;
}
if (mIsWholeDocument && aTagName == nsGkAtoms::meta &&
attrName == nsGkAtoms::content) {
// If we're serializing a <meta http-equiv="content-type">,
// use the proper value, rather than what's in the document.
nsAutoString header;
aContent->GetAttr(kNameSpaceID_None, nsGkAtoms::httpEquiv, header);
if (header.LowerCaseEqualsLiteral("content-type")) {
valueStr = NS_LITERAL_STRING("text/html; charset=") +
NS_ConvertASCIItoUTF16(mCharset);
}
}
attrName->ToString(nameStr);
/*If we already crossed the MaxColumn limit or
* if this attr name-value pair(including a space,=,opening and closing quotes) is greater than MaxColumn limit
* then start the attribute from a new line.
*/
if (mDoFormat
&& (mColPos >= mMaxColumn
|| ((PRInt32)(mColPos + nameStr.Length() +
valueStr.Length() + 4) > mMaxColumn))) {
aStr.Append(mLineBreak);
mColPos = 0;
}
// Expand shorthand attribute.
if (IsShorthandAttr(attrName, aTagName) && valueStr.IsEmpty()) {
valueStr = nameStr;
//.........这里部分代码省略.........
示例2:
nsresult
nsXULContentUtils::GetTextForNode(nsIRDFNode* aNode, nsAString& aResult)
{
if (! aNode) {
aResult.Truncate();
return NS_OK;
}
nsresult rv;
// Literals are the most common, so try these first.
nsCOMPtr<nsIRDFLiteral> literal = do_QueryInterface(aNode);
if (literal) {
const char16_t* p;
rv = literal->GetValueConst(&p);
if (NS_FAILED(rv)) return rv;
aResult = p;
return NS_OK;
}
nsCOMPtr<nsIRDFDate> dateLiteral = do_QueryInterface(aNode);
if (dateLiteral) {
PRTime value;
rv = dateLiteral->GetValue(&value);
if (NS_FAILED(rv)) return rv;
nsAutoString str;
rv = gFormat->FormatPRTime(nullptr /* nsILocale* locale */,
kDateFormatShort,
kTimeFormatSeconds,
value,
str);
aResult.Assign(str);
if (NS_FAILED(rv)) return rv;
return NS_OK;
}
nsCOMPtr<nsIRDFInt> intLiteral = do_QueryInterface(aNode);
if (intLiteral) {
int32_t value;
rv = intLiteral->GetValue(&value);
if (NS_FAILED(rv)) return rv;
aResult.Truncate();
nsAutoString intStr;
intStr.AppendInt(value, 10);
aResult.Append(intStr);
return NS_OK;
}
nsCOMPtr<nsIRDFResource> resource = do_QueryInterface(aNode);
if (resource) {
const char* p;
rv = resource->GetValueConst(&p);
if (NS_FAILED(rv)) return rv;
CopyUTF8toUTF16(p, aResult);
return NS_OK;
}
NS_ERROR("not a resource or a literal");
return NS_ERROR_UNEXPECTED;
}
示例3:
void
nsCSPSchemeSrc::toString(nsAString& outStr) const
{
outStr.Append(mScheme);
outStr.AppendASCII(":");
}
示例4: if
void
nsCSSValue::AppendToString(nsCSSProperty aProperty, nsAString& aResult) const
{
// eCSSProperty_UNKNOWN gets used for some recursive calls below.
NS_ABORT_IF_FALSE((0 <= aProperty &&
aProperty <= eCSSProperty_COUNT_no_shorthands) ||
aProperty == eCSSProperty_UNKNOWN,
"property ID out of range");
nsCSSUnit unit = GetUnit();
if (unit == eCSSUnit_Null) {
return;
}
if (eCSSUnit_String <= unit && unit <= eCSSUnit_Attr) {
if (unit == eCSSUnit_Attr) {
aResult.AppendLiteral("attr(");
}
nsAutoString buffer;
GetStringValue(buffer);
if (unit == eCSSUnit_String) {
nsStyleUtil::AppendEscapedCSSString(buffer, aResult);
} else if (unit == eCSSUnit_Families) {
// XXX We really need to do *some* escaping.
aResult.Append(buffer);
} else {
nsStyleUtil::AppendEscapedCSSIdent(buffer, aResult);
}
}
else if (eCSSUnit_Array <= unit && unit <= eCSSUnit_Cubic_Bezier) {
switch (unit) {
case eCSSUnit_Counter: aResult.AppendLiteral("counter("); break;
case eCSSUnit_Counters: aResult.AppendLiteral("counters("); break;
case eCSSUnit_Cubic_Bezier: aResult.AppendLiteral("cubic-bezier("); break;
default: break;
}
nsCSSValue::Array *array = GetArrayValue();
PRBool mark = PR_FALSE;
for (size_t i = 0, i_end = array->Count(); i < i_end; ++i) {
if (aProperty == eCSSProperty_border_image && i >= 5) {
if (array->Item(i).GetUnit() == eCSSUnit_Null) {
continue;
}
if (i == 5) {
aResult.AppendLiteral(" /");
}
}
if (mark && array->Item(i).GetUnit() != eCSSUnit_Null) {
if (unit == eCSSUnit_Array &&
eCSSProperty_transition_timing_function != aProperty)
aResult.AppendLiteral(" ");
else
aResult.AppendLiteral(", ");
}
nsCSSProperty prop =
((eCSSUnit_Counter <= unit && unit <= eCSSUnit_Counters) &&
i == array->Count() - 1)
? eCSSProperty_list_style_type : aProperty;
if (array->Item(i).GetUnit() != eCSSUnit_Null) {
array->Item(i).AppendToString(prop, aResult);
mark = PR_TRUE;
}
}
if (eCSSUnit_Array == unit &&
aProperty == eCSSProperty_transition_timing_function) {
aResult.AppendLiteral(")");
}
}
/* Although Function is backed by an Array, we'll handle it separately
* because it's a bit quirky.
*/
else if (eCSSUnit_Function == unit) {
const nsCSSValue::Array* array = GetArrayValue();
NS_ABORT_IF_FALSE(array->Count() >= 1,
"Functions must have at least one element for the name.");
/* Append the function name. */
const nsCSSValue& functionName = array->Item(0);
if (functionName.GetUnit() == eCSSUnit_Enumerated) {
// We assume that the first argument is always of nsCSSKeyword type.
const nsCSSKeyword functionId =
static_cast<nsCSSKeyword>(functionName.GetIntValue());
nsStyleUtil::AppendEscapedCSSIdent(
NS_ConvertASCIItoUTF16(nsCSSKeywords::GetStringValue(functionId)),
aResult);
} else {
functionName.AppendToString(aProperty, aResult);
}
aResult.AppendLiteral("(");
/* Now, step through the function contents, writing each of them as we go. */
for (size_t index = 1; index < array->Count(); ++index) {
array->Item(index).AppendToString(aProperty, aResult);
/* If we're not at the final element, append a comma. */
if (index + 1 != array->Count())
aResult.AppendLiteral(", ");
}
//.........这里部分代码省略.........
示例5: initFunctionPointers
void
nsWin32Locale::GetXPLocale(LCID winLCID, nsAString& locale)
{
initFunctionPointers ();
if (lcidToLocaleName)
{
WCHAR ret_locale[LOCALE_NAME_MAX_LENGTH];
int rv = lcidToLocaleName(winLCID, ret_locale, LOCALE_NAME_MAX_LENGTH, 0);
// rv 0 means that the function failed to match up the LCID, so we fallback
// to the old function
if (rv != 0)
{
locale.Assign(ret_locale);
return;
}
}
DWORD lang_id, sublang_id;
size_t i, j;
lang_id = PRIMARYLANGID(LANGIDFROMLCID(winLCID));
sublang_id = SUBLANGID(LANGIDFROMLCID(winLCID));
/* Special-case Norwegian Bokmal and Norwegian Nynorsk, which have the same
LANG_ID on Windows, but have separate ISO-639-2 codes */
if (lang_id == LANG_NORWEGIAN) {
if (sublang_id == SUBLANG_NORWEGIAN_BOKMAL) {
locale.AssignASCII("nb-NO");
} else if (sublang_id == SUBLANG_NORWEGIAN_NYNORSK) {
locale.AssignASCII("nn-NO");
} else {
locale.AssignASCII("no-NO");
}
return;
}
for(i=0;i<LENGTH_MAPPING_LIST;i++) {
if (lang_id==iso_list[i].win_code) {
/* Special-case Croatian and Serbian, which have the same LANG_ID on
Windows, but have been split into separate ISO-639-2 codes */
if (lang_id == LANG_CROATIAN) {
if (sublang_id == SUBLANG_DEFAULT) {
locale.AssignLiteral(CROATIAN_ISO_CODE);
} else {
locale.AssignLiteral(SERBIAN_ISO_CODE);
}
} else {
locale.AssignASCII(iso_list[i].iso_code);
}
for(j=0;iso_list[i].sublang_list[j].win_code;j++) {
if (sublang_id == iso_list[i].sublang_list[j].win_code) {
locale.Append(PRUnichar('-'));
locale.AppendASCII(iso_list[i].sublang_list[j].iso_code);
break;
}
}
return;
}
}
//
// didn't find any match. fall back to en-US, which is better
// than unusable buttons without 'OK', 'Cancel', etc (bug 224546)
//
locale.AssignLiteral("en-US");
return;
}
示例6: GetURI
NS_IMETHODIMP
nsLocation::GetHash(nsAString& aHash)
{
if (!CallerSubsumes())
return NS_ERROR_DOM_SECURITY_ERR;
aHash.SetLength(0);
nsCOMPtr<nsIURI> uri;
nsresult rv = GetURI(getter_AddRefs(uri));
if (NS_FAILED(rv) || !uri) {
return rv;
}
nsAutoCString ref;
nsAutoString unicodeRef;
rv = uri->GetRef(ref);
if (nsContentUtils::EncodeDecodeURLHash()) {
if (NS_SUCCEEDED(rv)) {
nsCOMPtr<nsITextToSubURI> textToSubURI(
do_GetService(NS_ITEXTTOSUBURI_CONTRACTID, &rv));
if (NS_SUCCEEDED(rv)) {
nsAutoCString charset;
uri->GetOriginCharset(charset);
rv = textToSubURI->UnEscapeURIForUI(charset, ref, unicodeRef);
}
if (NS_FAILED(rv)) {
// Oh, well. No intl here!
NS_UnescapeURL(ref);
CopyASCIItoUTF16(ref, unicodeRef);
rv = NS_OK;
}
}
if (NS_SUCCEEDED(rv) && !unicodeRef.IsEmpty()) {
aHash.Assign(char16_t('#'));
aHash.Append(unicodeRef);
}
} else { // URL Hash should simply return the value of the Ref segment
if (NS_SUCCEEDED(rv) && !ref.IsEmpty()) {
aHash.Assign(char16_t('#'));
AppendUTF8toUTF16(ref, aHash);
}
}
if (aHash == mCachedHash) {
// Work around ShareThis stupidly polling location.hash every
// 5ms all the time by handing out the same exact string buffer
// we handed out last time.
aHash = mCachedHash;
} else {
mCachedHash = aHash;
}
return rv;
}
示例7: ToStringInternal
void nsCSSSelector::ToStringInternal(nsAString& aString,
nsICSSStyleSheet* aSheet,
PRBool aIsPseudoElem,
PRIntn aNegatedIndex,
const nsString& aIdPrefix) const
{
nsAutoString temp;
PRBool aIsNegated = PRBool(0 < aNegatedIndex);
PRBool isPseudoElement = IsPseudoElement(mTag);
// selectors are linked from right-to-left, so the next selector in the linked list
// actually precedes this one in the resulting string
if (mNext) {
mNext->ToStringInternal(aString, aSheet, IsPseudoElement(mTag), 0,
aIdPrefix);
if (!aIsNegated && !isPseudoElement) {
// don't add a leading whitespace if we have a pseudo-element
// or a negated simple selector
aString.Append(PRUnichar(' '));
}
}
if (1 < aNegatedIndex) {
// the first mNegations does not contain a negated type element selector
// or a negated universal selector
NS_IF_NEGATED_START(aIsNegated, aString)
}
// For non-pseudo-element selectors or for lone pseudo-elements, deal with
// namespace prefixes.
if (!isPseudoElement || !mNext) {
// append the namespace prefix if needed
if (mNameSpace == kNameSpaceID_None) {
// The only way to do this in CSS is to have an explicit namespace
// of "none" specified in the sheet by having a '|' with nothing
// before it.
aString.Append(PRUnichar('|'));
} else {
#ifndef FBML
if (aSheet) {
nsXMLNameSpaceMap *sheetNS = aSheet->GetNameSpaceMap();
// sheetNS is non-null if and only if we had an @namespace rule. If it's
// null, that means that the only namespaces we could have are the
// wildcard namespace (which can be implicit in this case) and the "none"
// namespace, which we handled above. So no need to output anything when
// sheetNS is null.
if (sheetNS) {
nsIAtom *prefixAtom = nsnull;
// prefixAtom is non-null if and only if we have a prefix other than
// '*'
if (mNameSpace != kNameSpaceID_Unknown) {
prefixAtom = sheetNS->FindPrefix(mNameSpace);
}
if (prefixAtom) {
nsAutoString prefix;
prefixAtom->ToString(prefix);
aString.Append(prefix);
aString.Append(PRUnichar('|'));
} else if (mNameSpace == kNameSpaceID_Unknown) {
// explicit *| or only non-default namespace rules and we're not
// using any of those namespaces
aString.AppendLiteral("*|");
}
// else we are in the default namespace and don't need to output
// anything
}
}
#endif
}
}
// smells like a universal selector
if (!mTag && !mIDList && !mClassList) {
if (1 != aNegatedIndex) {
aString.Append(PRUnichar('*'));
}
if (1 < aNegatedIndex) {
NS_IF_NEGATED_END(aIsNegated, aString)
}
} else {
// Append the tag name, if there is one
if (mTag) {
示例8:
void
txErrorExpr::toString(nsAString& aStr)
{
aStr.Append(mStr);
}
示例9: GetProtocol
void URL::GetProtocol(nsAString& aProtocol) const {
URL_GETTER(aProtocol, GetScheme);
aProtocol.Append(char16_t(':'));
}
示例10: ToStringInternal
void nsCSSSelector::ToStringInternal(nsAString& aString,
nsICSSStyleSheet* aSheet,
PRBool aIsPseudoElem,
PRBool aIsNegated) const
{
nsAutoString temp;
PRBool isPseudoElement = IsPseudoElement(mTag);
// selectors are linked from right-to-left, so the next selector in the linked list
// actually precedes this one in the resulting string
if (mNext) {
mNext->ToStringInternal(aString, aSheet, IsPseudoElement(mTag), 0);
if (!aIsNegated && !isPseudoElement) {
// don't add a leading whitespace if we have a pseudo-element
// or a negated simple selector
aString.Append(PRUnichar(' '));
}
}
// For non-pseudo-element selectors or for lone pseudo-elements, deal with
// namespace prefixes.
PRBool wroteNamespace = PR_FALSE;
if (!isPseudoElement || !mNext) {
// append the namespace prefix if needed
if (mNameSpace == kNameSpaceID_None) {
// The only way to do this in CSS is to have an explicit namespace
// of "none" specified in the sheet by having a '|' with nothing
// before it.
aString.Append(PRUnichar('|'));
wroteNamespace = PR_TRUE;
} else {
if (aSheet) {
nsXMLNameSpaceMap *sheetNS = aSheet->GetNameSpaceMap();
// sheetNS is non-null if and only if we had an @namespace rule. If it's
// null, that means that the only namespaces we could have are the
// wildcard namespace (which can be implicit in this case) and the "none"
// namespace, which we handled above. So no need to output anything when
// sheetNS is null.
if (sheetNS) {
if (mNameSpace != kNameSpaceID_Unknown) {
if (sheetNS->FindNameSpaceID(nsnull) != mNameSpace) {
nsIAtom *prefixAtom = sheetNS->FindPrefix(mNameSpace);
NS_ASSERTION(prefixAtom, "how'd we get a non-default namespace "
"without a prefix?");
nsAutoString prefix;
prefixAtom->ToString(prefix);
aString.Append(prefix);
aString.Append(PRUnichar('|'));
wroteNamespace = PR_TRUE;
}
// otherwise it must be the default namespace
} else {
// A selector for an element in any namespace.
if (// Use explicit "*|" only when it's not implied
sheetNS->FindNameSpaceID(nsnull) != kNameSpaceID_None &&
// :not() is special in that the default namespace is
// not implied for non-type selectors
(!aIsNegated || (!mIDList && !mClassList &&
!mPseudoClassList && !mAttrList))) {
aString.AppendLiteral("*|");
wroteNamespace = PR_TRUE;
}
}
}
}
}
}
if (!mTag) {
// Universal selector: avoid writing the universal selector when we
// can avoid it, especially since we're required to avoid it for the
// inside of :not()
if (wroteNamespace ||
(!mIDList && !mClassList && !mPseudoClassList && !mAttrList &&
(aIsNegated || !mNegations))) {
aString.Append(PRUnichar('*'));
}
} else {
// Append the tag name
if (isPseudoElement) {
if (!mNext) {
// Lone pseudo-element selector -- toss in a wildcard type selector
// XXXldb Why?
aString.Append(PRUnichar('*'));
}
if (!nsCSSPseudoElements::IsCSS2PseudoElement(mTag)) {
aString.Append(PRUnichar(':'));
}
}
nsAutoString prefix;
mTag->ToString(prefix);
aString.Append(prefix);
}
// Append the id, if there is one
if (mIDList) {
nsAtomList* list = mIDList;
while (list != nsnull) {
list->mAtom->ToString(temp);
//.........这里部分代码省略.........
示例11: nsMsgI18NConvertToUnicode
nsresult nsMsgI18NConvertToUnicode(const char* aCharset,
const nsCString& inString,
nsAString& outString,
bool aIsCharsetCanonical)
{
if (inString.IsEmpty()) {
outString.Truncate();
return NS_OK;
}
else if (!*aCharset || !PL_strcasecmp(aCharset, "us-ascii") ||
!PL_strcasecmp(aCharset, "ISO-8859-1")) {
// Despite its name, it also works for Latin-1.
CopyASCIItoUTF16(inString, outString);
return NS_OK;
}
else if (!PL_strcasecmp(aCharset, "UTF-8")) {
if (MsgIsUTF8(inString)) {
nsAutoString tmp;
CopyUTF8toUTF16(inString, tmp);
if (!tmp.IsEmpty() && tmp.get()[0] == char16_t(0xFEFF))
tmp.Cut(0, 1);
outString.Assign(tmp);
return NS_OK;
}
NS_WARNING("Invalid UTF-8 string");
return NS_ERROR_UNEXPECTED;
}
nsresult rv;
nsCOMPtr <nsICharsetConverterManager> ccm = do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr <nsIUnicodeDecoder> decoder;
// get an unicode converter
if (aIsCharsetCanonical) // optimize for modified UTF-7 used by IMAP
rv = ccm->GetUnicodeDecoderRaw(aCharset, getter_AddRefs(decoder));
else
rv = ccm->GetUnicodeDecoderInternal(aCharset, getter_AddRefs(decoder));
NS_ENSURE_SUCCESS(rv, rv);
const char *originalSrcPtr = inString.get();
const char *currentSrcPtr = originalSrcPtr;
int32_t originalLength = inString.Length();
int32_t srcLength;
int32_t dstLength;
char16_t localbuf[512];
int32_t consumedLen = 0;
outString.Truncate();
// convert
while (consumedLen < originalLength) {
srcLength = originalLength - consumedLen;
dstLength = 512;
rv = decoder->Convert(currentSrcPtr, &srcLength, localbuf, &dstLength);
if (NS_FAILED(rv) || dstLength == 0)
break;
outString.Append(localbuf, dstLength);
currentSrcPtr += srcLength;
consumedLen = currentSrcPtr - originalSrcPtr; // src length used so far
}
return rv;
}
示例12:
void
nsXMLContentSerializer::AppendToString(const PRUnichar aChar,
nsAString& aOutputStr)
{
aOutputStr.Append(aChar);
}
示例13: DOMFileResult
NS_IMETHODIMP
nsDOMFile::GetAsDataURL(nsAString &aResult)
{
aResult.AssignLiteral("data:");
nsresult rv;
if (!mContentType.Length()) {
nsCOMPtr<nsIMIMEService> mimeService =
do_GetService(NS_MIMESERVICE_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
nsCAutoString contentType;
rv = mimeService->GetTypeFromFile(mFile, contentType);
if (NS_SUCCEEDED(rv)) {
CopyUTF8toUTF16(contentType, mContentType);
}
}
if (mContentType.Length()) {
aResult.Append(mContentType);
} else {
aResult.AppendLiteral("application/octet-stream");
}
aResult.AppendLiteral(";base64,");
nsCOMPtr<nsIInputStream> stream;
rv = GetInternalStream(getter_AddRefs(stream));
NS_ENSURE_SUCCESS(rv, DOMFileResult(rv));
char readBuf[4096];
PRUint32 leftOver = 0;
PRUint32 numRead;
do {
rv = stream->Read(readBuf + leftOver, sizeof(readBuf) - leftOver, &numRead);
NS_ENSURE_SUCCESS(rv, DOMFileResult(rv));
PRUint32 numEncode = numRead + leftOver;
leftOver = 0;
if (numEncode == 0) break;
// unless this is the end of the file, encode in multiples of 3
if (numRead > 0) {
leftOver = numEncode % 3;
numEncode -= leftOver;
}
// out buffer should be at least 4/3rds the read buf, plus a terminator
char *base64 = PL_Base64Encode(readBuf, numEncode, nsnull);
if (!base64) {
return DOMFileResult(NS_ERROR_OUT_OF_MEMORY);
}
nsDependentCString str(base64);
PRUint32 strLen = str.Length();
PRUint32 oldLength = aResult.Length();
AppendASCIItoUTF16(str, aResult);
PR_Free(base64);
if (aResult.Length() - oldLength != strLen) {
return DOMFileResult(NS_ERROR_OUT_OF_MEMORY);
}
if (leftOver) {
memmove(readBuf, readBuf + numEncode, leftOver);
}
} while (numRead > 0);
return NS_OK;
}
示例14: FormatTMTime
// performs a locale sensitive date formatting operation on the struct tm parameter
nsresult nsDateTimeFormatWin::FormatTMTime(nsILocale* locale,
const nsDateFormatSelector dateFormatSelector,
const nsTimeFormatSelector timeFormatSelector,
const struct tm* tmTime,
nsAString& stringOut)
{
SYSTEMTIME system_time;
DWORD dwFlags_Date = 0, dwFlags_Time = 0;
int dateLen, timeLen;
PRUnichar dateBuffer[NSDATETIMEFORMAT_BUFFER_LEN], timeBuffer[NSDATETIMEFORMAT_BUFFER_LEN];
// set up locale data
(void) Initialize(locale);
// Map tm to SYSTEMTIME
system_time.wYear = 1900 + tmTime->tm_year;
system_time.wMonth = tmTime->tm_mon + 1;
system_time.wDayOfWeek = tmTime->tm_wday;
system_time.wDay = tmTime->tm_mday;
system_time.wHour = tmTime->tm_hour;
system_time.wMinute = tmTime->tm_min;
system_time.wSecond = tmTime->tm_sec;
system_time.wMilliseconds = 0;
// Map to WinAPI date format
switch (dateFormatSelector) {
case kDateFormatLong:
dwFlags_Date = DATE_LONGDATE;
break;
case kDateFormatShort:
dwFlags_Date = DATE_SHORTDATE;
break;
case kDateFormatWeekday:
dwFlags_Date = 0;
break;
case kDateFormatYearMonth:
dwFlags_Date = 0; // TODO:only availabe NT5
break;
}
// Map to WinAPI time format
switch (timeFormatSelector) {
case kTimeFormatSeconds:
dwFlags_Time = 0;
break;
case kTimeFormatNoSeconds:
dwFlags_Time = TIME_NOSECONDS;
break;
case kTimeFormatSecondsForce24Hour:
dwFlags_Time = TIME_FORCE24HOURFORMAT;
break;
case kTimeFormatNoSecondsForce24Hour:
dwFlags_Time = TIME_NOSECONDS + TIME_FORCE24HOURFORMAT;
break;
}
// Call GetDateFormatW
if (dateFormatSelector == kDateFormatNone) {
dateLen = 0;
}
else {
if (dateFormatSelector == kDateFormatYearMonth) {
dateLen = nsGetDateFormatW(0, &system_time, "yyyy/MM",
dateBuffer, NSDATETIMEFORMAT_BUFFER_LEN);
}
else if (dateFormatSelector == kDateFormatWeekday) {
dateLen = nsGetDateFormatW(0, &system_time, "ddd",
dateBuffer, NSDATETIMEFORMAT_BUFFER_LEN);
}
else {
dateLen = nsGetDateFormatW(dwFlags_Date, &system_time, NULL,
dateBuffer, NSDATETIMEFORMAT_BUFFER_LEN);
}
if (dateLen != 0) {
dateLen--; // Since the count includes the terminating null.
}
}
// Call GetTimeFormatW
if (timeFormatSelector == kTimeFormatNone) {
timeLen = 0;
}
else {
timeLen = nsGetTimeFormatW(dwFlags_Time, &system_time, NULL,
timeBuffer, NSDATETIMEFORMAT_BUFFER_LEN);
if (timeLen != 0) {
timeLen--; // Since the count includes the terminating null.
}
}
NS_ASSERTION(NSDATETIMEFORMAT_BUFFER_LEN >= (uint32_t) (dateLen + 1), "internal date buffer is not large enough");
NS_ASSERTION(NSDATETIMEFORMAT_BUFFER_LEN >= (uint32_t) (timeLen + 1), "internal time buffer is not large enough");
// Copy the result
stringOut.Truncate();
if (dateLen != 0 && timeLen != 0) {
stringOut.Assign(dateBuffer, dateLen);
stringOut.Append((PRUnichar *)(L" "), 1);
stringOut.Append(timeBuffer, timeLen);
//.........这里部分代码省略.........
示例15: toString
/*
* Converts the value of the given double to a String, and places
* The result into the destination String.
* @return the given dest string
*/
void Double::toString(double aValue, nsAString& aDest)
{
// check for special cases
if (isNaN(aValue)) {
aDest.AppendLiteral("NaN");
return;
}
if (isInfinite(aValue)) {
if (aValue < 0)
aDest.Append(PRUnichar('-'));
aDest.AppendLiteral("Infinity");
return;
}
// Mantissa length is 17, so this is plenty
const int buflen = 20;
char buf[buflen];
PRIntn intDigits, sign;
char* endp;
PR_dtoa(aValue, 0, 0, &intDigits, &sign, &endp, buf, buflen - 1);
// compute length
PRInt32 length = endp - buf;
if (length > intDigits) {
// decimal point needed
++length;
if (intDigits < 1) {
// leading zeros, -intDigits + 1
length += 1 - intDigits;
}
}
else {
// trailing zeros, total length given by intDigits
length = intDigits;
}
if (aValue < 0)
++length;
// grow the string
PRUint32 oldlength = aDest.Length();
if (!EnsureStringLength(aDest, oldlength + length))
return; // out of memory
nsAString::iterator dest;
aDest.BeginWriting(dest).advance(PRInt32(oldlength));
if (aValue < 0) {
*dest = '-'; ++dest;
}
int i;
// leading zeros
if (intDigits < 1) {
*dest = '0'; ++dest;
*dest = '.'; ++dest;
for (i = 0; i > intDigits; --i) {
*dest = '0'; ++dest;
}
}
// mantissa
int firstlen = PR_MIN(intDigits, endp - buf);
for (i = 0; i < firstlen; i++) {
*dest = buf[i]; ++dest;
}
if (i < endp - buf) {
if (i > 0) {
*dest = '.'; ++dest;
}
for (; i < endp - buf; i++) {
*dest = buf[i]; ++dest;
}
}
// trailing zeros
for (; i < intDigits; i++) {
*dest = '0'; ++dest;
}
}