Skip to content

Commit

Permalink
Bug 1772006 - Part 6: Simplify and move the find+replace methods from…
Browse files Browse the repository at this point in the history
… ns[T]StringObsolete, r=xpcom-reviewers,barret

The remaining methods in ns[T]StringObsolete are all find+replace methods for
nsTSubstring. These were migrated in a similar way to the find methods, and
partially updated to avoid using methods from nsStringObsolete.cpp.

This change removes the ns[T]StringObsolete.cpp files completely, as they are
no longer necessary.

Differential Revision: https://phabricator.services.mozilla.com/D148301
  • Loading branch information
mystor committed Jul 30, 2022
1 parent 80b7664 commit e3fbeb4
Show file tree
Hide file tree
Showing 13 changed files with 241 additions and 931 deletions.
2 changes: 1 addition & 1 deletion caps/OriginAttributes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ void OriginAttributes::CreateSuffix(nsACString& aStr) const {
if (!mGeckoViewSessionContextId.IsEmpty()) {
nsAutoString sanitizedGeckoViewUserContextId(mGeckoViewSessionContextId);
sanitizedGeckoViewUserContextId.ReplaceChar(
dom::quota::QuotaManager::kReplaceChars, kSanitizedChar);
dom::quota::QuotaManager::kReplaceChars16, kSanitizedChar);

params.Set(u"geckoViewUserContextId"_ns, sanitizedGeckoViewUserContextId);
}
Expand Down
6 changes: 3 additions & 3 deletions dom/base/nsContentAreaDragDrop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,8 @@ nsContentAreaDragDropDataProvider::GetFlavorData(nsITransferable* aTransferable,
nsIMIMEService::VALIDATE_DEFAULT, targetFilename);
} else {
// make the filename safe for the filesystem
targetFilename.ReplaceChar(FILE_PATH_SEPARATOR FILE_ILLEGAL_CHARACTERS,
'-');
targetFilename.ReplaceChar(
u"" FILE_PATH_SEPARATOR FILE_ILLEGAL_CHARACTERS, u'-');
}
#endif /* defined(XP_MACOSX) */

Expand Down Expand Up @@ -745,7 +745,7 @@ nsresult DragDataProducer::AddStringsToDataTransfer(
// that expects url\ntitle formatted data for x-moz-url.
nsAutoString title(mTitleString);
title.Trim("\r\n");
title.ReplaceChar("\r\n", ' ');
title.ReplaceChar(u"\r\n", ' ');
dragData += title;

AddString(aDataTransfer, NS_LITERAL_STRING_FROM_CSTRING(kURLMime), dragData,
Expand Down
2 changes: 1 addition & 1 deletion dom/canvas/CanvasRenderingContext2D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3685,7 +3685,7 @@ void CanvasRenderingContext2D::GetFontKerning(nsAString& aFontKerning) {
* @param str The string whose whitespace characters to replace.
*/
static inline void TextReplaceWhitespaceCharacters(nsAutoString& aStr) {
aStr.ReplaceChar("\x09\x0A\x0B\x0C\x0D", char16_t(' '));
aStr.ReplaceChar(u"\x09\x0A\x0B\x0C\x0D", char16_t(' '));
}

void CanvasRenderingContext2D::FillText(const nsAString& aText, double aX,
Expand Down
4 changes: 2 additions & 2 deletions dom/media/gmp/GMPParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,10 @@ RefPtr<GenericPromise> GMPParent::Init(GeckoMediaPluginServiceParent* aService,
// set |mChildLaunchArch| to x64 and allow the library to be used as long
// as this process is a universal binary.
if (!(pluginArch & arm64) && (pluginArch & x86)) {
bool isWidevine = parentLeafName.Find("widevine") != kNotFound;
bool isWidevine = parentLeafName.Find(u"widevine") != kNotFound;
bool isWidevineAllowed =
StaticPrefs::media_gmp_widevinecdm_allow_x64_plugin_on_arm64();
bool isH264 = parentLeafName.Find("openh264") != kNotFound;
bool isH264 = parentLeafName.Find(u"openh264") != kNotFound;
bool isH264Allowed =
StaticPrefs::media_gmp_gmpopenh264_allow_x64_plugin_on_arm64();

Expand Down
2 changes: 2 additions & 0 deletions dom/quota/ActorsParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,8 @@ using mozilla::net::MozURL;
// of illegal characters so we use its FILE_ILLEGAL_CHARACTERS and
// FILE_PATH_SEPARATOR.
const char QuotaManager::kReplaceChars[] = CONTROL_CHARACTERS "/:*?\"<>|\\";
const char16_t QuotaManager::kReplaceChars16[] =
u"" CONTROL_CHARACTERS "/:*?\"<>|\\";

namespace {

Expand Down
1 change: 1 addition & 0 deletions dom/quota/QuotaManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ class QuotaManager final : public BackgroundThreadObject {
}

static const char kReplaceChars[];
static const char16_t kReplaceChars16[];

static Result<MovingNotNull<RefPtr<QuotaManager>>, nsresult> GetOrCreate();

Expand Down
2 changes: 1 addition & 1 deletion extensions/spellcheck/hunspell/glue/mozHunspell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ mozHunspell::LoadDictionariesFromDir(nsIFile* aDir) {
if (NS_FAILED(rv) || !check) continue;

// Replace '_' separator with '-'
dict.ReplaceChar("_", '-');
dict.ReplaceChar('_', '-');

nsCOMPtr<nsIURI> uri;
rv = NS_NewFileURI(getter_AddRefs(uri), file);
Expand Down
6 changes: 3 additions & 3 deletions uriloader/exthandler/nsExternalHelperAppService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ static nsresult GetDownloadDirectory(nsIFile** _directory,
nsAutoString userDir;
userDir.AssignLiteral("mozilla_");
userDir.AppendASCII(userName);
userDir.ReplaceChar(FILE_PATH_SEPARATOR FILE_ILLEGAL_CHARACTERS, '_');
userDir.ReplaceChar(u"" FILE_PATH_SEPARATOR FILE_ILLEGAL_CHARACTERS, '_');

int counter = 0;
bool pathExists;
Expand Down Expand Up @@ -3504,8 +3504,8 @@ void nsExternalHelperAppService::SanitizeFileName(nsAString& aFileName,
nsAutoString fileName(aFileName);

// Replace known invalid characters.
fileName.ReplaceChar(u"" KNOWN_PATH_SEPARATORS, '_');
fileName.ReplaceChar(u"" FILE_ILLEGAL_CHARACTERS, ' ');
fileName.ReplaceChar(u"" KNOWN_PATH_SEPARATORS, u'_');
fileName.ReplaceChar(u"" FILE_ILLEGAL_CHARACTERS, u' ');
fileName.StripChar(char16_t(0));

const char16_t *startStr, *endStr;
Expand Down
1 change: 0 additions & 1 deletion xpcom/string/moz.build
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ UNIFIED_SOURCES += [
"nsString.cpp",
"nsStringBuffer.cpp",
"nsStringComparator.cpp",
"nsStringObsolete.cpp",
"nsTextFormatter.cpp",
"nsTStringRepr.cpp",
"nsTSubstring.cpp",
Expand Down
Loading

0 comments on commit e3fbeb4

Please sign in to comment.