Bug 997963, part 1 - Delete trailing whitespace from string bundle files. r=ehsan
authorAndrew McCreight <continuation@gmail.com>
Mon, 21 Apr 2014 09:41:56 -0700
changeset 179404 a61517ca13ace8eace698c9066be62131ccef0fb
parent 179403 408e7a1d91a1758b8fdc9451c0de88e049c9f4ea
child 179405 d5f5047b958510c1002fd34c1c9d227429ff29c0
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersehsan
bugs997963
milestone31.0a1
Bug 997963, part 1 - Delete trailing whitespace from string bundle files. r=ehsan
intl/strres/src/nsStringBundle.cpp
intl/strres/src/nsStringBundle.h
intl/strres/src/nsStringBundleService.h
--- a/intl/strres/src/nsStringBundle.cpp
+++ b/intl/strres/src/nsStringBundle.cpp
@@ -51,79 +51,79 @@ nsStringBundle::LoadProperties()
 {
   // this is different than mLoaded, because we only want to attempt
   // to load once
   // we only want to load once, but if we've tried once and failed,
   // continue to throw an error!
   if (mAttemptedLoad) {
     if (mLoaded)
       return NS_OK;
-      
+
     return NS_ERROR_UNEXPECTED;
   }
-  
+
   mAttemptedLoad = true;
 
   nsresult rv;
 
   // do it synchronously
   nsCOMPtr<nsIURI> uri;
   rv = NS_NewURI(getter_AddRefs(uri), mPropertiesURL);
   if (NS_FAILED(rv)) return rv;
 
   // We don't use NS_OpenURI because we want to tweak the channel
   nsCOMPtr<nsIChannel> channel;
   rv = NS_NewChannel(getter_AddRefs(channel), uri);
   if (NS_FAILED(rv)) return rv;
 
   // It's a string bundle.  We expect a text/plain type, so set that as hint
   channel->SetContentType(NS_LITERAL_CSTRING("text/plain"));
-  
+
   nsCOMPtr<nsIInputStream> in;
   rv = channel->Open(getter_AddRefs(in));
   if (NS_FAILED(rv)) return rv;
 
   NS_ASSERTION(NS_SUCCEEDED(rv) && in, "Error in OpenBlockingStream");
   NS_ENSURE_TRUE(NS_SUCCEEDED(rv) && in, NS_ERROR_FAILURE);
 
   static NS_DEFINE_CID(kPersistentPropertiesCID, NS_IPERSISTENTPROPERTIES_CID);
   mProps = do_CreateInstance(kPersistentPropertiesCID, &rv);
   NS_ENSURE_SUCCESS(rv, rv);
-  
+
   mAttemptedLoad = mLoaded = true;
   rv = mProps->Load(in);
 
   mLoaded = NS_SUCCEEDED(rv);
-  
+
   return rv;
 }
 
 
 nsresult
 nsStringBundle::GetStringFromID(int32_t aID, nsAString& aResult)
-{  
+{
   ReentrantMonitorAutoEnter automon(mReentrantMonitor);
   nsAutoCString name;
   name.AppendInt(aID, 10);
 
   nsresult rv;
-  
+
   // try override first
   if (mOverrideStrings) {
     rv = mOverrideStrings->GetStringFromName(mPropertiesURL,
                                              name,
                                              aResult);
     if (NS_SUCCEEDED(rv)) return rv;
   }
-  
+
   rv = mProps->GetStringProperty(name, aResult);
 
 #ifdef DEBUG_tao_
   char *s = ToNewCString(aResult);
-  printf("\n** GetStringFromID: aResult=%s, len=%d\n", s?s:"null", 
+  printf("\n** GetStringFromID: aResult=%s, len=%d\n", s?s:"null",
          aResult.Length());
   if (s) nsMemory::Free(s);
 #endif /* DEBUG_tao_ */
 
   return rv;
 }
 
 nsresult
@@ -134,22 +134,22 @@ nsStringBundle::GetStringFromName(const 
 
   // try override first
   if (mOverrideStrings) {
     rv = mOverrideStrings->GetStringFromName(mPropertiesURL,
                                              NS_ConvertUTF16toUTF8(aName),
                                              aResult);
     if (NS_SUCCEEDED(rv)) return rv;
   }
-  
+
   rv = mProps->GetStringProperty(NS_ConvertUTF16toUTF8(aName), aResult);
 #ifdef DEBUG_tao_
   char *s = ToNewCString(aResult),
        *ss = ToNewCString(aName);
-  printf("\n** GetStringFromName: aName=%s, aResult=%s, len=%d\n", 
+  printf("\n** GetStringFromName: aName=%s, aResult=%s, len=%d\n",
          ss?ss:"null", s?s:"null", aResult.Length());
   if (s)  nsMemory::Free(s);
   if (ss) nsMemory::Free(ss);
 #endif /* DEBUG_tao_ */
   return rv;
 }
 
 NS_IMETHODIMP
@@ -173,49 +173,49 @@ nsStringBundle::FormatStringFromName(con
 {
   NS_ENSURE_ARG_POINTER(aName);
   NS_ASSERTION(aParams && aLength, "FormatStringFromName() without format parameters: use GetStringFromName() instead");
   NS_ENSURE_ARG_POINTER(aResult);
 
   nsresult rv;
   rv = LoadProperties();
   if (NS_FAILED(rv)) return rv;
-  
+
   nsAutoString formatStr;
   rv = GetStringFromName(nsDependentString(aName), formatStr);
   if (NS_FAILED(rv)) return rv;
 
   return FormatString(formatStr.get(), aParams, aLength, aResult);
 }
-                                     
+
 
 NS_IMPL_ISUPPORTS1(nsStringBundle, nsIStringBundle)
 
 /* void GetStringFromID (in long aID, out wstring aResult); */
 NS_IMETHODIMP
 nsStringBundle::GetStringFromID(int32_t aID, char16_t **aResult)
 {
   nsresult rv;
   rv = LoadProperties();
   if (NS_FAILED(rv)) return rv;
-  
+
   *aResult = nullptr;
   nsAutoString tmpstr;
 
   rv = GetStringFromID(aID, tmpstr);
   NS_ENSURE_SUCCESS(rv, rv);
 
   *aResult = ToNewUnicode(tmpstr);
   NS_ENSURE_TRUE(*aResult, NS_ERROR_OUT_OF_MEMORY);
 
   return NS_OK;
 }
 
 /* void GetStringFromName (in wstring aName, out wstring aResult); */
-NS_IMETHODIMP 
+NS_IMETHODIMP
 nsStringBundle::GetStringFromName(const char16_t *aName, char16_t **aResult)
 {
   NS_ENSURE_ARG_POINTER(aName);
   NS_ENSURE_ARG_POINTER(aResult);
 
   nsresult rv;
   rv = LoadProperties();
   if (NS_FAILED(rv)) return rv;
@@ -223,17 +223,17 @@ nsStringBundle::GetStringFromName(const 
   ReentrantMonitorAutoEnter automon(mReentrantMonitor);
   *aResult = nullptr;
   nsAutoString tmpstr;
   rv = GetStringFromName(nsDependentString(aName), tmpstr);
   if (NS_FAILED(rv))
   {
 #if 0
     // it is not uncommon for apps to request a string name which may not exist
-    // so be quiet about it. 
+    // so be quiet about it.
     NS_WARNING("String missing from string bundle");
     printf("  '%s' missing from bundle %s\n", NS_ConvertUTF16toUTF8(aName).get(), mPropertiesURL.get());
 #endif
     return rv;
   }
 
   *aResult = ToNewUnicode(tmpstr);
   NS_ENSURE_TRUE(*aResult, NS_ERROR_OUT_OF_MEMORY);
@@ -242,28 +242,28 @@ nsStringBundle::GetStringFromName(const 
 }
 
 nsresult
 nsStringBundle::GetCombinedEnumeration(nsIStringBundleOverride* aOverrideStrings,
                                        nsISimpleEnumerator** aResult)
 {
   nsCOMPtr<nsISupports> supports;
   nsCOMPtr<nsIPropertyElement> propElement;
-  
+
   nsresult rv;
 
   nsCOMPtr<nsIMutableArray> resultArray =
     do_CreateInstance(NS_ARRAY_CONTRACTID, &rv);
   NS_ENSURE_SUCCESS(rv, rv);
 
   // first, append the override elements
   nsCOMPtr<nsISimpleEnumerator> overrideEnumerator;
   rv = aOverrideStrings->EnumerateKeysInBundle(mPropertiesURL,
                                                getter_AddRefs(overrideEnumerator));
-  
+
   bool hasMore;
   rv = overrideEnumerator->HasMoreElements(&hasMore);
   NS_ENSURE_SUCCESS(rv, rv);
   while (hasMore) {
 
     rv = overrideEnumerator->GetNext(getter_AddRefs(supports));
     if (NS_SUCCEEDED(rv))
       resultArray->AppendElement(supports, false);
@@ -299,31 +299,31 @@ nsStringBundle::GetCombinedEnumeration(n
     }
 
     rv = propEnumerator->HasMoreElements(&hasMore);
     NS_ENSURE_SUCCESS(rv, rv);
   } while (hasMore);
 
   return resultArray->Enumerate(aResult);
 }
-                                
+
 
 NS_IMETHODIMP
 nsStringBundle::GetSimpleEnumeration(nsISimpleEnumerator** elements)
 {
   if (!elements)
     return NS_ERROR_INVALID_POINTER;
 
   nsresult rv;
   rv = LoadProperties();
   if (NS_FAILED(rv)) return rv;
-  
+
   if (mOverrideStrings)
       return GetCombinedEnumeration(mOverrideStrings, elements);
-  
+
   return mProps->Enumerate(elements);
 }
 
 nsresult
 nsStringBundle::FormatString(const char16_t *aFormatStr,
                              const char16_t **aParams, uint32_t aLength,
                              char16_t **aResult)
 {
@@ -331,17 +331,17 @@ nsStringBundle::FormatString(const char1
   NS_ENSURE_ARG(aLength <= 10); // enforce 10-parameter limit
 
   // implementation note: you would think you could use vsmprintf
   // to build up an arbitrary length array.. except that there
   // is no way to build up a va_list at runtime!
   // Don't believe me? See:
   //   http://www.eskimo.com/~scs/C-faq/q15.13.html
   // -alecf
-  char16_t *text = 
+  char16_t *text =
     nsTextFormatter::smprintf(aFormatStr,
                               aLength >= 1 ? aParams[0] : nullptr,
                               aLength >= 2 ? aParams[1] : nullptr,
                               aLength >= 3 ? aParams[2] : nullptr,
                               aLength >= 4 ? aParams[3] : nullptr,
                               aLength >= 5 ? aParams[4] : nullptr,
                               aLength >= 6 ? aParams[5] : nullptr,
                               aLength >= 7 ? aParams[6] : nullptr,
@@ -369,17 +369,17 @@ NS_IMPL_ISUPPORTS1(nsExtensibleStringBun
 
 nsExtensibleStringBundle::nsExtensibleStringBundle()
 {
   mLoaded = false;
 }
 
 nsresult
 nsExtensibleStringBundle::Init(const char * aCategory,
-                               nsIStringBundleService* aBundleService) 
+                               nsIStringBundleService* aBundleService)
 {
 
   nsresult rv;
   nsCOMPtr<nsICategoryManager> catman =
     do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv);
   if (NS_FAILED(rv)) return rv;
 
   nsCOMPtr<nsISimpleEnumerator> enumerator;
@@ -408,17 +408,17 @@ nsExtensibleStringBundle::Init(const cha
       continue;
 
     mBundles.AppendObject(bundle);
   }
 
   return rv;
 }
 
-nsExtensibleStringBundle::~nsExtensibleStringBundle() 
+nsExtensibleStringBundle::~nsExtensibleStringBundle()
 {
 }
 
 nsresult nsExtensibleStringBundle::GetStringFromID(int32_t aID, char16_t ** aResult)
 {
   nsresult rv;
   const uint32_t size = mBundles.Count();
   for (uint32_t i = 0; i < size; ++i) {
@@ -531,46 +531,46 @@ nsStringBundleService::Init()
     os->AddObserver(this, "chrome-flush-caches", true);
     os->AddObserver(this, "xpcom-category-entry-added", true);
   }
 
   // instantiate the override service, if there is any.
   // at some point we probably want to make this a category, and
   // support multiple overrides
   mOverrideStrings = do_GetService(NS_STRINGBUNDLETEXTOVERRIDE_CONTRACTID);
-  
+
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsStringBundleService::Observe(nsISupports* aSubject,
                                const char* aTopic,
                                const char16_t* aSomeData)
 {
   if (strcmp("memory-pressure", aTopic) == 0 ||
       strcmp("profile-do-change", aTopic) == 0 ||
       strcmp("chrome-flush-caches", aTopic) == 0)
   {
     flushBundleCache();
   }
   else if (strcmp("xpcom-category-entry-added", aTopic) == 0 &&
-           NS_LITERAL_STRING("xpcom-autoregistration").Equals(aSomeData)) 
+           NS_LITERAL_STRING("xpcom-autoregistration").Equals(aSomeData))
   {
     mOverrideStrings = do_GetService(NS_STRINGBUNDLETEXTOVERRIDE_CONTRACTID);
   }
-  
+
   return NS_OK;
 }
 
 void
 nsStringBundleService::flushBundleCache()
 {
   // release all bundles in the cache
   mBundleMap.Reset();
-  
+
   while (!mBundleCache.isEmpty()) {
     bundleCacheEntry_t *cacheEntry = mBundleCache.popFirst();
 
     recycleEntry(cacheEntry);
   }
   PL_FreeArenaPool(&mCacheEntryPool);
 }
 
@@ -584,30 +584,30 @@ nsStringBundleService::FlushBundles()
 nsresult
 nsStringBundleService::getStringBundle(const char *aURLSpec,
                                        nsIStringBundle **aResult)
 {
   nsCStringKey completeKey(aURLSpec);
 
   bundleCacheEntry_t* cacheEntry =
     (bundleCacheEntry_t*)mBundleMap.Get(&completeKey);
-  
+
   if (cacheEntry) {
     // cache hit!
     // remove it from the list, it will later be reinserted
     // at the head of the list
     cacheEntry->remove();
-    
+
   } else {
 
     // hasn't been cached, so insert it into the hash table
     nsStringBundle* bundle = new nsStringBundle(aURLSpec, mOverrideStrings);
     if (!bundle) return NS_ERROR_OUT_OF_MEMORY;
     NS_ADDREF(bundle);
-    
+
     cacheEntry = insertIntoCache(bundle, &completeKey);
     NS_RELEASE(bundle);         // cache should now be holding a ref
                                 // in the cacheEntry
   }
 
   // at this point the cacheEntry should exist in the hashtable,
   // but is not in the LRU cache.
   // put the cache entry at the front of the list
@@ -620,66 +620,66 @@ nsStringBundleService::getStringBundle(c
   return NS_OK;
 }
 
 bundleCacheEntry_t *
 nsStringBundleService::insertIntoCache(nsIStringBundle* aBundle,
                                        nsCStringKey* aHashKey)
 {
   bundleCacheEntry_t *cacheEntry;
-  
+
   if (mBundleMap.Count() < MAX_CACHED_BUNDLES) {
     // cache not full - create a new entry
-    
+
     void *cacheEntryArena;
     PL_ARENA_ALLOCATE(cacheEntryArena, &mCacheEntryPool, sizeof(bundleCacheEntry_t));
     cacheEntry = new (cacheEntryArena) bundleCacheEntry_t();
-      
+
   } else {
     // cache is full
     // take the last entry in the list, and recycle it.
     cacheEntry = mBundleCache.getLast();
-      
+
     // remove it from the hash table and linked list
     NS_ASSERTION(mBundleMap.Exists(cacheEntry->mHashKey),
                  "Element will not be removed!");
 #ifdef DEBUG_alecf
     NS_WARNING(nsPrintfCString("Booting %s to make room for %s\n",
                                cacheEntry->mHashKey->GetString(),
                                aHashKey->GetString()).get());
 #endif
     mBundleMap.Remove(cacheEntry->mHashKey);
     cacheEntry->remove();
 
     // free up excess memory
     recycleEntry(cacheEntry);
   }
-    
+
   // at this point we have a new cacheEntry that doesn't exist
   // in the hashtable, so set up the cacheEntry
   cacheEntry->mBundle = aBundle;
   NS_ADDREF(cacheEntry->mBundle);
 
   cacheEntry->mHashKey = (nsCStringKey*)aHashKey->Clone();
-  
+
   // insert the entry into the cache and map, make it the MRU
   mBundleMap.Put(cacheEntry->mHashKey, cacheEntry);
 
   return cacheEntry;
 }
 
 void
 nsStringBundleService::recycleEntry(bundleCacheEntry_t *aEntry)
 {
   delete aEntry->mHashKey;
   NS_RELEASE(aEntry->mBundle);
 }
 
 NS_IMETHODIMP
-nsStringBundleService::CreateBundle(const char* aURLSpec, 
+nsStringBundleService::CreateBundle(const char* aURLSpec,
                                     nsIStringBundle** aResult)
 {
 #ifdef DEBUG_tao_
   printf("\n++ nsStringBundleService::CreateBundle ++\n");
   printf("\n** nsStringBundleService::CreateBundle: %s\n", aURLSpec ? aURLSpec : "null");
 #endif
 
   return getStringBundle(aURLSpec,aResult);
@@ -767,30 +767,30 @@ nsStringBundleService::FormatStatusMessa
   if (argCount == 1) {
     // avoid construction for the simple case:
     argArray[0] = (char16_t*)aStatusArg;
   }
   else if (argCount > 1) {
     int32_t offset = 0;
     for (i = 0; i < argCount; i++) {
       int32_t pos = args.FindChar('\n', offset);
-      if (pos == -1) 
+      if (pos == -1)
         pos = args.Length();
       argArray[i] = ToNewUnicode(Substring(args, offset, pos - offset));
       if (argArray[i] == nullptr) {
         rv = NS_ERROR_OUT_OF_MEMORY;
         argCount = i - 1; // don't try to free uninitialized memory
         goto done;
       }
       offset = pos + 1;
     }
   }
 
   // find the string bundle for the error's module:
-  rv = mErrorService->GetErrorStringBundle(NS_ERROR_GET_MODULE(aStatus), 
+  rv = mErrorService->GetErrorStringBundle(NS_ERROR_GET_MODULE(aStatus),
                                            getter_Copies(stringBundleURL));
   if (NS_SUCCEEDED(rv)) {
     rv = getStringBundle(stringBundleURL, getter_AddRefs(bundle));
     if (NS_SUCCEEDED(rv)) {
       rv = FormatWithBundle(bundle, aStatus, argCount, argArray, result);
     }
   }
   if (NS_FAILED(rv)) {
@@ -804,9 +804,8 @@ done:
   if (argCount > 1) {
     for (i = 0; i < argCount; i++) {
       if (argArray[i])
         nsMemory::Free(argArray[i]);
     }
   }
   return rv;
 }
-
--- a/intl/strres/src/nsStringBundle.h
+++ b/intl/strres/src/nsStringBundle.h
@@ -17,38 +17,38 @@ class nsIStringBundleOverride;
 
 class nsStringBundle : public nsIStringBundle
 {
 public:
     // init version
     nsStringBundle(const char* aURLSpec, nsIStringBundleOverride*);
     nsresult LoadProperties();
     virtual ~nsStringBundle();
-  
+
     NS_DECL_THREADSAFE_ISUPPORTS
     NS_DECL_NSISTRINGBUNDLE
 
     nsCOMPtr<nsIPersistentProperties> mProps;
 
 protected:
     //
-    // functional decomposition of the funitions repeatively called 
+    // functional decomposition of the funitions repeatively called
     //
     nsresult GetStringFromID(int32_t aID, nsAString& aResult);
     nsresult GetStringFromName(const nsAString& aName, nsAString& aResult);
 
     nsresult GetCombinedEnumeration(nsIStringBundleOverride* aOverrideString,
                                     nsISimpleEnumerator** aResult);
 private:
     nsCString              mPropertiesURL;
     nsCOMPtr<nsIStringBundleOverride> mOverrideStrings;
     mozilla::ReentrantMonitor    mReentrantMonitor;
     bool                         mAttemptedLoad;
     bool                         mLoaded;
-    
+
 public:
     static nsresult FormatString(const char16_t *formatStr,
                                  const char16_t **aParams, uint32_t aLength,
                                  char16_t **aResult);
 };
 
 /**
  * An extesible implementation of the StringBudle interface.
@@ -58,17 +58,17 @@ public:
  */
 class nsExtensibleStringBundle : public nsIStringBundle
 {
   NS_DECL_ISUPPORTS
   NS_DECL_NSISTRINGBUNDLE
 
   nsresult Init(const char * aCategory, nsIStringBundleService *);
 private:
-  
+
   nsCOMArray<nsIStringBundle> mBundles;
   bool               mLoaded;
 
 public:
 
   nsExtensibleStringBundle();
   virtual ~nsExtensibleStringBundle();
 };
--- a/intl/strres/src/nsStringBundleService.h
+++ b/intl/strres/src/nsStringBundleService.h
@@ -29,30 +29,30 @@ public:
   nsStringBundleService();
   virtual ~nsStringBundleService();
 
   nsresult Init();
 
   NS_DECL_THREADSAFE_ISUPPORTS
   NS_DECL_NSISTRINGBUNDLESERVICE
   NS_DECL_NSIOBSERVER
-    
+
 private:
   nsresult getStringBundle(const char *aUrl, nsIStringBundle** aResult);
-  nsresult FormatWithBundle(nsIStringBundle* bundle, nsresult aStatus, 
+  nsresult FormatWithBundle(nsIStringBundle* bundle, nsresult aStatus,
                             uint32_t argCount, char16_t** argArray,
                             char16_t* *result);
 
   void flushBundleCache();
-  
+
   bundleCacheEntry_t *insertIntoCache(nsIStringBundle *aBundle,
                                       nsCStringKey *aHashKey);
 
   static void recycleEntry(bundleCacheEntry_t*);
-  
+
   nsHashtable mBundleMap;
   mozilla::LinkedList<bundleCacheEntry_t> mBundleCache;
   PLArenaPool mCacheEntryPool;
 
   nsCOMPtr<nsIErrorService>     mErrorService;
   nsCOMPtr<nsIStringBundleOverride> mOverrideStrings;
 };