Bug 389437. Handle searching for word breaks when starting at the end of the available text. r=smontagu,a=damon
authorroc+@cs.cmu.edu
Mon, 10 Sep 2007 16:03:18 -0700
changeset 5844 b3bbfcc4f9a02aae2e1bbf5c6f136d4ca44e625c
parent 5843 79e8c861a0dd70389b8ea77092fbff989b24cd2f
child 5845 8da116883551365b5f864915e394a263c668ed70
push idunknown
push userunknown
push dateunknown
reviewerssmontagu, damon
bugs389437
milestone1.9a8pre
Bug 389437. Handle searching for word breaks when starting at the end of the available text. r=smontagu,a=damon
intl/lwbrk/src/nsSampleWordBreaker.cpp
--- a/intl/lwbrk/src/nsSampleWordBreaker.cpp
+++ b/intl/lwbrk/src/nsSampleWordBreaker.cpp
@@ -158,16 +158,18 @@ nsWordRange nsSampleWordBreaker::FindWor
   return range;
 }
 
 PRInt32 nsSampleWordBreaker::NextWord( 
   const PRUnichar* aText, PRUint32 aLen, PRUint32 aPos) 
 {
   PRInt8 c1, c2;
   PRUint32 cur = aPos;
+  if (cur == aLen)
+    return NS_WORDBREAKER_NEED_MORE_TEXT;
   c1 = this->GetClass(aText[cur]);
  
   for(cur++; cur <aLen; cur++)
   {
      c2 = this->GetClass(aText[cur]);
      if(c2 != c1) 
        break;
   }
@@ -181,16 +183,21 @@ PRInt32 nsSampleWordBreaker::NextWord(
   return cur;
 }
 
 PRInt32 nsSampleWordBreaker::PrevWord(
   const PRUnichar* aText, PRUint32 aLen, PRUint32 aPos) 
 {
   PRInt8 c1, c2;
   PRUint32 cur = aPos;
+  if (cur == aLen) {
+    if (cur == 0)
+      return NS_WORDBREAKER_NEED_MORE_TEXT;
+    --cur;
+  }
   c1 = this->GetClass(aText[cur]);
 
   for(; cur > 0; cur--)
   {
      c2 = this->GetClass(aText[cur-1]);
      if(c2 != c1)
        break;
   }