本文整理汇总了C++中nsString::Assign方法的典型用法代码示例。如果您正苦于以下问题:C++ nsString::Assign方法的具体用法?C++ nsString::Assign怎么用?C++ nsString::Assign使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nsString
的用法示例。
在下文中一共展示了nsString::Assign方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
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);
}
}
示例2: ce
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;
}
示例3:
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);
}
}
示例4: ConvertJSValToStr
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();
}
}
示例5: GetBundle
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;
}
示例6:
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);
}
}
示例7:
//--------------------------------------------------------
// 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;
}
示例8: if
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(']'));
}
}
示例9: GetSource
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('>'));
}
示例10: setPath
void
setPath(const nsAString& aPath) {
mPath.Assign(aPath);
NormalizeFilePath();
}
示例11:
gluezilla_stringSet(nsString & str, PRUnichar * text)
{
str.Assign (text);
}
示例12: if
/* 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;
}
示例13: nsValueList
nsValueList(nsString& aData) {
mData.Assign(aData);
SplitString(mData, mArray);
}
示例14: if
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);
//.........这里部分代码省略.........
示例15: HashHdr
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;
}