Bug 306324 - Fix some mistakes in nsMsgUtils. r=neil
authorJan Horak <jhorak@redhat.com>
Sat, 09 Jun 2012 10:04:32 -0400
changeset 10391 7a5f6bbdc891b5bb0ab6a0bfc6e85a5fe0a124ed
parent 10390 6c501efb77ec0630afee9c97525a19d2e6f3be79
child 10392 c2d74922a95a7464357eb6838773721a3c68fd5e
push id7866
push userryanvm@gmail.com
push dateSat, 09 Jun 2012 14:15:29 +0000
treeherdercomm-central@0cab86861bef [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersneil
bugs306324
Bug 306324 - Fix some mistakes in nsMsgUtils. r=neil
mailnews/base/util/nsMsgUtils.cpp
mailnews/base/util/nsMsgUtils.h
--- a/mailnews/base/util/nsMsgUtils.cpp
+++ b/mailnews/base/util/nsMsgUtils.cpp
@@ -1892,17 +1892,21 @@ NS_MSG_BASE void MsgReplaceSubstring(nsA
 }
 
 NS_MSG_BASE void MsgReplaceSubstring(nsACString &str, const char *what, const char *replacement)
 {
   PRUint32 replacementLength = strlen(replacement);
   PRUint32 whatLength = strlen(what);
   PRInt32 i = 0;
 
-  while ((i = str.Find(what, i)) != kNotFound)
+  /* We have to create nsDependentCString from 'what' because there's no
+   * str.Find(char *what, int offset) but there is only
+   * str.Find(char *what, int length) */
+  nsDependentCString what_dependent(what);
+  while ((i = str.Find(what_dependent, i)) != kNotFound)
   {
     str.Replace(i, whatLength, replacement, replacementLength);
     i += replacementLength;
   }
 }
 
 /* This class is based on nsInterfaceRequestorAgg from nsInterfaceRequestorAgg.h */
 class MsgInterfaceRequestorAgg : public nsIInterfaceRequestor
--- a/mailnews/base/util/nsMsgUtils.h
+++ b/mailnews/base/util/nsMsgUtils.h
@@ -375,25 +375,33 @@ NS_MSG_BASE nsresult ConvertBufToPlainTe
  * The internal and external methods expect the parameters in a different order.
  * The internal API also always expects a flag rather than a comparator.
  */
 inline PRInt32 MsgFind(nsAString &str, const char *what, bool ignore_case, PRUint32 offset)
 {
   return str.Find(what, offset, ignore_case);
 }
 
-inline PRInt32 MsgFind(nsACString &str, const char *what, bool ignore_case, PRUint32 offset)
+inline PRInt32 MsgFind(nsACString &str, const char *what, bool ignore_case, PRInt32 offset)
 {
+  /* See Find_ComputeSearchRange from nsStringObsolete.cpp */
+  if (offset < 0) {
+    offset = 0;
+  }
   if (ignore_case)
-    return str.Find(what, offset, CaseInsensitiveCompare);
-  return str.Find(what, offset);
+    return str.Find(nsDependentCString(what), offset, CaseInsensitiveCompare);
+  return str.Find(nsDependentCString(what), offset);
 }
 
-inline PRInt32 MsgFind(nsACString &str, const nsACString &what, bool ignore_case, PRUint32 offset)
+inline PRInt32 MsgFind(nsACString &str, const nsACString &what, bool ignore_case, PRInt32 offset)
 {
+  /* See Find_ComputeSearchRange from nsStringObsolete.cpp */
+  if (offset < 0) {
+    offset = 0;
+  }
   if (ignore_case)
     return str.Find(what, offset, CaseInsensitiveCompare);
   return str.Find(what, offset);
 }
 
 /**
  * The following methods are not exposed to the external API so we define
  * equivalent versions here.