Bug 1368646 - Expose nsSampleWordBreaker::GetClass as a public static function in nsIWordBreaker. r=emk
authorXidorn Quan <me@upsuper.org>
Thu, 01 Jun 2017 17:02:54 +1000
changeset 361788 4e8564ce92d8056d6282a499cac1933f4a90a769
parent 361787 d7b4edc492490251642bc0e35b244147b31b72e9
child 361789 9d8e1c9e19e009ec64bbae332a78b87c5acd7150
push id31943
push userryanvm@gmail.com
push dateThu, 01 Jun 2017 15:54:45 +0000
treeherdermozilla-central@62005e6aecdf [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersemk
bugs1368646
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1368646 - Expose nsSampleWordBreaker::GetClass as a public static function in nsIWordBreaker. r=emk MozReview-Commit-ID: VORgEZOVl0
intl/lwbrk/nsIWordBreaker.h
intl/lwbrk/nsSampleWordBreaker.cpp
intl/lwbrk/nsSampleWordBreaker.h
--- a/intl/lwbrk/nsIWordBreaker.h
+++ b/intl/lwbrk/nsIWordBreaker.h
@@ -16,26 +16,38 @@
 { 0xe86b3379, 0xbf89, 0x11d2, \
    { 0xb3, 0xaf, 0x0, 0x80, 0x5f, 0x8a, 0x66, 0x70 } }
 
 typedef struct {
   uint32_t mBegin;
   uint32_t mEnd;
 } nsWordRange;
 
+enum nsWordBreakClass : uint8_t {
+  kWbClassSpace = 0,
+  kWbClassAlphaLetter,
+  kWbClassPunct,
+  kWbClassHanLetter,
+  kWbClassKatakanaLetter,
+  kWbClassHiraganaLetter,
+  kWbClassHWKatakanaLetter,
+  kWbClassThaiLetter
+};
+
 class nsIWordBreaker : public nsISupports
 {
 public:
   NS_DECLARE_STATIC_IID_ACCESSOR(NS_IWORDBREAKER_IID)
 
   virtual bool BreakInBetween(const char16_t* aText1 , uint32_t aTextLen1,
                                 const char16_t* aText2 ,
                                 uint32_t aTextLen2) = 0;
   virtual nsWordRange FindWord(const char16_t* aText1 , uint32_t aTextLen1,
                                uint32_t aOffset) = 0;
   virtual int32_t NextWord(const char16_t* aText, uint32_t aLen, 
                            uint32_t aPos) = 0;
                            
+  static nsWordBreakClass GetClass(char16_t aChar);
 };
 
 NS_DEFINE_STATIC_IID_ACCESSOR(nsIWordBreaker, NS_IWORDBREAKER_IID)
 
 #endif  /* nsIWordBreaker_h__ */
--- a/intl/lwbrk/nsSampleWordBreaker.cpp
+++ b/intl/lwbrk/nsSampleWordBreaker.cpp
@@ -20,34 +20,35 @@ bool nsSampleWordBreaker::BreakInBetween
   const char16_t* aText2 , uint32_t aTextLen2)
 {
   NS_PRECONDITION( nullptr != aText1, "null ptr");
   NS_PRECONDITION( nullptr != aText2, "null ptr");
 
   if(!aText1 || !aText2 || (0 == aTextLen1) || (0 == aTextLen2))
     return false;
 
-  return (this->GetClass(aText1[aTextLen1-1]) != this->GetClass(aText2[0]));
+  return GetClass(aText1[aTextLen1-1]) != GetClass(aText2[0]);
 }
 
 
 #define IS_ASCII(c)            (0 == ( 0xFF80 & (c)))
 #define ASCII_IS_ALPHA(c)         ((( 'a' <= (c)) && ((c) <= 'z')) || (( 'A' <= (c)) && ((c) <= 'Z')))
 #define ASCII_IS_DIGIT(c)         (( '0' <= (c)) && ((c) <= '9'))
 #define ASCII_IS_SPACE(c)         (( ' ' == (c)) || ( '\t' == (c)) || ( '\r' == (c)) || ( '\n' == (c)))
 #define IS_ALPHABETICAL_SCRIPT(c) ((c) < 0x2E80) 
 
 // we change the beginning of IS_HAN from 0x4e00 to 0x3400 to relfect Unicode 3.0 
 #define IS_HAN(c)              (( 0x3400 <= (c)) && ((c) <= 0x9fff))||(( 0xf900 <= (c)) && ((c) <= 0xfaff))
 #define IS_KATAKANA(c)         (( 0x30A0 <= (c)) && ((c) <= 0x30FF))
 #define IS_HIRAGANA(c)         (( 0x3040 <= (c)) && ((c) <= 0x309F))
 #define IS_HALFWIDTHKATAKANA(c)         (( 0xFF60 <= (c)) && ((c) <= 0xFF9F))
 #define IS_THAI(c)         (0x0E00 == (0xFF80 & (c) )) // Look at the higest 9 bits
 
-uint8_t nsSampleWordBreaker::GetClass(char16_t c)
+/* static */ nsWordBreakClass
+nsIWordBreaker::GetClass(char16_t c)
 {
   // begin of the hack
 
   if (IS_ALPHABETICAL_SCRIPT(c))  {
 	  if(IS_ASCII(c))  {
 		  if(ASCII_IS_SPACE(c)) {
 			  return kWbClassSpace;
 		  } else if(ASCII_IS_ALPHA(c) || ASCII_IS_DIGIT(c)) {
@@ -70,17 +71,17 @@ uint8_t nsSampleWordBreaker::GetClass(ch
 	  } else if(IS_HIRAGANA(c))   {
 		  return kWbClassHiraganaLetter;
 	  } else if(IS_HALFWIDTHKATAKANA(c))  {
 		  return kWbClassHWKatakanaLetter;
 	  } else  {
 		  return kWbClassAlphaLetter;
 	  }
   }
-  return 0;
+  return static_cast<nsWordBreakClass>(0);
 }
 
 nsWordRange nsSampleWordBreaker::FindWord(
   const char16_t* aText , uint32_t aTextLen,
   uint32_t aOffset)
 {
   nsWordRange range;
   NS_PRECONDITION( nullptr != aText, "null ptr");
@@ -88,59 +89,59 @@ nsWordRange nsSampleWordBreaker::FindWor
   NS_PRECONDITION( aOffset <= aTextLen, "aOffset > aTextLen");
 
   range.mBegin = aTextLen + 1;
   range.mEnd = aTextLen + 1;
 
   if(!aText || aOffset > aTextLen)
     return range;
 
-  uint8_t c = this->GetClass(aText[aOffset]);
+  nsWordBreakClass c = GetClass(aText[aOffset]);
   uint32_t i;
   // Scan forward
   range.mEnd--;
   for(i = aOffset +1;i <= aTextLen; i++)
   {
-     if( c != this->GetClass(aText[i]))
+     if( c != GetClass(aText[i]))
      {
        range.mEnd = i;
        break;
      }
   }
 
   // Scan backward
   range.mBegin = 0;
   for(i = aOffset ;i > 0; i--)
   {
-     if( c != this->GetClass(aText[i-1]))
+     if( c != GetClass(aText[i-1]))
      {
        range.mBegin = i;
        break;
      }
   }
   if(kWbClassThaiLetter == c)
   {
 	// need to call Thai word breaker from here
 	// we should pass the whole Thai segment to the thai word breaker to find a shorter answer
   }
   return range;
 }
 
 int32_t nsSampleWordBreaker::NextWord( 
   const char16_t* aText, uint32_t aLen, uint32_t aPos) 
 {
-  int8_t c1, c2;
+  nsWordBreakClass c1, c2;
   uint32_t cur = aPos;
   if (cur == aLen)
     return NS_WORDBREAKER_NEED_MORE_TEXT;
-  c1 = this->GetClass(aText[cur]);
+  c1 = GetClass(aText[cur]);
  
   for(cur++; cur <aLen; cur++)
   {
-     c2 = this->GetClass(aText[cur]);
+     c2 = GetClass(aText[cur]);
      if(c2 != c1) 
        break;
   }
   if(kWbClassThaiLetter == c1)
   {
 	// need to call Thai word breaker from here
 	// we should pass the whole Thai segment to the thai word breaker to find a shorter answer
   }
--- a/intl/lwbrk/nsSampleWordBreaker.h
+++ b/intl/lwbrk/nsSampleWordBreaker.h
@@ -3,40 +3,27 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 #ifndef nsSampleWordBreaker_h__
 #define nsSampleWordBreaker_h__
 
 
 #include "nsIWordBreaker.h"
 
-typedef enum {
-  kWbClassSpace = 0,
-  kWbClassAlphaLetter,
-  kWbClassPunct,
-  kWbClassHanLetter,
-  kWbClassKatakanaLetter,
-  kWbClassHiraganaLetter,
-  kWbClassHWKatakanaLetter,
-  kWbClassThaiLetter
-} wb_class;
-
 class nsSampleWordBreaker : public nsIWordBreaker
 {
   NS_DECL_ISUPPORTS
 public:
 
   nsSampleWordBreaker() ;
 
   bool BreakInBetween(const char16_t* aText1 , uint32_t aTextLen1,
                         const char16_t* aText2 , uint32_t aTextLen2) override;
   nsWordRange FindWord(const char16_t* aText1 , uint32_t aTextLen1,
                        uint32_t aOffset) override;
 
   int32_t NextWord(const char16_t* aText, uint32_t aLen, uint32_t aPos) override;
 
 protected:
-  uint8_t  GetClass(char16_t aChar);
-
   virtual ~nsSampleWordBreaker();
 };
 
 #endif  /* nsSampleWordBreaker_h__ */