Bug 1425206 - port bug 1424898 to mailnews: nsILineBreaker and nsIWordBreaker are no longer COM services. rs=bustage-fix
authorJorg K <jorgk@jorgk.com>
Thu, 14 Dec 2017 11:45:43 +0100
changeset 22864 cdceb81023b89971e63cd7916fbe394d3497dc1f
parent 22863 8111785ba27ec36701b5f216dc80509c8960ea3a
child 22865 1b9ac062781a2de16b47869b84c92f7e134dd589
push id13849
push usermozilla@jorgk.com
push dateThu, 14 Dec 2017 10:48:13 +0000
treeherdercomm-central@cdceb81023b8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbustage-fix
bugs1425206, 1424898
Bug 1425206 - port bug 1424898 to mailnews: nsILineBreaker and nsIWordBreaker are no longer COM services. rs=bustage-fix
mailnews/compose/src/nsMsgComposeService.cpp
mailnews/extensions/bayesian-spam-filter/src/nsBayesianFilter.cpp
mailnews/extensions/bayesian-spam-filter/src/nsBayesianFilter.h
--- a/mailnews/compose/src/nsMsgComposeService.cpp
+++ b/mailnews/compose/src/nsMsgComposeService.cpp
@@ -40,18 +40,17 @@
 #include "nsNetUtil.h"
 #include "nsIMsgMailNewsUrl.h"
 #include "nsIInterfaceRequestorUtils.h"
 #include "nsIMsgDatabase.h"
 #include "nsIDocumentEncoder.h"
 #include "nsContentCID.h"
 #include "nsISelection.h"
 #include "nsUTF8Utils.h"
-#include "nsILineBreaker.h"
-#include "nsLWBrkCIID.h"
+#include "mozilla/intl/LineBreaker.h"
 #include "mozilla/Services.h"
 #include "mimemoz2.h"
 #include "nsIArray.h"
 #include "nsArrayUtils.h"
 
 #ifdef MSGCOMP_TRACE_PERFORMANCE
 #include "mozilla/Logging.h"
 #include "nsIMsgHdr.h"
@@ -291,31 +290,31 @@ nsMsgComposeService::GetOrigWindowSelect
 
     // If "mailnews.reply_quoting_selection.multi_word" is on, then there must be at least
     // two words selected in order to quote just the selected text
     if (requireMultipleWords)
     {
       if (selPlain.IsEmpty())
         return NS_ERROR_ABORT;
 
-      nsCOMPtr<nsILineBreaker> lineBreaker = do_GetService(NS_LBRK_CONTRACTID, &rv);
+      RefPtr<mozilla::intl::LineBreaker> lineBreaker = mozilla::intl::LineBreaker::Create();
 
       if (NS_SUCCEEDED(rv))
       {
         const uint32_t length = selPlain.Length();
         const char16_t* unicodeStr = selPlain.get();
         int32_t endWordPos = lineBreaker->Next(unicodeStr, length, 0);
 
         // If there's not even one word, then there's not multiple words
         if (endWordPos == NS_LINEBREAKER_NEED_MORE_TEXT)
           return NS_ERROR_ABORT;
 
         // If after the first word is only space, then there's not multiple words
         const char16_t* end;
-        for (end = unicodeStr + endWordPos; NS_IsSpace(*end); end++)
+        for (end = unicodeStr + endWordPos; mozilla::intl::NS_IsSpace(*end); end++)
           ;
         if (!*end)
           return NS_ERROR_ABORT;
       }
     }
 
     if (!charsOnlyIf.IsEmpty())
     {
--- a/mailnews/extensions/bayesian-spam-filter/src/nsBayesianFilter.cpp
+++ b/mailnews/extensions/bayesian-spam-filter/src/nsBayesianFilter.cpp
@@ -23,17 +23,16 @@
 #include "nsIMsgMailNewsUrl.h"
 #include "nsIMimeMiscStatus.h"
 #include "nsIPrefService.h"
 #include "nsIPrefBranch.h"
 #include "nsIStringEnumerator.h"
 #include "nsIObserverService.h"
 #include "nsIChannel.h"
 #include "nsDependentSubstring.h"
-#include "nsLWBrkCIID.h"
 #include "nsMemory.h"
 
 #include "mozilla/ArenaAllocatorExtensions.h" // for ArenaStrdup
 
 using namespace mozilla;
 
 // needed to mark attachment flag on the db hdr
 #include "nsIMsgHdr.h"
@@ -714,35 +713,32 @@ nsresult Tokenizer::stripHTML(const nsAS
     do_GetService(NS_PARSERUTILS_CONTRACTID);
   return utils->ConvertToPlainText(inString, flags, 80, outString);
 }
 
 // Copied from nsSemanticUnitScanner.cpp which was removed in bug 1368418.
 nsresult Tokenizer::ScannerNext(const char16_t *text, int32_t length, int32_t pos, bool isLastBuffer, int32_t *begin, int32_t *end, bool *_retval)
 {
     if (!mWordBreaker) {
-      nsresult rv;
-      mWordBreaker = do_CreateInstance(NS_WBRK_CONTRACTID, &rv);
-      if (NS_FAILED(rv))
-        return rv;
+      mWordBreaker = mozilla::intl::WordBreaker::Create();
     }
 
     // if we reach the end, just return
     if (pos >= length) {
        *begin = pos;
        *end = pos;
        *_retval = false;
        return NS_OK;
     }
 
-    nsWordBreakClass char_class = nsIWordBreaker::GetClass(text[pos]);
+    mozilla::intl::WordBreakClass char_class = mozilla::intl::WordBreaker::GetClass(text[pos]);
 
     // If we are in Chinese mode, return one Han letter at a time.
     // We should not do this if we are in Japanese or Korean mode.
-    if (kWbClassHanLetter == char_class) {
+    if (mozilla::intl::kWbClassHanLetter == char_class) {
        *begin = pos;
        *end = pos+1;
        *_retval = true;
        return NS_OK;
     }
 
     int32_t next;
     // Find the next "word".
@@ -752,17 +748,18 @@ nsresult Tokenizer::ScannerNext(const ch
     if (next == NS_WORDBREAKER_NEED_MORE_TEXT) {
        *begin = pos;
        *end = isLastBuffer ? length : pos;
        *_retval = isLastBuffer;
        return NS_OK;
     }
 
     // If what we got is space or punct, look at the next break.
-    if ((char_class == kWbClassSpace) || (char_class == kWbClassPunct)) {
+    if (char_class == mozilla::intl::kWbClassSpace ||
+        char_class == mozilla::intl::kWbClassPunct) {
         // If the next "word" is not letters,
         // call itself recursively with the new pos.
         return ScannerNext(text, length, next, isLastBuffer, begin, end, _retval);
     }
 
     // For the rest, return.
     *begin = pos;
     *end = next;
--- a/mailnews/extensions/bayesian-spam-filter/src/nsBayesianFilter.h
+++ b/mailnews/extensions/bayesian-spam-filter/src/nsBayesianFilter.h
@@ -10,17 +10,17 @@
 #include "nsCOMPtr.h"
 #include "nsIMsgFilterPlugin.h"
 #include "PLDHashTable.h"
 #include "nsITimer.h"
 #include "nsTArray.h"
 #include "nsString.h"
 #include "nsWeakReference.h"
 #include "nsIObserver.h"
-#include "nsIWordBreaker.h"
+#include "mozilla/intl/WordBreaker.h"
 
 #include "mozilla/ArenaAllocator.h"
 
 #define DEFAULT_MIN_INTERVAL_BETWEEN_WRITES             15*60*1000
 
 struct Token;
 class TokenEnumeration;
 class TokenAnalyzer;
@@ -146,17 +146,17 @@ private:
     void tokenize_japanese_word(char* chunk);
     inline void addTokenForHeader(const char * aTokenPrefix, nsACString& aValue,
         bool aTokenizeValue = false, const char* aDelimiters = nullptr);
     nsresult stripHTML(const nsAString& inString, nsAString& outString);
     // helper function to escape \n, \t, etc from a CString
     void UnescapeCString(nsCString& aCString);
     nsresult ScannerNext(const char16_t *text, int32_t length, int32_t pos,
                          bool isLastBuffer, int32_t *begin, int32_t *end, bool *_retval);
-    nsCOMPtr<nsIWordBreaker> mWordBreaker;
+    RefPtr<mozilla::intl::WordBreaker> mWordBreaker;
 };
 
 /**
  * Implements storage of a collection of message tokens and counts for
  * a corpus of classified messages
  */
 
 class CorpusStore: public TokenHash {