Bug 1648802 - remove Thunderbird usage of NS_NAMED_LITERAL_CSTRING and NS_NAMED_LITERAL_STRING macros (removed in bug 1648010). r=sg
authorMagnus Melin <mkmelin+mozilla@iki.fi>
Wed, 01 Jul 2020 16:15:15 +0300
changeset 89816 732ab4ae2b4e30db9f43178763f60ecf43574f72
parent 89815 cc901b85280c6258f0425cc346c55f7eb64abb0e
child 89817 1aa86015cd87b30709412551835bf902025cd7d1
push id11340
push usermkmelin@iki.fi
push dateWed, 01 Jul 2020 13:18:03 +0000
treeherdertry-comm-central@b100d6a8e613 [default view] [failures only]
reviewerssg
bugs1648802, 1648010
Bug 1648802 - remove Thunderbird usage of NS_NAMED_LITERAL_CSTRING and NS_NAMED_LITERAL_STRING macros (removed in bug 1648010). r=sg # NS_NAMED_LITERAL_CSTRING(foo, "bar") -> constexpr auto foo = "bar"_ns; find . -type f -not -path "*.hg/*" -not -path "third_party/*" -regex ".*\.\(c\|h\|cpp\|mm\)$" -exec sed -i -E 's/NS_NAMED_LITERAL_CSTRING\(([^,]+),\s*([^)]+)\)/constexpr auto \1 = \2_ns/g' {} \; # NS_NAMED_LITERAL_STRING(foo, "bar") -> constexpr auto foo = u"bar"_ns; find . -type f -not -path "*.hg/*" -not -path "third_party/*" -regex ".*\.\(c\|h\|cpp\|mm\)$" -exec sed -i -E 's/NS_NAMED_LITERAL_STRING\(([^,]+),\s*([^)]+)\)/constexpr auto \1 = u\2_ns/g' {} \; + a few manual replacements in nsMsgDBFolder.cpp and nsProfileMigrator.cpp + clang-format
common/saxparser/nsSAXXMLReader.cpp
ldap/xpcom/src/nsLDAPURL.cpp
mail/components/migration/src/nsProfileMigrator.cpp
mailnews/addrbook/src/nsAbLDAPDirectory.cpp
mailnews/base/util/nsMsgDBFolder.cpp
mailnews/base/util/nsMsgI18N.cpp
mailnews/base/util/nsMsgIncomingServer.cpp
mailnews/import/applemail/src/nsEmlxHelperUtils.mm
mailnews/mapi/mapihook/src/msgMapiHook.cpp
mailnews/news/src/nsNntpIncomingServer.cpp
--- a/common/saxparser/nsSAXXMLReader.cpp
+++ b/common/saxparser/nsSAXXMLReader.cpp
@@ -70,17 +70,17 @@ nsSAXXMLReader::HandleStartElement(const
   if (!mContentHandler) return NS_OK;
 
   RefPtr<nsSAXAttributes> atts = new nsSAXAttributes();
   if (!atts) return NS_ERROR_OUT_OF_MEMORY;
   nsAutoString uri, localName, qName;
   for (; *aAtts; aAtts += 2) {
     SplitExpatName(aAtts[0], uri, localName, qName);
     // XXX don't have attr type information
-    NS_NAMED_LITERAL_STRING(cdataType, "CDATA");
+    constexpr auto cdataType = u"CDATA"_ns;
     // could support xmlns reporting, it's a standard SAX feature
     if (!uri.EqualsLiteral(XMLNS_URI)) {
       NS_ASSERTION(aAtts[1], "null passed to handler");
       atts->AddAttribute(uri, localName, qName, cdataType,
                          nsDependentString(aAtts[1]));
     }
   }
 
--- a/ldap/xpcom/src/nsLDAPURL.cpp
+++ b/ldap/xpcom/src/nsLDAPURL.cpp
@@ -12,18 +12,18 @@
 #include "nsComponentManagerUtils.h"
 #include "nsIStandardURL.h"
 #include "nsMsgUtils.h"
 #include "mozilla/Encoding.h"
 #include "ldap.h"
 
 // The two schemes we support, LDAP and LDAPS
 //
-NS_NAMED_LITERAL_CSTRING(LDAP_SCHEME, "ldap");
-NS_NAMED_LITERAL_CSTRING(LDAP_SSL_SCHEME, "ldaps");
+constexpr auto LDAP_SCHEME = "ldap"_ns;
+constexpr auto LDAP_SSL_SCHEME = "ldaps"_ns;
 
 NS_IMPL_ISUPPORTS(nsLDAPURL, nsILDAPURL, nsIURI)
 
 nsLDAPURL::nsLDAPURL() : mScope(SCOPE_BASE), mOptions(0) {}
 
 nsLDAPURL::~nsLDAPURL() {}
 
 nsresult nsLDAPURL::Init(uint32_t aUrlType, int32_t aDefaultPort,
--- a/mail/components/migration/src/nsProfileMigrator.cpp
+++ b/mail/components/migration/src/nsProfileMigrator.cpp
@@ -80,39 +80,37 @@ nsresult nsProfileMigrator::GetDefaultMa
   nsCOMPtr<nsIPrefBranch> prefs(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv));
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsCString forceMigrationType;
   prefs->GetCharPref("profile.force.migration", forceMigrationType);
 
   // if we are being forced to migrate to a particular migration type, then
   // create an instance of that migrator and return it.
-  NS_NAMED_LITERAL_CSTRING(migratorPrefix,
-                           NS_MAILPROFILEMIGRATOR_CONTRACTID_PREFIX);
   nsAutoCString migratorID;
   if (!forceMigrationType.IsEmpty()) {
     bool exists = false;
-    migratorID = migratorPrefix;
+    migratorID.AppendLiteral(NS_MAILPROFILEMIGRATOR_CONTRACTID_PREFIX);
     migratorID.Append(forceMigrationType);
     mailMigrator = do_CreateInstance(migratorID.get());
     if (!mailMigrator) return NS_ERROR_NOT_AVAILABLE;
 
     mailMigrator->GetSourceExists(&exists);
     /* trying to force migration on a source which doesn't
      * have any profiles.
      */
     if (!exists) return NS_ERROR_NOT_AVAILABLE;
     aKey = forceMigrationType;
     return NS_OK;
   }
 
 #define MAX_SOURCE_LENGTH 10
   const char sources[][MAX_SOURCE_LENGTH] = {"seamonkey", "outlook", ""};
   for (uint32_t i = 0; sources[i][0]; ++i) {
-    migratorID = migratorPrefix;
+    migratorID.AssignLiteral(NS_MAILPROFILEMIGRATOR_CONTRACTID_PREFIX);
     migratorID.Append(sources[i]);
     mailMigrator = do_CreateInstance(migratorID.get());
     if (!mailMigrator) continue;
 
     bool exists = false;
     mailMigrator->GetSourceExists(&exists);
     if (exists) {
       mailMigrator = nullptr;
--- a/mailnews/addrbook/src/nsAbLDAPDirectory.cpp
+++ b/mailnews/addrbook/src/nsAbLDAPDirectory.cpp
@@ -227,18 +227,18 @@ NS_IMETHODIMP nsAbLDAPDirectory::SetLDAP
   if (oldUrl.IsEmpty() ||
       StringBeginsWith(oldUrl, NS_LITERAL_CSTRING("ldap:")) != newIsNotSecure) {
     // They don't so its time to send round an update.
     nsCOMPtr<nsIAbManager> abManager =
         do_GetService(NS_ABMANAGER_CONTRACTID, &rv);
     NS_ENSURE_SUCCESS(rv, rv);
 
     // We inherit from nsIAbDirectory, so this static cast should be safe.
-    NS_NAMED_LITERAL_STRING(trueString, "true");
-    NS_NAMED_LITERAL_STRING(falseString, "false");
+    constexpr auto trueString = u"true"_ns;
+    constexpr auto falseString = u"false"_ns;
     abManager->NotifyItemPropertyChanged(
         static_cast<nsIAbDirectory*>(this), "IsSecure",
         (newIsNotSecure ? trueString : falseString),
         (newIsNotSecure ? falseString : trueString));
   }
 
   return NS_OK;
 }
--- a/mailnews/base/util/nsMsgDBFolder.cpp
+++ b/mailnews/base/util/nsMsgDBFolder.cpp
@@ -117,49 +117,49 @@ nsString nsMsgDBFolder::kLocalizedArchiv
 
 nsString nsMsgDBFolder::kLocalizedBrandShortName;
 
 nsrefcnt nsMsgDBFolder::mInstanceCount = 0;
 bool nsMsgDBFolder::gInitializeStringsDone = false;
 
 // We define strings for folder properties and events.
 // Properties:
-NS_NAMED_LITERAL_CSTRING(kBiffState, "BiffState");
-NS_NAMED_LITERAL_CSTRING(kCanFileMessages, "CanFileMessages");
-NS_NAMED_LITERAL_CSTRING(kDefaultServer, "DefaultServer");
-NS_NAMED_LITERAL_CSTRING(kFlagged, "Flagged");
-NS_NAMED_LITERAL_CSTRING(kFolderFlag, "FolderFlag");
-NS_NAMED_LITERAL_CSTRING(kFolderSize, "FolderSize");
-NS_NAMED_LITERAL_CSTRING(kIsDeferred, "isDeferred");
-NS_NAMED_LITERAL_CSTRING(kIsSecure, "isSecure");
-NS_NAMED_LITERAL_CSTRING(kJunkStatusChanged, "JunkStatusChanged");
-NS_NAMED_LITERAL_CSTRING(kKeywords, "Keywords");
-NS_NAMED_LITERAL_CSTRING(kMRMTimeChanged, "MRMTimeChanged");
-NS_NAMED_LITERAL_CSTRING(kMsgLoaded, "msgLoaded");
-NS_NAMED_LITERAL_CSTRING(kName, "Name");
-NS_NAMED_LITERAL_CSTRING(kNewMailReceived, "NewMailReceived");
-NS_NAMED_LITERAL_CSTRING(kNewMessages, "NewMessages");
-NS_NAMED_LITERAL_CSTRING(kOpen, "open");
-NS_NAMED_LITERAL_CSTRING(kSortOrder, "SortOrder");
-NS_NAMED_LITERAL_CSTRING(kStatus, "Status");
-NS_NAMED_LITERAL_CSTRING(kSynchronize, "Synchronize");
-NS_NAMED_LITERAL_CSTRING(kTotalMessages, "TotalMessages");
-NS_NAMED_LITERAL_CSTRING(kTotalUnreadMessages, "TotalUnreadMessages");
+constexpr auto kBiffState = "BiffState"_ns;
+constexpr auto kCanFileMessages = "CanFileMessages"_ns;
+constexpr auto kDefaultServer = "DefaultServer"_ns;
+constexpr auto kFlagged = "Flagged"_ns;
+constexpr auto kFolderFlag = "FolderFlag"_ns;
+constexpr auto kFolderSize = "FolderSize"_ns;
+constexpr auto kIsDeferred = "isDeferred"_ns;
+constexpr auto kIsSecure = "isSecure"_ns;
+constexpr auto kJunkStatusChanged = "JunkStatusChanged"_ns;
+constexpr auto kKeywords = "Keywords"_ns;
+constexpr auto kMRMTimeChanged = "MRMTimeChanged"_ns;
+constexpr auto kMsgLoaded = "msgLoaded"_ns;
+constexpr auto kName = "Name"_ns;
+constexpr auto kNewMailReceived = "NewMailReceived"_ns;
+constexpr auto kNewMessages = "NewMessages"_ns;
+constexpr auto kOpen = "open"_ns;
+constexpr auto kSortOrder = "SortOrder"_ns;
+constexpr auto kStatus = "Status"_ns;
+constexpr auto kSynchronize = "Synchronize"_ns;
+constexpr auto kTotalMessages = "TotalMessages"_ns;
+constexpr auto kTotalUnreadMessages = "TotalUnreadMessages"_ns;
 
 // Events:
-NS_NAMED_LITERAL_CSTRING(kAboutToCompact, "AboutToCompact");
-NS_NAMED_LITERAL_CSTRING(kCompactCompleted, "CompactCompleted");
-NS_NAMED_LITERAL_CSTRING(kDeleteOrMoveMsgCompleted, "DeleteOrMoveMsgCompleted");
-NS_NAMED_LITERAL_CSTRING(kDeleteOrMoveMsgFailed, "DeleteOrMoveMsgFailed");
-NS_NAMED_LITERAL_CSTRING(kFiltersApplied, "FiltersApplied");
-NS_NAMED_LITERAL_CSTRING(kFolderCreateCompleted, "FolderCreateCompleted");
-NS_NAMED_LITERAL_CSTRING(kFolderCreateFailed, "FolderCreateFailed");
-NS_NAMED_LITERAL_CSTRING(kFolderLoaded, "FolderLoaded");
-NS_NAMED_LITERAL_CSTRING(kNumNewBiffMessages, "NumNewBiffMessages");
-NS_NAMED_LITERAL_CSTRING(kRenameCompleted, "RenameCompleted");
+constexpr auto kAboutToCompact = "AboutToCompact"_ns;
+constexpr auto kCompactCompleted = "CompactCompleted"_ns;
+constexpr auto kDeleteOrMoveMsgCompleted = "DeleteOrMoveMsgCompleted"_ns;
+constexpr auto kDeleteOrMoveMsgFailed = "DeleteOrMoveMsgFailed"_ns;
+constexpr auto kFiltersApplied = "FiltersApplied"_ns;
+constexpr auto kFolderCreateCompleted = "FolderCreateCompleted"_ns;
+constexpr auto kFolderCreateFailed = "FolderCreateFailed"_ns;
+constexpr auto kFolderLoaded = "FolderLoaded"_ns;
+constexpr auto kNumNewBiffMessages = "NumNewBiffMessages"_ns;
+constexpr auto kRenameCompleted = "RenameCompleted"_ns;
 
 NS_IMPL_ISUPPORTS(nsMsgDBFolder, nsISupportsWeakReference, nsIMsgFolder,
                   nsIDBChangeListener, nsIUrlListener,
                   nsIJunkMailClassificationListener,
                   nsIMsgTraitClassificationListener)
 
 nsMsgDBFolder::nsMsgDBFolder(void)
     : mAddListener(true),
@@ -1552,23 +1552,22 @@ nsresult nsMsgDBFolder::WriteStartOfNewL
   m_bytesAddedToLocalMsg = result.Length();
 
   nsCOMPtr<nsISeekableStream> seekable;
 
   if (m_offlineHeader) seekable = do_QueryInterface(m_tempMessageStream);
 
   m_tempMessageStream->Write(result.get(), result.Length(), &writeCount);
 
-  NS_NAMED_LITERAL_CSTRING(MozillaStatus,
-                           "X-Mozilla-Status: 0001" MSG_LINEBREAK);
+  constexpr auto MozillaStatus = "X-Mozilla-Status: 0001"_ns MSG_LINEBREAK;
   m_tempMessageStream->Write(MozillaStatus.get(), MozillaStatus.Length(),
                              &writeCount);
   m_bytesAddedToLocalMsg += writeCount;
-  NS_NAMED_LITERAL_CSTRING(MozillaStatus2,
-                           "X-Mozilla-Status2: 00000000" MSG_LINEBREAK);
+  constexpr auto MozillaStatus2 =
+      "X-Mozilla-Status2: 00000000"_ns MSG_LINEBREAK;
   m_bytesAddedToLocalMsg += MozillaStatus2.Length();
   return m_tempMessageStream->Write(MozillaStatus2.get(),
                                     MozillaStatus2.Length(), &writeCount);
 }
 
 nsresult nsMsgDBFolder::StartNewOfflineMessage() {
   bool isLocked;
   GetLocked(&isLocked);
--- a/mailnews/base/util/nsMsgI18N.cpp
+++ b/mailnews/base/util/nsMsgI18N.cpp
@@ -364,17 +364,17 @@ void nsMsgI18NConvertRawBytesToUTF8(cons
   nsAutoString utf16Text;
   nsresult rv = nsMsgI18NConvertToUnicode(charset, inString, utf16Text);
   if (NS_SUCCEEDED(rv)) {
     CopyUTF16toUTF8(utf16Text, outString);
     return;
   }
 
   // EF BF BD (UTF-8 encoding of U+FFFD)
-  NS_NAMED_LITERAL_CSTRING(utf8ReplacementChar, "\357\277\275");
+  constexpr auto utf8ReplacementChar = "\357\277\275"_ns;
   const char* cur = inString.BeginReading();
   const char* end = inString.EndReading();
   outString.Truncate();
   while (cur < end) {
     char c = *cur++;
     if (c & char(0x80))
       outString.Append(utf8ReplacementChar);
     else
--- a/mailnews/base/util/nsMsgIncomingServer.cpp
+++ b/mailnews/base/util/nsMsgIncomingServer.cpp
@@ -1829,18 +1829,18 @@ nsresult nsMsgIncomingServer::ConfigureT
     nsCOMPtr<nsIPrefBranch> prefs(do_GetService(NS_PREFSERVICE_CONTRACTID));
     if (prefs) prefs->GetIntPref("mail.incorporate.return_receipt", &incorp);
   }
 
   bool enable = (incorp == nsIMsgMdnGenerator::eIncorporateSent);
 
   // this is a temporary, internal mozilla filter
   // it will not show up in the UI, it will not be written to disk
-  NS_NAMED_LITERAL_STRING(internalReturnReceiptFilterName,
-                          "mozilla-temporary-internal-MDN-receipt-filter");
+  constexpr auto internalReturnReceiptFilterName =
+      u"mozilla-temporary-internal-MDN-receipt-filter"_ns;
 
   nsCOMPtr<nsIMsgFilter> newFilter;
   rv = filterList->GetFilterNamed(internalReturnReceiptFilterName,
                                   getter_AddRefs(newFilter));
   if (newFilter)
     newFilter->SetEnabled(enable);
   else if (enable) {
     nsCString actionTargetFolderUri;
--- a/mailnews/import/applemail/src/nsEmlxHelperUtils.mm
+++ b/mailnews/import/applemail/src/nsEmlxHelperUtils.mm
@@ -133,18 +133,18 @@ nsresult nsEmlxHelperUtils::AddEmlxMessa
     return NS_ERROR_FAILURE;
   }
 
   // skip whitespace
   while (*startOfMessageData == ' ' || *startOfMessageData == '\n' || *startOfMessageData == '\r' ||
          *startOfMessageData == '\t')
     ++startOfMessageData;
 
-  NS_NAMED_LITERAL_CSTRING(kBogusFromLine, "From \n");
-  NS_NAMED_LITERAL_CSTRING(kEndOfMessage, "\n\n");
+  constexpr auto kBogusFromLine = "From \n"_ns;
+  constexpr auto kEndOfMessage = "\n\n"_ns;
 
   // write the bogus "From " line which is a magic separator in the mbox format
   rv = aOut->Write(kBogusFromLine.get(), kBogusFromLine.Length(), &actualBytesWritten);
   if (NS_FAILED(rv)) {
     [pool release];
     return rv;
   }
 
--- a/mailnews/mapi/mapihook/src/msgMapiHook.cpp
+++ b/mailnews/mapi/mapihook/src/msgMapiHook.cpp
@@ -585,17 +585,17 @@ nsresult nsMapiHook::PopulateCompFieldsW
     else
       From.Append(NS_ConvertUTF8toUTF16(aMessage->lpOriginator->lpszAddress));
     aCompFields->SetFrom(From);
   }
 
   nsAutoString To;
   nsAutoString Cc;
   nsAutoString Bcc;
-  NS_NAMED_LITERAL_STRING(Comma, ",");
+  constexpr auto Comma = u","_ns;
   if (aMessage->lpRecips) {
     for (int i = 0; i < (int)aMessage->nRecipCount; i++) {
       if (aMessage->lpRecips[i].lpszAddress || aMessage->lpRecips[i].lpszName) {
         const char* addressWithoutType = (aMessage->lpRecips[i].lpszAddress)
                                              ? aMessage->lpRecips[i].lpszAddress
                                              : aMessage->lpRecips[i].lpszName;
         if (!PL_strncasecmp(addressWithoutType, "SMTP:", 5))
           addressWithoutType += 5;
@@ -695,17 +695,17 @@ nsresult nsMapiHook::PopulateCompFieldsW
   if (aMessage->lpOriginator && aMessage->lpOriginator->lpszAddress)
     aCompFields->SetFrom(
         nsDependentString(aMessage->lpOriginator->lpszAddress));
 
   nsAutoString To;
   nsAutoString Cc;
   nsAutoString Bcc;
 
-  NS_NAMED_LITERAL_STRING(Comma, ",");
+  constexpr auto Comma = u","_ns;
 
   if (aMessage->lpRecips) {
     for (int i = 0; i < (int)aMessage->nRecipCount; i++) {
       if (aMessage->lpRecips[i].lpszAddress || aMessage->lpRecips[i].lpszName) {
         const wchar_t* addressWithoutType =
             (aMessage->lpRecips[i].lpszAddress)
                 ? aMessage->lpRecips[i].lpszAddress
                 : aMessage->lpRecips[i].lpszName;
--- a/mailnews/news/src/nsNntpIncomingServer.cpp
+++ b/mailnews/news/src/nsNntpIncomingServer.cpp
@@ -1748,17 +1748,17 @@ nsNntpIncomingServer::ToggleOpenState(in
 }
 
 NS_IMETHODIMP
 nsNntpIncomingServer::CycleHeader(nsTreeColumn* col) {
   NS_ENSURE_ARG_POINTER(col);
 
   bool cycler = col->Cycler();
   if (!cycler) {
-    NS_NAMED_LITERAL_STRING(dir, "sortDirection");
+    constexpr auto dir = u"sortDirection"_ns;
     RefPtr<mozilla::dom::Element> element = col->Element();
     mSearchResultSortDescending = !mSearchResultSortDescending;
     mozilla::IgnoredErrorResult rv2;
     element->SetAttribute(dir,
                           mSearchResultSortDescending
                               ? NS_LITERAL_STRING("descending")
                               : NS_LITERAL_STRING("ascending"),
                           rv2);