--- a/accessible/base/nsAccessibilityService.cpp
+++ b/accessible/base/nsAccessibilityService.cpp
@@ -797,17 +797,17 @@ nsAccessibilityService::RecreateAccessib
}
void
nsAccessibilityService::GetStringRole(uint32_t aRole, nsAString& aString)
{
#define ROLE(geckoRole, stringRole, atkRole, \
macRole, msaaRole, ia2Role, nameRule) \
case roles::geckoRole: \
- CopyUTF8toUTF16(stringRole, aString); \
+ aString.AssignLiteral(stringRole); \
return;
switch (aRole) {
#include "RoleMap.h"
default:
aString.AssignLiteral("unknown");
return;
}
@@ -987,17 +987,17 @@ nsAccessibilityService::GetStringEventTy
NS_ASSERTION(nsIAccessibleEvent::EVENT_LAST_ENTRY == ArrayLength(kEventTypeNames),
"nsIAccessibleEvent constants are out of sync to kEventTypeNames");
if (aEventType >= ArrayLength(kEventTypeNames)) {
aString.AssignLiteral("unknown");
return;
}
- CopyUTF8toUTF16(kEventTypeNames[aEventType], aString);
+ aString.AssignASCII(kEventTypeNames[aEventType]);
}
void
nsAccessibilityService::GetStringEventType(uint32_t aEventType,
nsACString& aString)
{
MOZ_ASSERT(nsIAccessibleEvent::EVENT_LAST_ENTRY == ArrayLength(kEventTypeNames),
"nsIAccessibleEvent constants are out of sync to kEventTypeNames");
--- a/docshell/base/nsDocShell.cpp
+++ b/docshell/base/nsDocShell.cpp
@@ -4981,17 +4981,17 @@ nsDocShell::LoadErrorPage(nsIURI* aURI,
mLSHE->AbandonBFCacheEntry();
}
nsAutoCString url;
if (aURI) {
nsresult rv = aURI->GetSpec(url);
NS_ENSURE_SUCCESS(rv, rv);
} else if (aURL) {
- CopyUTF16toUTF8(aURL, url);
+ CopyUTF16toUTF8(MakeStringSpan(aURL), url);
} else {
return NS_ERROR_INVALID_POINTER;
}
// Create a URL to pass all the error information through to the page.
#undef SAFE_ESCAPE
#define SAFE_ESCAPE(output, input, params) \
--- a/dom/audiochannel/AudioChannelService.cpp
+++ b/dom/audiochannel/AudioChannelService.cpp
@@ -108,25 +108,25 @@ public:
MOZ_LOG(AudioChannelService::GetAudioChannelLog(), LogLevel::Debug,
("AudioPlaybackRunnable, active = %s, reason = %s\n",
mActive ? "true" : "false", AudibleChangedReasonToStr(mReason)));
return NS_OK;
}
private:
- void GetActiveState(nsAString& astate)
+ void GetActiveState(nsAString& aState)
{
if (mActive) {
- CopyASCIItoUTF16("active", astate);
+ aState.AssignLiteral("active");
} else {
if(mReason == AudioChannelService::AudibleChangedReasons::ePauseStateChanged) {
- CopyASCIItoUTF16("inactive-pause", astate);
+ aState.AssignLiteral("inactive-pause");
} else {
- CopyASCIItoUTF16("inactive-nonaudible", astate);
+ aState.AssignLiteral("inactive-nonaudible");
}
}
}
nsCOMPtr<nsPIDOMWindowOuter> mWindow;
bool mActive;
AudioChannelService::AudibleChangedReasons mReason;
};
--- a/dom/base/DOMException.cpp
+++ b/dom/base/DOMException.cpp
@@ -234,17 +234,17 @@ Exception::GetName(nsAString& aName)
CopyUTF8toUTF16(mName, aName);
} else {
aName.Truncate();
const char* name = nullptr;
nsXPCException::NameAndFormatForNSResult(mResult, &name, nullptr);
if (name) {
- CopyUTF8toUTF16(name, aName);
+ CopyUTF8toUTF16(mozilla::MakeStringSpan(name), aName);
}
}
}
void
Exception::GetFilename(JSContext* aCx, nsAString& aFilename)
{
if (mLocation) {
--- a/dom/base/nsGenericDOMDataNode.cpp
+++ b/dom/base/nsGenericDOMDataNode.cpp
@@ -429,17 +429,17 @@ nsGenericDOMDataNode::ToCString(nsAStrin
aBuf.AppendLiteral("&");
} else if (ch == '<') {
aBuf.AppendLiteral("<");
} else if (ch == '>') {
aBuf.AppendLiteral(">");
} else if ((ch < ' ') || (ch >= 127)) {
char buf[10];
SprintfLiteral(buf, "\\u%04x", ch);
- AppendASCIItoUTF16(buf, aBuf);
+ aBuf.AppendASCII(buf);
} else {
aBuf.Append(ch);
}
}
} else {
unsigned char* cp = (unsigned char*)mText.Get1b() + aOffset;
const unsigned char* end = cp + aLen;
@@ -449,17 +449,17 @@ nsGenericDOMDataNode::ToCString(nsAStrin
aBuf.AppendLiteral("&");
} else if (ch == '<') {
aBuf.AppendLiteral("<");
} else if (ch == '>') {
aBuf.AppendLiteral(">");
} else if ((ch < ' ') || (ch >= 127)) {
char buf[10];
SprintfLiteral(buf, "\\u%04x", ch);
- AppendASCIItoUTF16(buf, aBuf);
+ aBuf.AppendASCII(buf);
} else {
aBuf.Append(ch);
}
}
}
}
#endif
--- a/dom/base/nsGlobalWindowOuter.cpp
+++ b/dom/base/nsGlobalWindowOuter.cpp
@@ -4988,17 +4988,17 @@ nsGlobalWindowOuter::HomeOuter(nsIPrinci
nsAutoString homeURL;
Preferences::GetLocalizedString(PREF_BROWSER_STARTUP_HOMEPAGE, homeURL);
if (homeURL.IsEmpty()) {
// if all else fails, use this
#ifdef DEBUG_seth
printf("all else failed. using %s as the home page\n", DEFAULT_HOME_PAGE);
#endif
- CopyASCIItoUTF16(DEFAULT_HOME_PAGE, homeURL);
+ homeURL.AssignLiteral(DEFAULT_HOME_PAGE);
}
#ifdef MOZ_PHOENIX
{
// Firefox lets the user specify multiple home pages to open in
// individual tabs by separating them with '|'. Since we don't
// have the machinery in place to easily open new tabs from here,
// simply truncate the homeURL at the first '|' character to
--- a/dom/base/nsXMLContentSerializer.cpp
+++ b/dom/base/nsXMLContentSerializer.cpp
@@ -596,19 +596,17 @@ nsXMLContentSerializer::ConfirmPrefix(ns
// to create a namespace decl for the final prefix
return true;
}
void
nsXMLContentSerializer::GenerateNewPrefix(nsAString& aPrefix)
{
aPrefix.Assign('a');
- char buf[128];
- SprintfLiteral(buf, "%d", mPrefixIndex++);
- AppendASCIItoUTF16(buf, aPrefix);
+ aPrefix.AppendInt(mPrefixIndex++);
}
bool
nsXMLContentSerializer::SerializeAttr(const nsAString& aPrefix,
const nsAString& aName,
const nsAString& aValue,
nsAString& aStr,
bool aDoEscapeEntities)
@@ -1254,17 +1252,17 @@ nsXMLContentSerializer::AppendAndTransla
if ((val <= kGTVal) && entityTable[val]) {
entityText = kEntityStrings[entityTable[val]];
break;
}
}
NS_ENSURE_TRUE(aOutputStr.Append(fragmentStart, advanceLength, mozilla::fallible), false);
if (entityText) {
- NS_ENSURE_TRUE(AppendASCIItoUTF16(entityText, aOutputStr, mozilla::fallible), false);
+ NS_ENSURE_TRUE(AppendASCIItoUTF16(mozilla::MakeStringSpan(entityText), aOutputStr, mozilla::fallible), false);
advanceLength++;
}
}
return true;
}
bool
--- a/dom/events/Event.cpp
+++ b/dom/events/Event.cpp
@@ -1229,17 +1229,17 @@ Event::GetWidgetEventType(WidgetEvent* a
if (!aEvent->mSpecifiedEventTypeString.IsEmpty()) {
aType = aEvent->mSpecifiedEventTypeString;
return;
}
const char* name = GetEventName(aEvent->mMessage);
if (name) {
- CopyASCIItoUTF16(name, aType);
+ CopyASCIItoUTF16(mozilla::MakeStringSpan(name), aType);
return;
} else if (aEvent->mMessage == eUnidentifiedEvent &&
aEvent->mSpecifiedEventType) {
// Remove "on"
aType = Substring(nsDependentAtomString(aEvent->mSpecifiedEventType), 2);
aEvent->mSpecifiedEventTypeString = aType;
return;
}
--- a/dom/offline/nsDOMOfflineResourceList.cpp
+++ b/dom/offline/nsDOMOfflineResourceList.cpp
@@ -289,17 +289,17 @@ nsDOMOfflineResourceList::MozItem(uint32
SetDOMStringToNull(aURI);
rv = CacheKeys();
NS_ENSURE_SUCCESS(rv, rv);
if (aIndex >= mCachedKeysCount)
return NS_ERROR_NOT_AVAILABLE;
- CopyUTF8toUTF16(mCachedKeys[aIndex], aURI);
+ CopyUTF8toUTF16(mozilla::MakeStringSpan(mCachedKeys[aIndex]), aURI);
return NS_OK;
}
NS_IMETHODIMP
nsDOMOfflineResourceList::MozAdd(const nsAString& aURI)
{
if (IS_CHILD_PROCESS())
--- a/dom/plugins/base/nsJSNPRuntime.cpp
+++ b/dom/plugins/base/nsJSNPRuntime.cpp
@@ -602,25 +602,25 @@ static void
ThrowJSExceptionASCII(JSContext *cx, const char *message)
{
const char *ex = PeekException();
if (ex) {
nsAutoString ucex;
if (message) {
- AppendASCIItoUTF16(message, ucex);
-
- AppendASCIItoUTF16(" [plugin exception: ", ucex);
+ AppendASCIItoUTF16(mozilla::MakeStringSpan(message), ucex);
+
+ ucex.AppendLiteral(" [plugin exception: ");
}
- AppendUTF8toUTF16(ex, ucex);
+ AppendUTF8toUTF16(mozilla::MakeStringSpan(ex), ucex);
if (message) {
- AppendASCIItoUTF16("].", ucex);
+ ucex.AppendLiteral("].");
}
JSString *str = ::JS_NewUCStringCopyN(cx, ucex.get(), ucex.Length());
if (str) {
JS::Rooted<JS::Value> exn(cx, JS::StringValue(str));
::JS_SetPendingException(cx, exn);
}
--- a/dom/plugins/base/nsNPAPIPluginInstance.cpp
+++ b/dom/plugins/base/nsNPAPIPluginInstance.cpp
@@ -851,17 +851,17 @@ nsNPAPIPluginInstance::GetFormValue(nsAS
{
aValue.Truncate();
char *value = nullptr;
nsresult rv = GetValueFromPlugin(NPPVformValue, &value);
if (NS_FAILED(rv) || !value)
return NS_ERROR_FAILURE;
- CopyUTF8toUTF16(value, aValue);
+ CopyUTF8toUTF16(MakeStringSpan(value), aValue);
// NPPVformValue allocates with NPN_MemAlloc(), which uses
// nsMemory.
free(value);
return NS_OK;
}
--- a/dom/presentation/PresentationRequest.cpp
+++ b/dom/presentation/PresentationRequest.cpp
@@ -211,17 +211,17 @@ PresentationRequest::StartWithDevice(con
return promise.forget();
}
nsID uuid;
uuidgen->GenerateUUIDInPlace(&uuid);
char buffer[NSID_LENGTH];
uuid.ToProvidedString(buffer);
nsAutoString id;
- CopyASCIItoUTF16(buffer, id);
+ CopyASCIItoUTF16(MakeSpan(buffer, NSID_LENGTH - 1), id);
nsCOMPtr<nsIPresentationService> service =
do_GetService(PRESENTATION_SERVICE_CONTRACTID);
if(NS_WARN_IF(!service)) {
promise->MaybeReject(NS_ERROR_DOM_OPERATION_ERR);
return promise.forget();
}
--- a/dom/webbrowserpersist/nsWebBrowserPersist.cpp
+++ b/dom/webbrowserpersist/nsWebBrowserPersist.cpp
@@ -1569,17 +1569,17 @@ nsWebBrowserPersist::GetExtensionForCont
nsresult rv;
if (!mMIMEService)
{
mMIMEService = do_GetService(NS_MIMESERVICE_CONTRACTID, &rv);
NS_ENSURE_TRUE(mMIMEService, NS_ERROR_FAILURE);
}
nsAutoCString contentType;
- LossyCopyUTF16toASCII(aContentType, contentType);
+ LossyCopyUTF16toASCII(MakeStringSpan(aContentType), contentType);
nsAutoCString ext;
rv = mMIMEService->GetPrimaryExtension(contentType, EmptyCString(), ext);
if (NS_SUCCEEDED(rv))
{
*aExt = UTF8ToNewUnicode(ext);
NS_ENSURE_TRUE(*aExt, NS_ERROR_OUT_OF_MEMORY);
return NS_OK;
}
--- a/dom/xhr/XMLHttpRequestWorker.cpp
+++ b/dom/xhr/XMLHttpRequestWorker.cpp
@@ -444,17 +444,17 @@ public:
, mWorkerPrivate(aProxy->mWorkerPrivate)
, mProxy(aProxy)
, mXHR(aProxy->mXHR)
, mXMLHttpRequestPrivate(aXHRPrivate)
, mChannelId(mProxy->mInnerChannelId)
, mReceivedLoadStart(false)
{
AssertIsOnMainThread();
- CopyASCIItoUTF16(sEventStrings[STRING_loadstart], mEventType);
+ mEventType.AssignASCII(sEventStrings[STRING_loadstart]);
}
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_NSIRUNNABLE
NS_DECL_NSIDOMEVENTLISTENER
bool
RegisterAndDispatch()
--- a/dom/xslt/xslt/txEXSLTFunctions.cpp
+++ b/dom/xslt/xslt/txEXSLTFunctions.cpp
@@ -305,17 +305,17 @@ txEXSLTFunctionCall::evaluate(txIEvalCon
nsresult rv = mParams[0]->evaluate(aContext,
getter_AddRefs(exprResult));
NS_ENSURE_SUCCESS(rv, rv);
RefPtr<StringResult> strRes;
rv = aContext->recycler()->getStringResult(getter_AddRefs(strRes));
NS_ENSURE_SUCCESS(rv, rv);
- AppendASCIItoUTF16(sTypes[exprResult->getResultType()],
+ AppendASCIItoUTF16(MakeStringSpan(sTypes[exprResult->getResultType()]),
strRes->mValue);
NS_ADDREF(*aResult = strRes);
return NS_OK;
}
case DIFFERENCE:
case INTERSECTION:
--- a/dom/xslt/xslt/txXSLTNumberCounters.cpp
+++ b/dom/xslt/xslt/txXSLTNumberCounters.cpp
@@ -199,16 +199,16 @@ void txRomanCounter::appendNumber(int32_
aNumber -= 1000;
}
int32_t posValue;
// Hundreds
posValue = aNumber / 100;
aNumber %= 100;
- AppendASCIItoUTF16(kTxRomanNumbers[posValue + mTableOffset], aDest);
+ AppendASCIItoUTF16(mozilla::MakeStringSpan(kTxRomanNumbers[posValue + mTableOffset]), aDest);
// Tens
posValue = aNumber / 10;
aNumber %= 10;
- AppendASCIItoUTF16(kTxRomanNumbers[10 + posValue + mTableOffset], aDest);
+ AppendASCIItoUTF16(mozilla::MakeStringSpan(kTxRomanNumbers[10 + posValue + mTableOffset]), aDest);
// Ones
- AppendASCIItoUTF16(kTxRomanNumbers[20 + aNumber + mTableOffset], aDest);
+ AppendASCIItoUTF16(mozilla::MakeStringSpan(kTxRomanNumbers[20 + aNumber + mTableOffset]), aDest);
}
--- a/editor/libeditor/CSSEditUtils.cpp
+++ b/editor/libeditor/CSSEditUtils.cpp
@@ -63,17 +63,17 @@ void ProcessBValue(const nsAString* aInp
static
void ProcessDefaultValue(const nsAString* aInputString,
nsAString& aOutputString,
const char* aDefaultValueString,
const char* aPrependString,
const char* aAppendString)
{
- CopyASCIItoUTF16(aDefaultValueString, aOutputString);
+ CopyASCIItoUTF16(MakeStringSpan(aDefaultValueString), aOutputString);
}
static
void ProcessSameValue(const nsAString* aInputString,
nsAString & aOutputString,
const char* aDefaultValueString,
const char* aPrependString,
const char* aAppendString)
@@ -90,21 +90,21 @@ void ProcessExtendedValue(const nsAStrin
nsAString& aOutputString,
const char* aDefaultValueString,
const char* aPrependString,
const char* aAppendString)
{
aOutputString.Truncate();
if (aInputString) {
if (aPrependString) {
- AppendASCIItoUTF16(aPrependString, aOutputString);
+ AppendASCIItoUTF16(MakeStringSpan(aPrependString), aOutputString);
}
aOutputString.Append(*aInputString);
if (aAppendString) {
- AppendASCIItoUTF16(aAppendString, aOutputString);
+ AppendASCIItoUTF16(MakeStringSpan(aAppendString), aOutputString);
}
}
}
static
void ProcessLengthValue(const nsAString* aInputString,
nsAString& aOutputString,
const char* aDefaultValueString,
--- a/gfx/thebes/gfxFcPlatformFontList.cpp
+++ b/gfx/thebes/gfxFcPlatformFontList.cpp
@@ -122,41 +122,41 @@ FindCanonicalNameIndex(FcPattern* aFont,
static void
GetFaceNames(FcPattern* aFont, const nsAString& aFamilyName,
nsAString& aPostscriptName, nsAString& aFullname)
{
// get the Postscript name
FcChar8* psname;
if (FcPatternGetString(aFont, FC_POSTSCRIPT_NAME, 0, &psname) == FcResultMatch) {
- AppendUTF8toUTF16(ToCharPtr(psname), aPostscriptName);
+ AppendUTF8toUTF16(MakeStringSpan(ToCharPtr(psname)), aPostscriptName);
}
// get the canonical fullname (i.e. en name or first name)
uint32_t en = FindCanonicalNameIndex(aFont, FC_FULLNAMELANG);
FcChar8* fullname;
if (FcPatternGetString(aFont, FC_FULLNAME, en, &fullname) == FcResultMatch) {
- AppendUTF8toUTF16(ToCharPtr(fullname), aFullname);
+ AppendUTF8toUTF16(MakeStringSpan(ToCharPtr(fullname)), aFullname);
}
// if have fullname, done
if (!aFullname.IsEmpty()) {
return;
}
// otherwise, set the fullname to family + style name [en] and use that
aFullname.Append(aFamilyName);
// figure out the en style name
en = FindCanonicalNameIndex(aFont, FC_STYLELANG);
nsAutoString style;
FcChar8* stylename = nullptr;
FcPatternGetString(aFont, FC_STYLE, en, &stylename);
if (stylename) {
- AppendUTF8toUTF16(ToCharPtr(stylename), style);
+ AppendUTF8toUTF16(MakeStringSpan(ToCharPtr(stylename)), style);
}
if (!style.IsEmpty() && !style.EqualsLiteral("Regular")) {
aFullname.Append(' ');
aFullname.Append(style);
}
}
@@ -1556,17 +1556,17 @@ gfxFcPlatformFontList::AddPatternToFontL
}
// same as the last one? no need to add a new family, skip
if (FcStrCmp(canonical, aLastFamilyName) != 0) {
aLastFamilyName = canonical;
// add new family if one doesn't already exist
aFamilyName.Truncate();
- AppendUTF8toUTF16(ToCharPtr(canonical), aFamilyName);
+ AppendUTF8toUTF16(MakeStringSpan(ToCharPtr(canonical)), aFamilyName);
nsAutoString keyName(aFamilyName);
ToLowerCase(keyName);
aFontFamily = static_cast<gfxFontconfigFontFamily*>
(mFontFamilies.GetWeak(keyName));
if (!aFontFamily) {
aFontFamily = new gfxFontconfigFontFamily(aFamilyName);
mFontFamilies.Put(keyName, aFontFamily);
@@ -1787,17 +1787,17 @@ GetSystemFontList(nsTArray<nsString>& aL
if (FcPatternGetString(fs->fonts[i], FC_FAMILY, 0,
(FcChar8 **) &family) != FcResultMatch)
{
continue;
}
// Remove duplicates...
nsAutoString strFamily;
- AppendUTF8toUTF16(family, strFamily);
+ AppendUTF8toUTF16(MakeStringSpan(family), strFamily);
if (aListOfFonts.Contains(strFamily)) {
continue;
}
aListOfFonts.AppendElement(strFamily);
}
aListOfFonts.Sort();
--- a/js/xpconnect/src/XPCComponents.cpp
+++ b/js/xpconnect/src/XPCComponents.cpp
@@ -2124,17 +2124,17 @@ nsXPCComponents_Utils::ReportError(Handl
if (!scripterr) {
scripterr = new nsScriptError();
}
if (err) {
// It's a proper JS Error
nsAutoString fileUni;
- CopyUTF8toUTF16(err->filename, fileUni);
+ CopyUTF8toUTF16(mozilla::MakeStringSpan(err->filename), fileUni);
uint32_t column = err->tokenOffset();
const char16_t* linebuf = err->linebuf();
nsresult rv = scripterr->InitWithWindowID(
err->message() ? NS_ConvertUTF8toUTF16(err->message().c_str())
: EmptyString(),
--- a/js/xpconnect/src/XPCConvert.cpp
+++ b/js/xpconnect/src/XPCConvert.cpp
@@ -1016,19 +1016,19 @@ JSErrorToXPCException(const char* toStri
Exception** exceptn)
{
AutoJSContext cx;
nsresult rv = NS_ERROR_FAILURE;
RefPtr<nsScriptError> data;
if (report) {
nsAutoString bestMessage;
if (report && report->message()) {
- CopyUTF8toUTF16(report->message().c_str(), bestMessage);
+ CopyUTF8toUTF16(mozilla::MakeStringSpan(report->message().c_str()), bestMessage);
} else if (toStringResult) {
- CopyUTF8toUTF16(toStringResult, bestMessage);
+ CopyUTF8toUTF16(mozilla::MakeStringSpan(toStringResult), bestMessage);
} else {
bestMessage.AssignLiteral("JavaScript Error");
}
const char16_t* linebuf = report->linebuf();
data = new nsScriptError();
data->InitWithWindowID(
--- a/js/xpconnect/src/nsXPConnect.cpp
+++ b/js/xpconnect/src/nsXPConnect.cpp
@@ -179,17 +179,18 @@ nsXPConnect::IsISupportsDescendant(nsIIn
}
void
xpc::ErrorBase::Init(JSErrorBase* aReport)
{
if (!aReport->filename)
mFileName.SetIsVoid(true);
else
- CopyASCIItoUTF16(aReport->filename, mFileName);
+ CopyASCIItoUTF16(mozilla::MakeStringSpan(aReport->filename), mFileName);
+ // XXX should the above use CopyUTF8toUTF16 instead?
mLineNumber = aReport->lineno;
mColumn = aReport->column;
}
void
xpc::ErrorNote::Init(JSErrorNotes::Note* aNote)
{
@@ -204,17 +205,17 @@ xpc::ErrorReport::Init(JSErrorReport* aR
{
xpc::ErrorBase::Init(aReport);
mCategory = aIsChrome ? NS_LITERAL_CSTRING("chrome javascript")
: NS_LITERAL_CSTRING("content javascript");
mWindowID = aWindowID;
ErrorReportToMessageString(aReport, mErrorMsg);
if (mErrorMsg.IsEmpty() && aToStringResult) {
- AppendUTF8toUTF16(aToStringResult, mErrorMsg);
+ AppendUTF8toUTF16(mozilla::MakeStringSpan(aToStringResult), mErrorMsg);
}
mSourceLine.Assign(aReport->linebuf(), aReport->linebufLength());
const JSErrorFormatString* efs = js::GetErrorMessage(nullptr, aReport->errorNumber);
if (efs == nullptr) {
mErrorMsgName.AssignASCII("");
} else {
--- a/layout/generic/nsFrame.cpp
+++ b/layout/generic/nsFrame.cpp
@@ -7852,19 +7852,19 @@ nsFrame::MakeFrameName(const nsAString&
mContent->AsElement()->GetAttr(kNameSpaceID_None, nsGkAtoms::src, src);
buf.AppendLiteral(" src=");
buf.Append(src);
}
aResult.Append('(');
aResult.Append(buf);
aResult.Append(')');
}
- char buf[40];
- SprintfLiteral(buf, "(%d)", ContentIndexInContainer(this));
- AppendASCIItoUTF16(buf, aResult);
+ aResult.Append('(');
+ aResult.AppendInt(ContentIndexInContainer(this));
+ aResult.Append(')');
return NS_OK;
}
void
nsIFrame::DumpFrameTree() const
{
RootFrameList(PresContext(), stderr);
}
--- a/layout/inspector/InspectorUtils.cpp
+++ b/layout/inspector/InspectorUtils.cpp
@@ -523,17 +523,17 @@ static void GetColorsForProperty(const u
if (aParserVariant & VARIANT_COLOR) {
// GetKeywordsForProperty and GetOtherValuesForProperty assume aArray is sorted,
// and if aArray is not empty here, then it's not going to be sorted coming out.
MOZ_ASSERT(aArray.Length() == 0);
size_t size;
const char * const *allColorNames = NS_AllColorNames(&size);
nsString* utf16Names = aArray.AppendElements(size);
for (size_t i = 0; i < size; i++) {
- CopyASCIItoUTF16(allColorNames[i], utf16Names[i]);
+ utf16Names[i].AssignASCII(allColorNames[i]);
}
InsertNoDuplicates(aArray, NS_LITERAL_STRING("currentColor"));
}
}
static void GetOtherValuesForProperty(const uint32_t aParserVariant,
nsTArray<nsString>& aArray)
{
--- a/layout/style/nsCSSParser.cpp
+++ b/layout/style/nsCSSParser.cpp
@@ -6749,27 +6749,27 @@ CSSParserImpl::ParseColor(nsCSSValue& aV
switch (tk->mType) {
case eCSSToken_Ident:
str.Assign(tk->mIdent);
break;
case eCSSToken_Number:
if (tk->mIntegerValid && tk->mInteger < 1000000 && tk->mInteger >= 0) {
SprintfLiteral(buffer, "%06d", tk->mInteger);
- CopyASCIItoUTF16(buffer, str);
+ str.AssignASCII(buffer);
}
break;
case eCSSToken_Dimension:
if (tk->mIntegerValid &&
tk->mIdent.Length() + CountNumbersForHashlessColor(tk->mInteger) <= 6 &&
tk->mInteger >= 0) {
SprintfLiteral(buffer, "%06d", tk->mInteger);
nsAutoString temp;
- CopyASCIItoUTF16(buffer, temp);
+ temp.AssignASCII(buffer);
temp.Right(str, 6 - tk->mIdent.Length());
str.Append(tk->mIdent);
}
break;
default:
// There is a whole bunch of cases that are
// not handled by this switch. Ignore them.
break;
--- a/netwerk/base/Dashboard.cpp
+++ b/netwerk/base/Dashboard.cpp
@@ -763,19 +763,19 @@ Dashboard::GetDNSCacheEntries(DnsData *d
if (!addr) {
JS_ReportOutOfMemory(cx);
return NS_ERROR_OUT_OF_MEMORY;
}
CopyASCIItoUTF16(dnsData->mData[i].hostaddr[j], *addr);
}
if (dnsData->mData[i].family == PR_AF_INET6) {
- CopyASCIItoUTF16("ipv6", entry.mFamily);
+ entry.mFamily.AssignLiteral("ipv6");
} else {
- CopyASCIItoUTF16("ipv4", entry.mFamily);
+ entry.mFamily.AssignLiteral("ipv4");
}
}
JS::RootedValue val(cx);
if (!ToJSValue(cx, dict, &val)) {
return NS_ERROR_FAILURE;
}
dnsData->mCallback->OnDashboardDataAvailable(val);
--- a/netwerk/protocol/http/HttpBaseChannel.cpp
+++ b/netwerk/protocol/http/HttpBaseChannel.cpp
@@ -2398,17 +2398,17 @@ HttpBaseChannel::GetResponseVersion(uint
}
void
HttpBaseChannel::NotifySetCookie(char const *aCookie)
{
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
if (obs) {
nsAutoString cookie;
- CopyASCIItoUTF16(aCookie, cookie);
+ CopyASCIItoUTF16(mozilla::MakeStringSpan(aCookie), cookie);
obs->NotifyObservers(static_cast<nsIChannel*>(this),
"http-on-response-set-cookie",
cookie.get());
}
}
NS_IMETHODIMP
HttpBaseChannel::SetCookie(const char *aCookieHeader)
--- a/netwerk/protocol/http/nsHttpBasicAuth.cpp
+++ b/netwerk/protocol/http/nsHttpBasicAuth.cpp
@@ -84,20 +84,22 @@ nsHttpBasicAuth::GenerateCredentials(nsI
*aFlags = 0;
// we only know how to deal with Basic auth for http.
bool isBasicAuth = !PL_strncasecmp(challenge, "basic", 5);
NS_ENSURE_TRUE(isBasicAuth, NS_ERROR_UNEXPECTED);
// we work with UTF-8 around here
nsAutoCString userpass;
- CopyUTF16toUTF8(user, userpass);
+ if (user) {
+ CopyUTF16toUTF8(mozilla::MakeStringSpan(user), userpass);
+ }
userpass.Append(':'); // always send a ':' (see bug 129565)
if (password) {
- AppendUTF16toUTF8(password, userpass);
+ AppendUTF16toUTF8(mozilla::MakeStringSpan(password), userpass);
}
nsAutoCString authString;
nsresult rv = Base64Encode(userpass, authString);
NS_ENSURE_SUCCESS(rv, rv);
authString.InsertLiteral("Basic ", 0);
--- a/netwerk/protocol/http/nsHttpChannel.cpp
+++ b/netwerk/protocol/http/nsHttpChannel.cpp
@@ -6169,25 +6169,25 @@ nsHttpChannel::BeginConnect()
rv = mRequestHead.SetHeader(nsHttp::Alternate_Service_Used, altUsedLine);
MOZ_ASSERT(NS_SUCCEEDED(rv));
}
nsCOMPtr<nsIConsoleService> consoleService =
do_GetService(NS_CONSOLESERVICE_CONTRACTID);
if (consoleService) {
nsAutoString message(NS_LITERAL_STRING("Alternate Service Mapping found: "));
- AppendASCIItoUTF16(scheme.get(), message);
+ AppendASCIItoUTF16(scheme, message);
message.AppendLiteral(u"://");
- AppendASCIItoUTF16(host.get(), message);
+ AppendASCIItoUTF16(host, message);
message.AppendLiteral(u":");
message.AppendInt(port);
message.AppendLiteral(u" to ");
- AppendASCIItoUTF16(scheme.get(), message);
+ AppendASCIItoUTF16(scheme, message);
message.AppendLiteral(u"://");
- AppendASCIItoUTF16(mapping->AlternateHost().get(), message);
+ AppendASCIItoUTF16(mapping->AlternateHost(), message);
message.AppendLiteral(u":");
message.AppendInt(mapping->AlternatePort());
consoleService->LogStringMessage(message.get());
}
LOG(("nsHttpChannel %p Using connection info from altsvc mapping", this));
mapping->GetConnectionInfo(getter_AddRefs(mConnectionInfo), proxyInfo, originAttributes);
Telemetry::Accumulate(Telemetry::HTTP_TRANSACTION_USE_ALTSVC, true);
--- a/netwerk/streamconv/converters/mozTXTToHTMLConv.cpp
+++ b/netwerk/streamconv/converters/mozTXTToHTMLConv.cpp
@@ -743,21 +743,21 @@ mozTXTToHTMLConv::SmilyHit(const char16_
{
if (!col0)
{
outputHTML.Truncate();
outputHTML.Append(char16_t(' '));
}
outputHTML.AppendLiteral("<span class=\""); // <span class="
- AppendASCIItoUTF16(imageName, outputHTML); // e.g. smiley-frown
+ outputHTML.AppendASCII(imageName); // e.g. smiley-frown
outputHTML.AppendLiteral("\" title=\""); // " title="
- AppendASCIItoUTF16(tagTXT, outputHTML); // smiley tooltip
+ outputHTML.AppendASCII(tagTXT); // smiley tooltip
outputHTML.AppendLiteral("\"><span>"); // "><span>
- AppendASCIItoUTF16(tagTXT, outputHTML); // original text
+ outputHTML.AppendASCII(tagTXT); // original text
outputHTML.AppendLiteral("</span></span>"); // </span></span>
glyphTextLen = (col0 ? 0 : 1) + tagLen;
return true;
}
return false;
}
--- a/netwerk/streamconv/converters/nsTXTToHTMLConv.cpp
+++ b/netwerk/streamconv/converters/nsTXTToHTMLConv.cpp
@@ -142,19 +142,18 @@ nsTXTToHTMLConv::OnDataAvailable(nsIRequ
if (!buffer) return NS_ERROR_OUT_OF_MEMORY;
do {
uint32_t read = 0;
// XXX readSegments, to avoid the first copy?
rv = aInStream->Read(buffer.get(), aCount-amtRead, &read);
if (NS_FAILED(rv)) return rv;
- buffer[read] = '\0';
// XXX charsets?? non-latin1 characters?? utf-16??
- AppendASCIItoUTF16(buffer.get(), mBuffer);
+ AppendASCIItoUTF16(mozilla::MakeSpan(buffer.get(), read), mBuffer);
amtRead += read;
int32_t front = -1, back = -1, tokenLoc = -1, cursor = 0;
while ( (tokenLoc = FindToken(cursor, &mToken)) > -1) {
if (mToken->prepend) {
front = mBuffer.RFindCharInSet(TOKEN_DELIMITERS, tokenLoc);
front++;
--- a/netwerk/wifi/nsWifiAccessPoint.cpp
+++ b/netwerk/wifi/nsWifiAccessPoint.cpp
@@ -30,17 +30,17 @@ NS_IMETHODIMP nsWifiAccessPoint::GetMac(
aMac.Assign(mMac);
return NS_OK;
}
NS_IMETHODIMP nsWifiAccessPoint::GetSsid(nsAString& aSsid)
{
// just assign and embedded nulls will truncate resulting
// in a displayable string.
- CopyASCIItoUTF16(mSsid, aSsid);
+ aSsid.AssignASCII(mSsid);
return NS_OK;
}
NS_IMETHODIMP nsWifiAccessPoint::GetRawSSID(nsACString& aRawSsid)
{
aRawSsid.Assign(mSsid, mSsidLen); // SSIDs are 32 chars long
return NS_OK;
--- a/parser/htmlparser/nsExpatDriver.cpp
+++ b/parser/htmlparser/nsExpatDriver.cpp
@@ -26,16 +26,17 @@
#include "nsUnicharInputStream.h"
#include "nsContentUtils.h"
#include "NullPrincipal.h"
#include "mozilla/Logging.h"
using mozilla::fallible;
using mozilla::LogLevel;
+using mozilla::MakeStringSpan;
#define kExpatSeparatorChar 0xFFFF
static const char16_t kUTF16[] = { 'U', 'T', 'F', '-', '1', '6', '\0' };
static mozilla::LazyLogModule gExpatDriverLog("expatdriver");
/***************************** EXPAT CALL BACKS ******************************/
@@ -572,21 +573,21 @@ nsExpatDriver::HandleExternalEntityRef(c
// Load the external entity into a buffer.
nsCOMPtr<nsIInputStream> in;
nsAutoString absURL;
nsresult rv = OpenInputStreamFromExternalDTD(publicId, systemId, base,
getter_AddRefs(in), absURL);
if (NS_FAILED(rv)) {
#ifdef DEBUG
nsCString message("Failed to open external DTD: publicId \"");
- AppendUTF16toUTF8(publicId, message);
+ AppendUTF16toUTF8(MakeStringSpan(publicId), message);
message += "\" systemId \"";
- AppendUTF16toUTF8(systemId, message);
+ AppendUTF16toUTF8(MakeStringSpan(systemId), message);
message += "\" base \"";
- AppendUTF16toUTF8(base, message);
+ AppendUTF16toUTF8(MakeStringSpan(base), message);
message += "\" URL \"";
AppendUTF16toUTF8(absURL, message);
message += "\"";
NS_WARNING(message.get());
#endif
return 1;
}
--- a/rdf/base/nsRDFContentSink.cpp
+++ b/rdf/base/nsRDFContentSink.cpp
@@ -797,17 +797,17 @@ RDFContentSinkImpl::GetIdAboutAttribute(
// http://www.w3.org/TR/REC-xml#NT-Nmtoken), as per
// 6.21. If we wanted to, this would be where to do it.
// Construct an in-line resource whose URI is the
// document's URI plus the XML name specified in the ID
// attribute.
nsAutoCString name;
nsAutoCString ref('#');
- AppendUTF16toUTF8(aAttributes[1], ref);
+ AppendUTF16toUTF8(MakeStringSpan(aAttributes[1]), ref);
rv = mDocumentURL->Resolve(ref, name);
if (NS_FAILED(rv)) return rv;
return gRDFService->GetResource(name, aResource);
}
else if (localName == nsGkAtoms::nodeID) {
nodeID.Assign(aAttributes[1]);
--- a/security/manager/ssl/PKCS11ModuleDB.cpp
+++ b/security/manager/ssl/PKCS11ModuleDB.cpp
@@ -48,23 +48,23 @@ PKCS11ModuleDB::DeleteModule(const nsASt
// to programmatically query the scalar key length limit, so we have to
// hard-code the value here.)
void
GetModuleNameForTelemetry(/*in*/ const SECMODModule* module,
/*out*/nsString& result)
{
result.Truncate();
if (module->dllName) {
- CopyASCIItoUTF16(module->dllName, result);
+ result.AssignASCII(module->dllName);
int32_t separatorIndex = result.RFind(FILE_PATH_SEPARATOR);
if (separatorIndex != kNotFound) {
result = Substring(result, separatorIndex + 1);
}
} else {
- CopyASCIItoUTF16(module->commonName, result);
+ result.AssignASCII(module->commonName);
}
if (result.Length() >= 70) {
result.Truncate(69);
}
}
// Add a new PKCS11 module to the user's profile.
NS_IMETHODIMP
--- a/security/manager/ssl/nsNSSCertHelper.cpp
+++ b/security/manager/ssl/nsNSSCertHelper.cpp
@@ -658,17 +658,17 @@ ProcessRawBytes(SECItem* data, nsAString
// string that can later be displayed as a byte
// string. We place a new line after 24 bytes
// to break up extermaly long sequence of bytes.
uint32_t i;
char buffer[5];
for (i = 0; i < data->len; i++) {
SprintfLiteral(buffer, "%02x ", data->data[i]);
- AppendASCIItoUTF16(buffer, text);
+ text.AppendASCII(buffer);
if ((i + 1) % 16 == 0) {
text.AppendLiteral(SEPARATOR);
}
}
return NS_OK;
}
/**
@@ -935,17 +935,17 @@ AppendBMPtoUTF16(const UniquePLArenaPool
be sufficient to just swap bytes, or do nothing */
unsigned int utf8ValLen = len * 3 + 1;
unsigned char* utf8Val =
(unsigned char*)PORT_ArenaZAlloc(arena.get(), utf8ValLen);
if (!PORT_UCS2_UTF8Conversion(
false, data, len, utf8Val, utf8ValLen, &utf8ValLen)) {
return NS_ERROR_FAILURE;
}
- AppendUTF8toUTF16((char*)utf8Val, text);
+ AppendUTF8toUTF16(MakeSpan(reinterpret_cast<char*>(utf8Val), utf8ValLen), text);
return NS_OK;
}
static nsresult
ProcessBMPString(SECItem* extData, nsAString& text)
{
UniquePLArenaPool arena(PORT_NewArena(DER_DEFAULT_CHUNKSIZE));
if (!arena) {
@@ -1247,17 +1247,17 @@ ProcessUserNotice(SECItem* derNotice, ns
SECItem** itemList = notice->noticeReference.noticeNumbers;
while (*itemList) {
unsigned long number;
char buffer[60];
if (SEC_ASN1DecodeInteger(*itemList, &number) == SECSuccess) {
SprintfLiteral(buffer, "#%lu", number);
if (itemList != notice->noticeReference.noticeNumbers)
text.AppendLiteral(", ");
- AppendASCIItoUTF16(buffer, text);
+ text.AppendASCII(buffer);
}
itemList++;
}
}
if (notice->displayText.len != 0) {
text.AppendLiteral(SEPARATOR);
text.AppendLiteral(" ");
switch (notice->displayText.type) {
--- a/security/manager/ssl/nsNSSCertificate.cpp
+++ b/security/manager/ssl/nsNSSCertificate.cpp
@@ -369,17 +369,17 @@ nsNSSCertificate::GetDisplayName(nsAStri
return NS_OK;
}
NS_IMETHODIMP
nsNSSCertificate::GetEmailAddress(nsAString& aEmailAddress)
{
if (mCert->emailAddr) {
- CopyUTF8toUTF16(mCert->emailAddr, aEmailAddress);
+ CopyUTF8toUTF16(MakeStringSpan(mCert->emailAddr), aEmailAddress);
} else {
nsresult rv;
nsCOMPtr<nsINSSComponent> nssComponent(do_GetService(kNSSComponentCID, &rv));
if (NS_FAILED(rv) || !nssComponent) {
return NS_ERROR_FAILURE;
}
nssComponent->GetPIPNSSBundleString("CertNoEmailAddress", aEmailAddress);
}
--- a/security/manager/ssl/nsNSSVersion.cpp
+++ b/security/manager/ssl/nsNSSVersion.cpp
@@ -19,74 +19,74 @@ nsNSSVersion::nsNSSVersion()
nsNSSVersion::~nsNSSVersion()
{
}
NS_IMETHODIMP
nsNSSVersion::GetNSPR_Version(nsAString & v)
{
- CopyUTF8toUTF16(PR_GetVersion(), v);
+ v.AssignASCII(PR_GetVersion());
return NS_OK;
}
NS_IMETHODIMP
nsNSSVersion::GetNSS_Version(nsAString & v)
{
- CopyUTF8toUTF16(NSS_GetVersion(), v);
+ v.AssignASCII(NSS_GetVersion());
return NS_OK;
}
NS_IMETHODIMP
nsNSSVersion::GetNSSUTIL_Version(nsAString & v)
{
- CopyUTF8toUTF16(NSSUTIL_GetVersion(), v);
+ v.AssignASCII(NSSUTIL_GetVersion());
return NS_OK;
}
NS_IMETHODIMP
nsNSSVersion::GetNSSSSL_Version(nsAString & v)
{
- CopyUTF8toUTF16(NSSSSL_GetVersion(), v);
+ v.AssignASCII(NSSSSL_GetVersion());
return NS_OK;
}
NS_IMETHODIMP
nsNSSVersion::GetNSSSMIME_Version(nsAString & v)
{
- CopyUTF8toUTF16(NSSSMIME_GetVersion(), v);
+ v.AssignASCII(NSSSMIME_GetVersion());
return NS_OK;
}
NS_IMETHODIMP
nsNSSVersion::GetNSPR_MinVersion(nsAString & v)
{
- CopyUTF8toUTF16(PR_VERSION, v);
+ v.AssignLiteral(PR_VERSION);
return NS_OK;
}
NS_IMETHODIMP
nsNSSVersion::GetNSS_MinVersion(nsAString & v)
{
- CopyUTF8toUTF16(NSS_VERSION, v);
+ v.AssignLiteral(NSS_VERSION);
return NS_OK;
}
NS_IMETHODIMP
nsNSSVersion::GetNSSUTIL_MinVersion(nsAString & v)
{
- CopyUTF8toUTF16(NSSUTIL_VERSION, v);
+ v.AssignLiteral(NSSUTIL_VERSION);
return NS_OK;
}
NS_IMETHODIMP
nsNSSVersion::GetNSSSSL_MinVersion(nsAString & v)
{
- CopyUTF8toUTF16(NSS_VERSION, v);
+ v.AssignLiteral(NSS_VERSION);
return NS_OK;
}
NS_IMETHODIMP
nsNSSVersion::GetNSSSMIME_MinVersion(nsAString & v)
{
- CopyUTF8toUTF16(NSS_VERSION, v);
+ v.AssignLiteral(NSS_VERSION);
return NS_OK;
}
--- a/toolkit/components/windowwatcher/nsWindowWatcher.cpp
+++ b/toolkit/components/windowwatcher/nsWindowWatcher.cpp
@@ -707,17 +707,17 @@ nsWindowWatcher::OpenWindowInternal(mozI
if (NS_FAILED(rv)) {
return rv;
}
uriToLoad->SchemeIs("chrome", &uriToLoadIsChrome);
}
bool nameSpecified = false;
if (aName) {
- CopyUTF8toUTF16(aName, name);
+ CopyUTF8toUTF16(MakeStringSpan(aName), name);
nameSpecified = true;
} else {
name.SetIsVoid(true);
}
if (aFeatures) {
features.Assign(aFeatures);
features.StripWhitespace();
--- a/toolkit/xre/nsAppRunner.cpp
+++ b/toolkit/xre/nsAppRunner.cpp
@@ -2228,17 +2228,17 @@ ShowProfileManager(nsIToolkitProfileServ
NS_ENSURE_SUCCESS(rv, rv);
rv = lock->GetLocalDirectory(getter_AddRefs(profLD));
NS_ENSURE_SUCCESS(rv, rv);
rv = ioParamBlock->GetString(0, &profileNamePtr);
NS_ENSURE_SUCCESS(rv, rv);
- CopyUTF16toUTF8(profileNamePtr, profileName);
+ CopyUTF16toUTF8(MakeStringSpan(profileNamePtr), profileName);
free(profileNamePtr);
lock->Unlock();
}
}
SaveFileToEnv("XRE_PROFILE_PATH", profD);
SaveFileToEnv("XRE_PROFILE_LOCAL_PATH", profLD);
--- a/uriloader/exthandler/nsExternalHelperAppService.cpp
+++ b/uriloader/exthandler/nsExternalHelperAppService.cpp
@@ -2800,17 +2800,17 @@ NS_IMETHODIMP nsExternalHelperAppService
nsAutoCString fileExt;
if (!fileName.IsEmpty())
{
int32_t len = fileName.Length();
for (int32_t i = len; i >= 0; i--)
{
if (fileName[i] == char16_t('.'))
{
- CopyUTF16toUTF8(fileName.get() + i + 1, fileExt);
+ CopyUTF16toUTF8(Substring(fileName, i + 1), fileExt);
break;
}
}
}
if (fileExt.IsEmpty())
return NS_ERROR_FAILURE;
--- a/widget/gtk/IMContextWrapper.cpp
+++ b/widget/gtk/IMContextWrapper.cpp
@@ -1345,17 +1345,17 @@ IMContextWrapper::GetCompositionString(G
nsAString& aCompositionString)
{
gchar *preedit_string;
gint cursor_pos;
PangoAttrList *feedback_list;
gtk_im_context_get_preedit_string(aContext, &preedit_string,
&feedback_list, &cursor_pos);
if (preedit_string && *preedit_string) {
- CopyUTF8toUTF16(preedit_string, aCompositionString);
+ CopyUTF8toUTF16(MakeStringSpan(preedit_string), aCompositionString);
} else {
aCompositionString.Truncate();
}
MOZ_LOG(gGtkIMLog, LogLevel::Info,
("0x%p GetCompositionString(aContext=0x%p), "
"aCompositionString=\"%s\"",
this, aContext, preedit_string));
--- a/widget/gtk/nsDeviceContextSpecG.cpp
+++ b/widget/gtk/nsDeviceContextSpecG.cpp
@@ -416,17 +416,17 @@ nsPrinterEnumeratorGTK::InitPrintSetting
nsresult rv = aPrintSettings->GetToFileName(filename);
if (NS_FAILED(rv) || filename.IsEmpty()) {
const char* path = PR_GetEnv("PWD");
if (!path) {
path = PR_GetEnv("HOME");
}
if (path) {
- CopyUTF8toUTF16(path, filename);
+ CopyUTF8toUTF16(MakeStringSpan(path), filename);
filename.AppendLiteral("/mozilla.pdf");
} else {
filename.AssignLiteral("mozilla.pdf");
}
DO_PR_DEBUG_LOG(("Setting default filename to '%s'\n",
NS_ConvertUTF16toUTF8(filename).get()));
aPrintSettings->SetToFileName(filename);
--- a/widget/nsBaseWidget.cpp
+++ b/widget/nsBaseWidget.cpp
@@ -3220,21 +3220,18 @@ case _value: eventName.AssignLiteral(_na
_ASSIGN_eventName(eReadyStateChange,"eReadyStateChange");
_ASSIGN_eventName(eXULBroadcast, "eXULBroadcast");
_ASSIGN_eventName(eXULCommandUpdate, "eXULCommandUpdate");
#undef _ASSIGN_eventName
default:
{
- char buf[32];
-
- SprintfLiteral(buf,"UNKNOWN: %d",aGuiEvent->mMessage);
-
- CopyASCIItoUTF16(buf, eventName);
+ eventName.AssignLiteral("UNKNOWN: ");
+ eventName.AppendInt(aGuiEvent->mMessage);
}
break;
}
return nsAutoString(eventName);
}
//////////////////////////////////////////////////////////////
//
--- a/xpcom/base/CycleCollectedJSRuntime.cpp
+++ b/xpcom/base/CycleCollectedJSRuntime.cpp
@@ -1624,17 +1624,17 @@ CycleCollectedJSRuntime::ErrorIntercepto
// work, we want to avoid that complex use case.
// Fortunately, we have already checked above that `exn` is an exception object,
// so nothing such should happen.
nsContentUtils::ExtractErrorValues(cx, value, details.mFilename, &details.mLine, &details.mColumn, details.mMessage);
nsAutoCString stack;
JS::UniqueChars buf = JS::FormatStackDump(cx, nullptr, /* showArgs = */ false, /* showLocals = */ false, /* showThisProps = */ false);
stack.Append(buf.get());
- CopyUTF8toUTF16(buf.get(), details.mStack);
+ CopyUTF8toUTF16(mozilla::MakeStringSpan(buf.get()), details.mStack);
mThrownError.emplace(Move(details));
}
void
CycleCollectedJSRuntime::ClearRecentDevError()
{
mErrorInterceptor.mThrownError.reset();
--- a/xpcom/ds/nsVariant.cpp
+++ b/xpcom/ds/nsVariant.cpp
@@ -824,17 +824,17 @@ nsDiscriminatedUnion::ConvertToAString(n
return NS_OK;
case nsIDataType::VTYPE_CSTRING:
CopyASCIItoUTF16(*u.mCStringValue, aResult);
return NS_OK;
case nsIDataType::VTYPE_UTF8STRING:
CopyUTF8toUTF16(*u.mUTF8StringValue, aResult);
return NS_OK;
case nsIDataType::VTYPE_CHAR_STR:
- CopyASCIItoUTF16(u.str.mStringValue, aResult);
+ CopyASCIItoUTF16(mozilla::MakeStringSpan(u.str.mStringValue), aResult);
return NS_OK;
case nsIDataType::VTYPE_WCHAR_STR:
aResult.Assign(u.wstr.mWStringValue);
return NS_OK;
case nsIDataType::VTYPE_STRING_SIZE_IS:
CopyASCIItoUTF16(nsDependentCString(u.str.mStringValue,
u.str.mStringLength),
aResult);
@@ -919,17 +919,17 @@ nsDiscriminatedUnion::ConvertToAUTF8Stri
return NS_OK;
case nsIDataType::VTYPE_CHAR_STR:
// XXX Extra copy, can be removed if we're sure CHAR_STR can
// only contain ASCII.
CopyUTF16toUTF8(NS_ConvertASCIItoUTF16(u.str.mStringValue),
aResult);
return NS_OK;
case nsIDataType::VTYPE_WCHAR_STR:
- CopyUTF16toUTF8(u.wstr.mWStringValue, aResult);
+ CopyUTF16toUTF8(mozilla::MakeStringSpan(u.wstr.mWStringValue), aResult);
return NS_OK;
case nsIDataType::VTYPE_STRING_SIZE_IS:
// XXX Extra copy, can be removed if we're sure CHAR_STR can
// only contain ASCII.
CopyUTF16toUTF8(NS_ConvertASCIItoUTF16(
nsDependentCString(u.str.mStringValue,
u.str.mStringLength)), aResult);
return NS_OK;
--- a/xpcom/string/nsReadableUtils.cpp
+++ b/xpcom/string/nsReadableUtils.cpp
@@ -12,17 +12,16 @@
#include "nscore.h"
#include "nsMemory.h"
#include "nsString.h"
#include "nsTArray.h"
#include "nsUTF8Utils.h"
using mozilla::MakeSpan;
-using mozilla::AsWritableBytes;
/**
* A helper function that allocates a buffer of the desired character type big enough to hold a copy of the supplied string (plus a zero terminator).
*
* @param aSource an string you will eventually be making a copy of
* @return a new buffer (of the type specified by the second parameter) which you must free with |free|.
*
*/
@@ -40,17 +39,17 @@ char*
ToNewCString(const nsAString& aSource)
{
char* dest = AllocateStringCopy(aSource, (char*)nullptr);
if (!dest) {
return nullptr;
}
auto len = aSource.Length();
- LossyConvertUTF16toLatin1(aSource, AsWritableBytes(MakeSpan(dest, len)));
+ LossyConvertUTF16toLatin1(aSource, MakeSpan(dest, len));
dest[len] = 0;
return dest;
}
char*
ToNewUTF8String(const nsAString& aSource, uint32_t* aUTF8Count)
{
auto len = aSource.Length();
@@ -69,17 +68,17 @@ ToNewUTF8String(const nsAString& aSource
if (destLenVal > UINT32_MAX) {
return nullptr;
}
char* dest = static_cast<char*>(moz_xmalloc(destLenVal));
if (!dest) {
return nullptr;
}
- size_t written = ConvertUTF16toUTF8Func(aSource, AsWritableBytes(MakeSpan(dest, destLenVal)));
+ size_t written = ConvertUTF16toUTF8Func(aSource, MakeSpan(dest, destLenVal));
dest[written] = 0;
if (aUTF8Count) {
*aUTF8Count = written;
}
return dest;
}
--- a/xpcom/string/nsReadableUtils.h
+++ b/xpcom/string/nsReadableUtils.h
@@ -16,80 +16,80 @@
#include "mozilla/Assertions.h"
#include "nsAString.h"
#include "nsTArrayForwardDeclare.h"
// Can't include mozilla/Encoding.h here
extern "C" {
size_t encoding_utf8_valid_up_to(uint8_t const* buffer, size_t buffer_len);
- bool encoding_mem_is_ascii(uint8_t const* buffer, size_t buffer_len);
+ bool encoding_mem_is_ascii(char const* buffer, size_t buffer_len);
bool encoding_mem_is_basic_latin(char16_t const* buffer, size_t buffer_len);
- void encoding_mem_convert_utf16_to_latin1_lossy(const char16_t* src, size_t src_len, uint8_t* dst, size_t dst_len);
- void encoding_mem_convert_latin1_to_utf16(const uint8_t* src, size_t src_len, char16_t* dst, size_t dst_len);
- size_t encoding_mem_convert_utf16_to_utf8(const char16_t* src, size_t src_len, uint8_t* dst, size_t dst_len);
- size_t encoding_mem_convert_utf8_to_utf16(const uint8_t* src, size_t src_len, char16_t* dst, size_t dst_len);
+ void encoding_mem_convert_utf16_to_latin1_lossy(const char16_t* src, size_t src_len, char* dst, size_t dst_len);
+ void encoding_mem_convert_latin1_to_utf16(const char* src, size_t src_len, char16_t* dst, size_t dst_len);
+ size_t encoding_mem_convert_utf16_to_utf8(const char16_t* src, size_t src_len, char* dst, size_t dst_len);
+ size_t encoding_mem_convert_utf8_to_utf16(const char* src, size_t src_len, char16_t* dst, size_t dst_len);
}
// From the nsstring crate
extern "C" {
- bool nsstring_fallible_append_utf8_impl(nsAString* aThis, const uint8_t* aOther, size_t aOtherLen, size_t aOldLen);
- bool nsstring_fallible_append_latin1_impl(nsAString* aThis, const uint8_t* aOther, size_t aOtherLen, size_t aOldLen);
+ bool nsstring_fallible_append_utf8_impl(nsAString* aThis, const char* aOther, size_t aOtherLen, size_t aOldLen);
+ bool nsstring_fallible_append_latin1_impl(nsAString* aThis, const char* aOther, size_t aOtherLen, size_t aOldLen);
bool nscstring_fallible_append_utf16_to_utf8_impl(nsACString* aThis, const char16_t*, size_t aOtherLen, size_t aOldLen);
bool nscstring_fallible_append_utf16_to_latin1_lossy_impl(nsACString* aThis, const char16_t*, size_t aOtherLen, size_t aOldLen);
bool nscstring_fallible_append_utf8_to_latin1_lossy_check(nsACString* aThis, const nsACString* aOther, size_t aOldLen);
bool nscstring_fallible_append_latin1_to_utf8_check(nsACString* aThis, const nsACString* aOther, size_t aOldLen);
}
/**
* If all the code points in the input are below U+0100, converts to Latin1, i.e. unsigned byte value is Unicode
* scalar value; not windows-1252. If there are code points above U+00FF, asserts in debug builds and produces
* garbage in release builds. The nature of the garbage depends on the CPU architecture and must not be relied upon.
*
* The length of aDest must be not be less than the length of aSource.
*/
inline void
-LossyConvertUTF16toLatin1(mozilla::Span<const char16_t> aSource, mozilla::Span<uint8_t> aDest)
+LossyConvertUTF16toLatin1(mozilla::Span<const char16_t> aSource, mozilla::Span<char> aDest)
{
encoding_mem_convert_utf16_to_latin1_lossy(aSource.Elements(), aSource.Length(), aDest.Elements(), aDest.Length());
}
/**
* Interprets unsigned byte value as Unicode scalar value (i.e. not windows-1251!).
*
* The length of aDest must be not be less than the length of aSource.
*/
inline void
-ConvertLatin1toUTF16(mozilla::Span<const uint8_t> aSource, mozilla::Span<char16_t> aDest)
+ConvertLatin1toUTF16(mozilla::Span<const char> aSource, mozilla::Span<char16_t> aDest)
{
encoding_mem_convert_latin1_to_utf16(aSource.Elements(), aSource.Length(), aDest.Elements(), aDest.Length());
}
/**
* Lone surrogates are replaced with the REPLACEMENT CHARACTER.
*
* The length of aDest must be at least the length of aSource times three _plus one_.
*
* Returns the number of code units written.
*/
inline size_t
-ConvertUTF16toUTF8Func(mozilla::Span<const char16_t> aSource, mozilla::Span<uint8_t> aDest)
+ConvertUTF16toUTF8Func(mozilla::Span<const char16_t> aSource, mozilla::Span<char> aDest)
{
return encoding_mem_convert_utf16_to_utf8(aSource.Elements(), aSource.Length(), aDest.Elements(), aDest.Length());
}
/**
* Malformed byte sequences are replaced with the REPLACEMENT CHARACTER.
*
* The length of aDest must be not be less than the length of aSource.
*
* Returns the number of code units written.
*/
inline size_t
-ConvertUTF8toUTF16Func(mozilla::Span<const uint8_t> aSource, mozilla::Span<char16_t> aDest)
+ConvertUTF8toUTF16Func(mozilla::Span<const char> aSource, mozilla::Span<char16_t> aDest)
{
return encoding_mem_convert_utf8_to_utf16(aSource.Elements(), aSource.Length(), aDest.Elements(), aDest.Length());
}
inline size_t
Distance(const nsReadingIterator<char16_t>& aStart,
const nsReadingIterator<char16_t>& aEnd)
{
@@ -102,153 +102,80 @@ Distance(const nsReadingIterator<char>&
{
MOZ_ASSERT(aStart.get() <= aEnd.get());
return static_cast<size_t>(aEnd.get() - aStart.get());
}
// UTF-8 to UTF-16
// Invalid UTF-8 byte sequences are replaced with the REPLACEMENT CHARACTER.
-inline MOZ_MUST_USE bool CopyUTF8toUTF16(mozilla::Span<const uint8_t> aSource,
+inline MOZ_MUST_USE bool CopyUTF8toUTF16(mozilla::Span<const char> aSource,
nsAString& aDest,
const mozilla::fallible_t&)
{
return nsstring_fallible_append_utf8_impl(&aDest, aSource.Elements(), aSource.Length(), 0);
}
-inline void CopyUTF8toUTF16(mozilla::Span<const uint8_t> aSource,
+inline void CopyUTF8toUTF16(mozilla::Span<const char> aSource,
nsAString& aDest)
{
if (MOZ_UNLIKELY(!CopyUTF8toUTF16(aSource, aDest, mozilla::fallible))) {
aDest.AllocFailed(aSource.Length());
}
}
-inline MOZ_MUST_USE bool AppendUTF8toUTF16(mozilla::Span<const uint8_t> aSource,
+inline MOZ_MUST_USE bool AppendUTF8toUTF16(mozilla::Span<const char> aSource,
nsAString& aDest,
const mozilla::fallible_t&)
{
return nsstring_fallible_append_utf8_impl(&aDest, aSource.Elements(), aSource.Length(), aDest.Length());
}
-inline void AppendUTF8toUTF16(mozilla::Span<const uint8_t> aSource,
+inline void AppendUTF8toUTF16(mozilla::Span<const char> aSource,
nsAString& aDest)
{
if (MOZ_UNLIKELY(!AppendUTF8toUTF16(aSource, aDest, mozilla::fallible))) {
aDest.AllocFailed(aDest.Length() + aSource.Length());
}
}
-inline MOZ_MUST_USE bool CopyUTF8toUTF16(const char* aSource,
- nsAString& aDest,
- const mozilla::fallible_t&)
-{
- if (aSource) {
- return CopyUTF8toUTF16(mozilla::AsBytes(mozilla::MakeStringSpan(aSource)), aDest, mozilla::fallible);
- }
- return true;
-}
-
-inline void CopyUTF8toUTF16(const char* aSource,
- nsAString& aDest)
-{
- if (aSource) {
- CopyUTF8toUTF16(mozilla::AsBytes(mozilla::MakeStringSpan(aSource)), aDest);
- }
-}
-
-
-inline MOZ_MUST_USE bool AppendUTF8toUTF16(const char* aSource,
- nsAString& aDest,
- const mozilla::fallible_t&)
-{
- if (aSource) {
- return AppendUTF8toUTF16(mozilla::AsBytes(mozilla::MakeStringSpan(aSource)), aDest, mozilla::fallible);
- }
- return true;
-}
-
-inline void AppendUTF8toUTF16(const char* aSource,
- nsAString& aDest)
-{
- if (aSource) {
- AppendUTF8toUTF16(mozilla::AsBytes(mozilla::MakeStringSpan(aSource)), aDest);
- }
-}
-
// Latin1 to UTF-16
// Interpret each incoming unsigned byte value as a Unicode scalar value (not windows-1252!).
// The function names say "ASCII" instead of "Latin1" for legacy reasons.
-inline MOZ_MUST_USE bool CopyASCIItoUTF16(mozilla::Span<const uint8_t> aSource,
+inline MOZ_MUST_USE bool CopyASCIItoUTF16(mozilla::Span<const char> aSource,
nsAString& aDest,
const mozilla::fallible_t&)
{
return nsstring_fallible_append_latin1_impl(&aDest, aSource.Elements(), aSource.Length(), 0);
}
-inline void CopyASCIItoUTF16(mozilla::Span<const uint8_t> aSource,
+inline void CopyASCIItoUTF16(mozilla::Span<const char> aSource,
nsAString& aDest)
{
if (MOZ_UNLIKELY(!CopyASCIItoUTF16(aSource, aDest, mozilla::fallible))) {
aDest.AllocFailed(aSource.Length());
}
}
-inline MOZ_MUST_USE bool AppendASCIItoUTF16(mozilla::Span<const uint8_t> aSource,
+inline MOZ_MUST_USE bool AppendASCIItoUTF16(mozilla::Span<const char> aSource,
nsAString& aDest,
const mozilla::fallible_t&)
{
return nsstring_fallible_append_latin1_impl(&aDest, aSource.Elements(), aSource.Length(), aDest.Length());
}
-inline void AppendASCIItoUTF16(mozilla::Span<const uint8_t> aSource,
+inline void AppendASCIItoUTF16(mozilla::Span<const char> aSource,
nsAString& aDest)
{
if (MOZ_UNLIKELY(!AppendASCIItoUTF16(aSource, aDest, mozilla::fallible))) {
aDest.AllocFailed(aDest.Length() + aSource.Length());
}
}
-inline MOZ_MUST_USE bool CopyASCIItoUTF16(const char* aSource,
- nsAString& aDest,
- const mozilla::fallible_t&)
-{
- if (aSource) {
- return CopyASCIItoUTF16(mozilla::AsBytes(mozilla::MakeStringSpan(aSource)), aDest, mozilla::fallible);
- }
- return true;
-}
-
-inline void CopyASCIItoUTF16(const char* aSource,
- nsAString& aDest)
-{
- if (aSource) {
- CopyASCIItoUTF16(mozilla::AsBytes(mozilla::MakeStringSpan(aSource)), aDest);
- }
-}
-
-inline MOZ_MUST_USE bool AppendASCIItoUTF16(const char* aSource,
- nsAString& aDest,
- const mozilla::fallible_t&)
-{
- if (aSource) {
- return AppendASCIItoUTF16(mozilla::AsBytes(mozilla::MakeStringSpan(aSource)), aDest, mozilla::fallible);
- }
- return true;
-}
-
-inline void AppendASCIItoUTF16(const char* aSource,
- nsAString& aDest)
-{
- if (aSource) {
- AppendASCIItoUTF16(mozilla::AsBytes(mozilla::MakeStringSpan(aSource)), aDest);
- }
-}
-
// UTF-16 to UTF-8
// Unpaired surrogates are replaced with the REPLACEMENT CHARACTER.
inline MOZ_MUST_USE bool CopyUTF16toUTF8(mozilla::Span<const char16_t> aSource,
nsACString& aDest,
const mozilla::fallible_t&)
{
return nscstring_fallible_append_utf16_to_utf8_impl(&aDest, aSource.Elements(), aSource.Length(), 0);
@@ -272,52 +199,16 @@ inline MOZ_MUST_USE bool AppendUTF16toUT
inline void AppendUTF16toUTF8(mozilla::Span<const char16_t> aSource,
nsACString& aDest)
{
if (MOZ_UNLIKELY(!AppendUTF16toUTF8(aSource, aDest, mozilla::fallible))) {
aDest.AllocFailed(aDest.Length() + aSource.Length());
}
}
-inline MOZ_MUST_USE bool CopyUTF16toUTF8(const char16_t* aSource,
- nsACString& aDest,
- const mozilla::fallible_t&)
-{
- if (aSource) {
- return CopyUTF16toUTF8(mozilla::MakeStringSpan(aSource), aDest, mozilla::fallible);
- }
- return true;
-}
-
-inline void CopyUTF16toUTF8(const char16_t* aSource,
- nsACString& aDest)
-{
- if (aSource) {
- CopyUTF16toUTF8(mozilla::MakeStringSpan(aSource), aDest);
- }
-}
-
-inline MOZ_MUST_USE bool AppendUTF16toUTF8(const char16_t* aSource,
- nsACString& aDest,
- const mozilla::fallible_t&)
-{
- if (aSource) {
- return AppendUTF16toUTF8(mozilla::MakeStringSpan(aSource), aDest, mozilla::fallible);
- }
- return true;
-}
-
-inline void AppendUTF16toUTF8(const char16_t* aSource,
- nsACString& aDest)
-{
- if (aSource) {
- AppendUTF16toUTF8(mozilla::MakeStringSpan(aSource), aDest);
- }
-}
-
// UTF-16 to Latin1
// If all code points in the input are below U+0100, represents each scalar value
// as an unsigned byte. (This is not windows-1252!)
// If there are code points above U+00FF, asserts in debug builds and memory-safely
// produces garbage in release builds. The nature of the garbage may differ based on
// CPU architecture and must not be relied upon.
// The names say "ASCII" instead of "Latin1" for legacy reasons.
@@ -346,52 +237,16 @@ inline MOZ_MUST_USE bool LossyAppendUTF1
inline void LossyAppendUTF16toASCII(mozilla::Span<const char16_t> aSource,
nsACString& aDest)
{
if (MOZ_UNLIKELY(!LossyAppendUTF16toASCII(aSource, aDest, mozilla::fallible))) {
aDest.AllocFailed(aDest.Length() + aSource.Length());
}
}
-inline MOZ_MUST_USE bool LossyCopyUTF16toASCII(const char16_t* aSource,
- nsACString& aDest,
- const mozilla::fallible_t&)
-{
- if (aSource) {
- return LossyCopyUTF16toASCII(mozilla::MakeStringSpan(aSource), aDest, mozilla::fallible);
- }
- return true;
-}
-
-inline void LossyCopyUTF16toASCII(const char16_t* aSource,
- nsACString& aDest)
-{
- if (aSource) {
- LossyCopyUTF16toASCII(mozilla::MakeStringSpan(aSource), aDest);
- }
-}
-
-inline MOZ_MUST_USE bool LossyAppendUTF16toASCII(const char16_t* aSource,
- nsACString& aDest,
- const mozilla::fallible_t&)
-{
- if (aSource) {
- return LossyAppendUTF16toASCII(mozilla::MakeStringSpan(aSource), aDest, mozilla::fallible);
- }
- return true;
-}
-
-inline void LossyAppendUTF16toASCII(const char16_t* aSource,
- nsACString& aDest)
-{
- if (aSource) {
- LossyAppendUTF16toASCII(mozilla::MakeStringSpan(aSource), aDest);
- }
-}
-
/**
* Returns a new |char| buffer containing a zero-terminated copy of |aSource|.
*
* Allocates and returns a new |char| buffer which you must free with |free|.
* Performs a lossy encoding conversion by chopping 16-bit wide characters down to 8-bits wide while copying |aSource| to your new buffer.
* This conversion is not well defined; but it reproduces legacy string behavior.
* The new buffer is zero-terminated, but that may not help you if |aSource| contains embedded nulls.
*
@@ -566,17 +421,17 @@ inline bool IsASCII(mozilla::Span<const
return encoding_mem_is_basic_latin(aString.Elements(), aString.Length());
}
/**
* Returns |true| if |aString| contains only ASCII characters, that is, characters in the range (0x00, 0x7F).
*
* @param aString a 8-bit wide string to scan
*/
-inline bool IsASCII(mozilla::Span<const uint8_t> aString)
+inline bool IsASCII(mozilla::Span<const char> aString)
{
return encoding_mem_is_ascii(aString.Elements(), aString.Length());
}
/**
* Returns |true| if |aString| is a valid UTF-8 string.
*
* Note that this doesn't check whether the string might look like a valid
--- a/xpcom/string/nsString.h
+++ b/xpcom/string/nsString.h
@@ -42,17 +42,17 @@ static_assert(sizeof(nsTLiteralString<ch
/**
* A helper class that converts a UTF-16 string to ASCII in a lossy manner
*/
class NS_LossyConvertUTF16toASCII : public nsAutoCString
{
public:
explicit NS_LossyConvertUTF16toASCII(const char16ptr_t aString)
{
- LossyAppendUTF16toASCII(aString, *this);
+ LossyAppendUTF16toASCII(mozilla::MakeStringSpan(aString), *this);
}
NS_LossyConvertUTF16toASCII(const char16ptr_t aString, uint32_t aLength)
{
LossyAppendUTF16toASCII(Substring(static_cast<const char16_t*>(aString), aLength), *this);
}
explicit NS_LossyConvertUTF16toASCII(const nsAString& aString)
@@ -66,17 +66,17 @@ private:
};
class NS_ConvertASCIItoUTF16 : public nsAutoString
{
public:
explicit NS_ConvertASCIItoUTF16(const char* aCString)
{
- AppendASCIItoUTF16(aCString, *this);
+ AppendASCIItoUTF16(mozilla::MakeStringSpan(aCString), *this);
}
NS_ConvertASCIItoUTF16(const char* aCString, uint32_t aLength)
{
AppendASCIItoUTF16(Substring(aCString, aLength), *this);
}
explicit NS_ConvertASCIItoUTF16(const nsACString& aCString)
@@ -93,17 +93,17 @@ private:
/**
* A helper class that converts a UTF-16 string to UTF-8
*/
class NS_ConvertUTF16toUTF8 : public nsAutoCString
{
public:
explicit NS_ConvertUTF16toUTF8(const char16ptr_t aString)
{
- AppendUTF16toUTF8(aString, *this);
+ AppendUTF16toUTF8(mozilla::MakeStringSpan(aString), *this);
}
NS_ConvertUTF16toUTF8(const char16ptr_t aString, uint32_t aLength)
{
AppendUTF16toUTF8(Substring(static_cast<const char16_t*>(aString), aLength), *this);
}
explicit NS_ConvertUTF16toUTF8(const nsAString& aString)
@@ -117,17 +117,17 @@ private:
};
class NS_ConvertUTF8toUTF16 : public nsAutoString
{
public:
explicit NS_ConvertUTF8toUTF16(const char* aCString)
{
- AppendUTF8toUTF16(aCString, *this);
+ AppendUTF8toUTF16(mozilla::MakeStringSpan(aCString), *this);
}
NS_ConvertUTF8toUTF16(const char* aCString, uint32_t aLength)
{
AppendUTF8toUTF16(Substring(aCString, aLength), *this);
}
explicit NS_ConvertUTF8toUTF16(const nsACString& aCString)
--- a/xpcom/tests/gtest/TestCRT.cpp
+++ b/xpcom/tests/gtest/TestCRT.cpp
@@ -37,18 +37,18 @@ static void Check(const char* s1, const
int clib = PL_strcmp(s1, s2);
int clib_n = PL_strncmp(s1, s2, n);
if (!longerThanN) {
EXPECT_EQ(sign(clib), sign(clib_n));
}
nsAutoString t1,t2;
- CopyASCIItoUTF16(s1, t1);
- CopyASCIItoUTF16(s2, t2);
+ CopyASCIItoUTF16(mozilla::MakeStringSpan(s1), t1);
+ CopyASCIItoUTF16(mozilla::MakeStringSpan(s2), t2);
const char16_t* us1 = t1.get();
const char16_t* us2 = t2.get();
int u2, u2_n;
u2 = nsCRT::strcmp(us1, us2);
EXPECT_EQ(sign(clib), sign(u2));
--- a/xpcom/tests/gtest/TestStrings.cpp
+++ b/xpcom/tests/gtest/TestStrings.cpp
@@ -403,22 +403,20 @@ TEST(Strings, replace_substr)
s.AssignLiteral("foofoofoo");
s.ReplaceSubstring("of", "fo");
EXPECT_STREQ(s.get(), "fofoofooo");
}
TEST(Strings, replace_substr_2)
{
- const char *oldName = nullptr;
const char *newName = "user";
nsString acctName; acctName.AssignLiteral("forums.foo.com");
nsAutoString newAcctName, oldVal, newVal;
- CopyASCIItoUTF16(oldName, oldVal);
- CopyASCIItoUTF16(newName, newVal);
+ CopyASCIItoUTF16(mozilla::MakeStringSpan(newName), newVal);
newAcctName.Assign(acctName);
// here, oldVal is empty. we are testing that this function
// does not hang. see bug 235355.
newAcctName.ReplaceSubstring(oldVal, newVal);
// we expect that newAcctName will be unchanged.
EXPECT_TRUE(newAcctName.Equals(acctName));
--- a/xpfe/appshell/nsXULWindow.cpp
+++ b/xpfe/appshell/nsXULWindow.cpp
@@ -1666,67 +1666,62 @@ NS_IMETHODIMP nsXULWindow::SavePersisten
nsCOMPtr<nsIBaseWindow> parent(do_QueryReferent(mParentWindow));
if (parent && gotRestoredBounds) {
int32_t parentX, parentY;
if (NS_SUCCEEDED(parent->GetPosition(&parentX, &parentY))) {
rect.MoveBy(-parentX, -parentY);
}
}
- char sizeBuf[10];
nsAutoString sizeString;
nsAutoString windowElementId;
RefPtr<dom::XULDocument> ownerXULDoc;
// fetch docShellElement's ID and XUL owner document
ownerXULDoc = docShellElement->OwnerDoc()->AsXULDocument();
if (docShellElement->IsXULElement()) {
docShellElement->GetId(windowElementId);
}
bool shouldPersist = !isFullscreen && ownerXULDoc;
ErrorResult rv;
// (only for size elements which are persisted)
if ((mPersistentAttributesDirty & PAD_POSITION) && gotRestoredBounds) {
if (persistString.Find("screenX") >= 0) {
- SprintfLiteral(sizeBuf, "%d", NSToIntRound(rect.X() / posScale.scale));
- CopyASCIItoUTF16(sizeBuf, sizeString);
+ sizeString.AppendInt(NSToIntRound(rect.X() / posScale.scale));
docShellElement->SetAttribute(SCREENX_ATTRIBUTE, sizeString, rv);
if (shouldPersist) {
IgnoredErrorResult err;
ownerXULDoc->Persist(windowElementId, SCREENX_ATTRIBUTE, err);
}
}
if (persistString.Find("screenY") >= 0) {
- SprintfLiteral(sizeBuf, "%d", NSToIntRound(rect.Y() / posScale.scale));
- CopyASCIItoUTF16(sizeBuf, sizeString);
+ sizeString.AppendInt(NSToIntRound(rect.Y() / posScale.scale));
docShellElement->SetAttribute(SCREENY_ATTRIBUTE, sizeString, rv);
if (shouldPersist) {
IgnoredErrorResult err;
ownerXULDoc->Persist(windowElementId, SCREENY_ATTRIBUTE, err);
}
}
}
if ((mPersistentAttributesDirty & PAD_SIZE) && gotRestoredBounds) {
LayoutDeviceIntSize winDiff = GetWindowOuterInnerDiff(mWindow);
if (persistString.Find("width") >= 0) {
auto width = rect.Width() - winDiff.width;
- SprintfLiteral(sizeBuf, "%d", NSToIntRound(width / sizeScale.scale));
- CopyASCIItoUTF16(sizeBuf, sizeString);
+ sizeString.AppendInt(NSToIntRound(width / sizeScale.scale));
docShellElement->SetAttribute(WIDTH_ATTRIBUTE, sizeString, rv);
if (shouldPersist) {
IgnoredErrorResult err;
ownerXULDoc->Persist(windowElementId, WIDTH_ATTRIBUTE, err);
}
}
if (persistString.Find("height") >= 0) {
auto height = rect.Height() - winDiff.height;
- SprintfLiteral(sizeBuf, "%d", NSToIntRound(height / sizeScale.scale));
- CopyASCIItoUTF16(sizeBuf, sizeString);
+ sizeString.AppendInt(NSToIntRound(height / sizeScale.scale));
docShellElement->SetAttribute(HEIGHT_ATTRIBUTE, sizeString, rv);
if (shouldPersist) {
IgnoredErrorResult err;
ownerXULDoc->Persist(windowElementId, HEIGHT_ATTRIBUTE, err);
}
}
}
@@ -1746,18 +1741,17 @@ NS_IMETHODIMP nsXULWindow::SavePersisten
ownerXULDoc->Persist(windowElementId, MODE_ATTRIBUTE, err);
}
}
if (persistString.Find("zlevel") >= 0) {
uint32_t zLevel;
nsCOMPtr<nsIWindowMediator> mediator(do_GetService(NS_WINDOWMEDIATOR_CONTRACTID));
if (mediator) {
mediator->GetZLevel(this, &zLevel);
- SprintfLiteral(sizeBuf, "%" PRIu32, zLevel);
- CopyASCIItoUTF16(sizeBuf, sizeString);
+ sizeString.AppendInt(zLevel);
docShellElement->SetAttribute(ZLEVEL_ATTRIBUTE, sizeString, rv);
if (shouldPersist) {
IgnoredErrorResult err;
ownerXULDoc->Persist(windowElementId, ZLEVEL_ATTRIBUTE, err);
}
}
}
}
--- a/xpfe/components/directory/nsDirectoryViewer.cpp
+++ b/xpfe/components/directory/nsDirectoryViewer.cpp
@@ -158,17 +158,17 @@ nsHTTPIndex::OnFTPControlLog(bool server
dom::AutoEntryScript aes(globalObject,
"nsHTTPIndex OnFTPControlLog");
JSContext* cx = aes.cx();
JS::Rooted<JSObject*> global(cx, JS::CurrentGlobalOrNull(cx));
NS_ENSURE_TRUE(global, NS_OK);
nsString unicodeMsg;
- CopyASCIItoUTF16(msg, unicodeMsg);
+ CopyASCIItoUTF16(MakeStringSpan(msg), unicodeMsg);
JSString* jsMsgStr = JS_NewUCStringCopyZ(cx, unicodeMsg.get());
NS_ENSURE_TRUE(jsMsgStr, NS_ERROR_OUT_OF_MEMORY);
JS::AutoValueArray<2> params(cx);
params[0].setBoolean(server);
params[1].setString(jsMsgStr);
JS::Rooted<JS::Value> val(cx);