void URL::GetPort(nsString& aPort) const { aPort.Truncate(); int32_t port; nsresult rv = mURI->GetPort(&port); if (NS_SUCCEEDED(rv) && port != -1) { nsAutoString portStr; portStr.AppendInt(port, 10); aPort.Assign(portStr); } }
void URL::GetHash(nsString& aHash) const { aHash.Truncate(); nsAutoCString ref; nsresult rv = mURI->GetRef(ref); if (NS_SUCCEEDED(rv) && !ref.IsEmpty()) { NS_UnescapeURL(ref); // XXX may result in random non-ASCII bytes! aHash.Assign(PRUnichar('#')); AppendUTF8toUTF16(ref, aHash); } }
static nsresult GetAlgorithmName(JSContext* aCx, const OOS& aAlgorithm, nsString& aName) { ClearException ce(aCx); if (aAlgorithm.IsString()) { // If string, then treat as algorithm name aName.Assign(aAlgorithm.GetAsString()); } else { // Coerce to algorithm and extract name JS::RootedValue value(aCx, JS::ObjectValue(*aAlgorithm.GetAsObject())); Algorithm alg; if (!alg.Init(aCx, value) || !alg.mName.WasPassed()) { return NS_ERROR_DOM_SYNTAX_ERR; } aName.Assign(alg.mName.Value()); } return NS_OK; }
void URL::GetHash(nsString& aHash, ErrorResult& aRv) const { aHash.Truncate(); nsAutoCString ref; nsresult rv = mURI->GetRef(ref); if (NS_SUCCEEDED(rv) && !ref.IsEmpty()) { aHash.Assign(char16_t('#')); if (nsContentUtils::EncodeDecodeURLHash()) { NS_UnescapeURL(ref); // XXX may result in random non-ASCII bytes! } AppendUTF8toUTF16(ref, aHash); } }
void ConvertJSValToStr(nsString& aString, JSContext* aContext, jsval aValue) { JSString *jsstring; if ( !JSVAL_IS_NULL(aValue) && (jsstring = JS_ValueToString(aContext, aValue)) != nsnull) { aString.Assign(reinterpret_cast<const PRUnichar*>(JS_GetStringChars(jsstring))); } else { aString.Truncate(); } }
nsresult nsParserMsgUtils::GetLocalizedStringByID(const char * aPropFileName, PRUint32 aID, nsString& oVal) { oVal.Truncate(); nsCOMPtr<nsIStringBundle> bundle; nsresult rv = GetBundle(aPropFileName,getter_AddRefs(bundle)); if (NS_SUCCEEDED(rv) && bundle) { nsXPIDLString valUni; rv = bundle->GetStringFromID(aID, getter_Copies(valUni)); if (NS_SUCCEEDED(rv) && valUni) { oVal.Assign(valUni); } } return rv; }
static void AssignSourceNameHelper(nsString& aSourceNameDest, const nsAString& aSourceNameSrc) { if (aSourceNameSrc.IsEmpty()) return; aSourceNameDest.Assign(aSourceNameSrc); nsCOMPtr<nsIURI> uri; nsAutoCString pass; if (NS_SUCCEEDED(NS_NewURI(getter_AddRefs(uri), aSourceNameSrc)) && NS_SUCCEEDED(uri->GetPassword(pass)) && !pass.IsEmpty()) { NS_GetSanitizedURIStringFromURI(uri, aSourceNameDest); } }
//-------------------------------------------------------- // Return localized string static nsresult GetLocalizedString(nsIStringBundle* aStrBundle, const char* aKey, nsString& oVal) { NS_ENSURE_ARG_POINTER(aStrBundle); NS_ENSURE_ARG_POINTER(aKey); // Determine default label from string bundle nsXPIDLString valUni; nsAutoString key; key.AssignWithConversion(aKey); nsresult rv = aStrBundle->GetStringFromName(key.get(), getter_Copies(valUni)); if (NS_SUCCEEDED(rv) && valUni) { oVal.Assign(valUni); } else { oVal.Truncate(); } return rv; }
static void ValueToString(JSContext *cx, jsval aJSValue, nsString& aString) { if (JSVAL_IS_VOID(aJSValue)) { aString.Assign(kUndefined, STRLEN_ARRAY(kUndefined)); } else if (JSVAL_IS_NULL(aJSValue)) { aString.Assign(kNull, STRLEN_ARRAY(kNull)); } else if (JSVAL_IS_INT(aJSValue)) { jsint i = JSVAL_TO_INT(aJSValue); char buf[20]; PR_snprintf(buf, sizeof(buf), "%d", i); aString.Assign(NS_ConvertASCIItoUTF16(buf)); } else if (JSVAL_IS_DOUBLE(aJSValue)) { jsdouble d = JSVAL_TO_DOUBLE(aJSValue); char buf[50]; PR_snprintf(buf, sizeof(buf), "%f", d); aString.Assign(NS_ConvertASCIItoUTF16(buf)); } else if (JSVAL_IS_BOOLEAN(aJSValue)) { JSBool b = JSVAL_TO_BOOLEAN(aJSValue); if (b) aString.Assign(kTrue, STRLEN_ARRAY(kTrue)); else aString.Assign(kFalse, STRLEN_ARRAY(kFalse)); } else if (JSVAL_IS_STRING(aJSValue)) { JSString *str = JSVAL_TO_STRING(aJSValue); size_t len; const jschar *chars = JS_GetStringCharsAndLength(cx, str, &len); NS_ASSERTION(chars, "out of memory"); if (chars) { NS_ASSERTION(sizeof(jschar) == sizeof(PRUnichar), "char size mismatch"); aString.Assign(reinterpret_cast<const PRUnichar*>(chars), len); } } else { JSObject *obj = JSVAL_TO_OBJECT(aJSValue); JSClass *clazz = JS_GetClass(cx, obj); aString.Assign(PRUnichar('[')); aString.Append(NS_ConvertASCIItoUTF16(clazz->name)); aString.Append(PRUnichar(']')); } }
static nsresult GetAlgorithmName(JSContext* aCx, const OOS& aAlgorithm, /* out */ nsString& aName) { MOZ_ASSERT(aAlgorithm.IsString()); // TODO: remove assertion when we coerce. if (aAlgorithm.IsString()) { // If string, then treat as algorithm name aName.Assign(aAlgorithm.GetAsString()); } else { // TODO: Coerce to string and extract name. See WebCryptoTask.cpp } if (!NormalizeToken(aName, aName)) { return NS_ERROR_DOM_SYNTAX_ERR; } return NS_OK; }
nsresult nsParserMsgUtils::GetLocalizedStringByName(const char * aPropFileName, const char* aKey, nsString& oVal) { oVal.Truncate(); NS_ENSURE_ARG_POINTER(aKey); nsCOMPtr<nsIStringBundle> bundle; nsresult rv = GetBundle(aPropFileName,getter_AddRefs(bundle)); if (NS_SUCCEEDED(rv) && bundle) { nsXPIDLString valUni; nsAutoString key; key.AssignWithConversion(aKey); rv = bundle->GetStringFromName(key.get(), getter_Copies(valUni)); if (NS_SUCCEEDED(rv) && valUni) { oVal.Assign(valUni); } } return rv; }
void nsCParserStartNode::GetSource(nsString& aString) const { aString.Assign(PRUnichar('<')); const PRUnichar* theTagName = nsHTMLTags::GetStringValue(nsHTMLTag(mToken->GetTypeID())); if (theTagName) { aString.Append(theTagName); } PRInt32 index; PRInt32 size = mAttributes.GetSize(); for (index = 0 ; index < size; ++index) { CAttributeToken *theToken = static_cast<CAttributeToken*>(mAttributes.ObjectAt(index)); if (theToken) { theToken->AppendSourceTo(aString); aString.Append(PRUnichar(' ')); //this will get removed... } } aString.Append(PRUnichar('>')); }
void setPath(const nsAString& aPath) { mPath.Assign(aPath); NormalizeFilePath(); }
gluezilla_stringSet(nsString & str, PRUnichar * text) { str.Assign (text); }
bool nsMessengerUnixIntegration::BuildNotificationBody(nsIMsgDBHdr *aHdr, nsIStringBundle *aBundle, nsString &aBody) { nsAutoString alertBody; bool showPreview = true; bool showSubject = true; bool showSender = true; int32_t previewLength = SHOW_ALERT_PREVIEW_LENGTH_DEFAULT; nsCOMPtr<nsIPrefBranch> prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID)); if (!prefBranch) return false; prefBranch->GetBoolPref(SHOW_ALERT_PREVIEW, &showPreview); prefBranch->GetBoolPref(SHOW_ALERT_SENDER, &showSender); prefBranch->GetBoolPref(SHOW_ALERT_SUBJECT, &showSubject); prefBranch->GetIntPref(SHOW_ALERT_PREVIEW_LENGTH, &previewLength); nsCOMPtr<nsIMsgFolder> folder; aHdr->GetFolder(getter_AddRefs(folder)); if (!folder) return false; nsCString msgURI; folder->GetUriForMsg(aHdr, msgURI); bool localOnly; size_t msgURIIndex = mFetchingURIs.IndexOf(msgURI); if (msgURIIndex == mFetchingURIs.NoIndex) { localOnly = false; mFetchingURIs.AppendElement(msgURI); } else localOnly = true; uint32_t messageKey; if (NS_FAILED(aHdr->GetMessageKey(&messageKey))) return false; bool asyncResult = false; nsresult rv = folder->FetchMsgPreviewText(&messageKey, 1, localOnly, this, &asyncResult); // If we're still waiting on getting the message previews, // bail early. We'll come back later when the async operation // finishes. if (NS_FAILED(rv) || asyncResult) return false; // If we got here, that means that we've retrieved the message preview, // so we can stop tracking it with our mFetchingURIs array. if (msgURIIndex != mFetchingURIs.NoIndex) mFetchingURIs.RemoveElementAt(msgURIIndex); nsCString utf8previewString; if (showPreview && NS_FAILED(aHdr->GetStringProperty("preview", getter_Copies(utf8previewString)))) return false; // need listener that mailbox is remote such as IMAP // to generate preview message nsString previewString; CopyUTF8toUTF16(utf8previewString, previewString); nsString subject; if (showSubject && NS_FAILED(aHdr->GetMime2DecodedSubject(subject))) return false; nsString author; if (showSender) { nsString fullHeader; if (NS_FAILED(aHdr->GetMime2DecodedAuthor(fullHeader))) return false; ExtractName(DecodedHeader(fullHeader), author); } if (showSubject && showSender) { nsString msgTitle; const char16_t *formatStrings[] = { subject.get(), author.get() }; aBundle->FormatStringFromName(MOZ_UTF16("newMailNotification_messagetitle"), formatStrings, 2, getter_Copies(msgTitle)); alertBody.Append(msgTitle); } else if (showSubject) alertBody.Append(subject); else if (showSender) alertBody.Append(author); if (showPreview && (showSubject || showSender)) { alertBody.AppendLiteral("\n"); } if (showPreview) alertBody.Append(StringHead(previewString, previewLength)); if (alertBody.IsEmpty()) return false; aBody.Assign(alertBody); return true; }
/* static */ PRBool nsMathMLFrame::ParseNumericValue(nsString& aString, nsCSSValue& aCSSValue) { aCSSValue.Reset(); aString.CompressWhitespace(); // aString is not a const in this code... PRInt32 stringLength = aString.Length(); if (!stringLength) return PR_FALSE; nsAutoString number, unit; // Gather up characters that make up the number PRBool gotDot = PR_FALSE; PRUnichar c; for (PRInt32 i = 0; i < stringLength; i++) { c = aString[i]; if (gotDot && c == '.') return PR_FALSE; // two dots encountered else if (c == '.') gotDot = PR_TRUE; else if (!nsCRT::IsAsciiDigit(c)) { aString.Right(unit, stringLength - i); unit.CompressWhitespace(); // some authors leave blanks before the unit break; } number.Append(c); } // on exit, also return a nicer string version of the value in case // the caller wants it (e.g., this removes whitespace before units) aString.Assign(number); aString.Append(unit); // Convert number to floating point PRInt32 errorCode; float floatValue = number.ToFloat(&errorCode); if (errorCode) return PR_FALSE; nsCSSUnit cssUnit; if (unit.IsEmpty()) { cssUnit = eCSSUnit_Number; // no explicit unit, this is a number that will act as a multiplier } else if (unit.EqualsLiteral("%")) { aCSSValue.SetPercentValue(floatValue / 100.0f); return PR_TRUE; } else if (unit.EqualsLiteral("em")) cssUnit = eCSSUnit_EM; else if (unit.EqualsLiteral("ex")) cssUnit = eCSSUnit_XHeight; else if (unit.EqualsLiteral("px")) cssUnit = eCSSUnit_Pixel; else if (unit.EqualsLiteral("in")) cssUnit = eCSSUnit_Inch; else if (unit.EqualsLiteral("cm")) cssUnit = eCSSUnit_Centimeter; else if (unit.EqualsLiteral("mm")) cssUnit = eCSSUnit_Millimeter; else if (unit.EqualsLiteral("pt")) cssUnit = eCSSUnit_Point; else if (unit.EqualsLiteral("pc")) cssUnit = eCSSUnit_Pica; else // unexpected unit return PR_FALSE; aCSSValue.SetFloatValue(floatValue, cssUnit); return PR_TRUE; }
nsValueList(nsString& aData) { mData.Assign(aData); SplitString(mData, mArray); }
bool nsEudoraEditor::GetEmbeddedImageCID(PRUint32 aCIDHash, const nsAString & aOldRef, nsString &aCID) { bool foundMatch = false; PRInt32 startImageTag = 0; PRInt32 closeImageTag = 0; while ( (startImageTag = m_body.Find("<img", true, closeImageTag)) != kNotFound ) { closeImageTag = m_body.Find(">", false, startImageTag); // We should always find a close tag, bail if we don't if (closeImageTag == kNotFound) break; // Find the source attribute and make sure it's for our image tag PRInt32 startSrcValue = m_body.Find("src", true, startImageTag); if ( (startSrcValue == kNotFound) || (startSrcValue > closeImageTag) ) continue; // Move past the src startSrcValue += 3; // Move past any whitespace while ( isspace(m_body.CharAt(startSrcValue)) ) ++startSrcValue; // We should find an = now if (m_body.CharAt(startSrcValue) != '=') continue; // Move past = ++startSrcValue; // Move past any whitespace while ( isspace(m_body.CharAt(startSrcValue)) ) ++startSrcValue; // Get the quote char and verify that it's valid char quoteChar = static_cast <char> (m_body.CharAt(startSrcValue)); if ( (quoteChar != '"') && (quoteChar != '\'') ) continue; // Move past the quote ++startSrcValue; PRInt32 endSrcValue = m_body.FindChar(quoteChar, startSrcValue); PRInt32 srcLength = endSrcValue - startSrcValue; nsString srcValue; aCID.Assign(Substring(m_body, startSrcValue, srcLength)); if (aCIDHash != 0) { // Verify source value starts with "cid:" if (!StringBeginsWith(aCID, NS_LITERAL_STRING("cid:"), nsCaseInsensitiveStringComparator())) continue; // Remove "cid:" from the start aCID.Cut(0, 4); PRUint32 hashValue = EudoraHashString( NS_LossyConvertUTF16toASCII(aCID).get() ); foundMatch = (hashValue == aCIDHash); } else { foundMatch = aCID.Equals(aOldRef); } } return foundMatch; }
bool nsMessengerUnixIntegration::BuildNotificationBody(nsIMsgDBHdr *aHdr, nsIStringBundle *aBundle, nsString &aBody) { nsAutoString alertBody; bool showPreview = true; bool showSubject = true; bool showSender = true; PRInt32 previewLength = SHOW_ALERT_PREVIEW_LENGTH_DEFAULT; nsCOMPtr<nsIPrefBranch> prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID)); if (!prefBranch) return PR_FALSE; prefBranch->GetBoolPref(SHOW_ALERT_PREVIEW, &showPreview); prefBranch->GetBoolPref(SHOW_ALERT_SENDER, &showSender); prefBranch->GetBoolPref(SHOW_ALERT_SUBJECT, &showSubject); prefBranch->GetIntPref(SHOW_ALERT_PREVIEW_LENGTH, &previewLength); nsCOMPtr<nsIMsgHeaderParser> parser = do_GetService(NS_MAILNEWS_MIME_HEADER_PARSER_CONTRACTID); if (!parser) return PR_FALSE; nsCOMPtr<nsIMsgFolder> folder; aHdr->GetFolder(getter_AddRefs(folder)); if (!folder) return PR_FALSE; nsCString msgURI; folder->GetUriForMsg(aHdr, msgURI); bool localOnly; PRUint32 msgURIIndex = mFetchingURIs.IndexOf(msgURI); if (msgURIIndex == -1) { localOnly = PR_FALSE; mFetchingURIs.AppendElement(msgURI); } else localOnly = PR_TRUE; PRUint32 messageKey; if (NS_FAILED(aHdr->GetMessageKey(&messageKey))) return PR_FALSE; bool asyncResult = false; nsresult rv = folder->FetchMsgPreviewText(&messageKey, 1, localOnly, this, &asyncResult); // If we're still waiting on getting the message previews, // bail early. We'll come back later when the async operation // finishes. if (NS_FAILED(rv) || asyncResult) return PR_FALSE; // If we got here, that means that we've retrieved the message preview, // so we can stop tracking it with our mFetchingURIs array. if (msgURIIndex != -1) mFetchingURIs.RemoveElementAt(msgURIIndex); nsCString utf8previewString; if (showPreview && NS_FAILED(aHdr->GetStringProperty("preview", getter_Copies(utf8previewString)))) return PR_FALSE; // need listener that mailbox is remote such as IMAP // to generate preview message nsString previewString; CopyUTF8toUTF16(utf8previewString, previewString); nsString subject; if (showSubject && NS_FAILED(aHdr->GetMime2DecodedSubject(subject))) return PR_FALSE; nsString author; if (showSender) { if (NS_FAILED(aHdr->GetMime2DecodedAuthor(author))) return PR_FALSE; PRUnichar **emails; PRUnichar **names; PRUnichar **fullnames; PRUint32 num; if (NS_FAILED(parser->ParseHeadersWithArray(author.get(), &emails, &names, &fullnames, &num))) return PR_FALSE; if (num > 0) { author.Assign(names[0] ? names[0] : emails[0]); NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(num, emails); NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(num, names); NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(num, fullnames); } } if (showSubject && showSender) { nsString msgTitle; const PRUnichar *formatStrings[] = { subject.get(), author.get() }; aBundle->FormatStringFromName(NS_LITERAL_STRING("newMailNotification_messagetitle").get(), formatStrings, 2, getter_Copies(msgTitle)); alertBody.Append(msgTitle); } else if (showSubject) alertBody.Append(subject); else if (showSender) alertBody.Append(author); if (showPreview && (showSubject || showSender)) { alertBody.AppendLiteral("\n"); } if (showPreview) alertBody.Append(StringHead(previewString, previewLength)); if (alertBody.IsEmpty()) return PR_FALSE; aBody.Assign(alertBody); return PR_TRUE; }
nsresult nsMsgGroupView::HashHdr(nsIMsgDBHdr *msgHdr, nsString& aHashKey) { nsCString cStringKey; aHashKey.Truncate(); nsresult rv = NS_OK; bool rcvDate = false; switch (m_sortType) { case nsMsgViewSortType::bySubject: (void) msgHdr->GetSubject(getter_Copies(cStringKey)); CopyASCIItoUTF16(cStringKey, aHashKey); break; case nsMsgViewSortType::byAuthor: rv = nsMsgDBView::FetchAuthor(msgHdr, aHashKey); break; case nsMsgViewSortType::byRecipient: (void) msgHdr->GetRecipients(getter_Copies(cStringKey)); CopyASCIItoUTF16(cStringKey, aHashKey); break; case nsMsgViewSortType::byAccount: case nsMsgViewSortType::byTags: { nsCOMPtr <nsIMsgDatabase> dbToUse = m_db; if (!dbToUse) // probably search view GetDBForViewIndex(0, getter_AddRefs(dbToUse)); rv = (m_sortType == nsMsgViewSortType::byAccount) ? FetchAccount(msgHdr, aHashKey) : FetchTags(msgHdr, aHashKey); } break; case nsMsgViewSortType::byAttachments: { uint32_t flags; msgHdr->GetFlags(&flags); aHashKey.Assign(flags & nsMsgMessageFlags::Attachment ? '1' : '0'); break; } case nsMsgViewSortType::byFlagged: { uint32_t flags; msgHdr->GetFlags(&flags); aHashKey.Assign(flags & nsMsgMessageFlags::Marked ? '1' : '0'); break; } case nsMsgViewSortType::byPriority: { nsMsgPriorityValue priority; msgHdr->GetPriority(&priority); aHashKey.AppendInt(priority); } break; case nsMsgViewSortType::byStatus: { uint32_t status = 0; GetStatusSortValue(msgHdr, &status); aHashKey.AppendInt(status); } break; case nsMsgViewSortType::byReceived: rcvDate = true; case nsMsgViewSortType::byDate: { uint32_t ageBucket; rv = GetAgeBucketValue(msgHdr, &ageBucket, rcvDate); if (NS_SUCCEEDED(rv)) aHashKey.AppendInt(ageBucket); break; } case nsMsgViewSortType::byCustom: { nsIMsgCustomColumnHandler* colHandler = GetCurColumnHandlerFromDBInfo(); if (colHandler) { rv = colHandler->GetSortStringForRow(msgHdr, aHashKey); break; } } case nsMsgViewSortType::byCorrespondent: if (IsOutgoingMsg(msgHdr)) rv = FetchRecipients(msgHdr, aHashKey); else rv = FetchAuthor(msgHdr, aHashKey); break; default: NS_ASSERTION(false, "no hash key for this type"); rv = NS_ERROR_FAILURE; } return rv; }
/** * Get string of full contents, suitable for debug dump. * It should look exactly like the input source. * @update gess5/11/98 * @return reference to string containing string value */ void CToken::GetSource(nsString& anOutputString) { anOutputString.Assign(GetStringValue()); }