[Libreoffice-commits] .: sw/source

Caolán McNamara caolan at kemper.freedesktop.org
Fri Jul 8 16:15:31 PDT 2011


 sw/source/core/inc/scriptinfo.hxx |   25 ++++++++--------
 sw/source/core/txtnode/txtedt.cxx |   59 ++++++++++++++++++--------------------
 2 files changed, 42 insertions(+), 42 deletions(-)

New commits:
commit 65d3573c5afd7fd132b30c41a240d1d2d04c8527
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Sat Jul 9 00:13:40 2011 +0100

    Resolves: fdo#34779 wrong word counts for USHRT_MAX len paras

diff --git a/sw/source/core/inc/scriptinfo.hxx b/sw/source/core/inc/scriptinfo.hxx
index 636e884..e84b673 100644
--- a/sw/source/core/inc/scriptinfo.hxx
+++ b/sw/source/core/inc/scriptinfo.hxx
@@ -53,24 +53,25 @@ typedef std::list< xub_StrLen > PositionList;
 
 class SwScanner
 {
-    XubString aWord;
+    rtl::OUString aWord;
     const SwTxtNode& rNode;
-    const String& rText;
+    const rtl::OUString& rText;
     const LanguageType* pLanguage;
     const ModelToViewHelper::ConversionMap* pConversionMap;
-    xub_StrLen nStartPos;
-    xub_StrLen nEndPos;
-    xub_StrLen nBegin;
-    xub_StrLen nLen;
+    sal_Int32 nStartPos;
+    sal_Int32 nEndPos;
+    sal_Int32 nBegin;
+    sal_Int32 nLen;
     LanguageType aCurrLang;
     sal_uInt16 nWordType;
     sal_Bool bClip;
 
 public:
-    SwScanner( const SwTxtNode& rNd, const String& rTxt, const LanguageType* pLang,
+    SwScanner( const SwTxtNode& rNd, const rtl::OUString& rTxt,
+               const LanguageType* pLang,
                const ModelToViewHelper::ConversionMap* pConvMap,
                sal_uInt16 nWordType,
-               xub_StrLen nStart, xub_StrLen nEnde, sal_Bool bClip = sal_False );
+               sal_Int32 nStart, sal_Int32 nEnde, sal_Bool bClip = sal_False );
 
 
     // This next word function tries to find the language for the next word
@@ -78,11 +79,11 @@ public:
     // ! bReverse
     sal_Bool NextWord();
 
-    const XubString& GetWord() const    { return aWord; }
+    const rtl::OUString& GetWord() const    { return aWord; }
 
-    xub_StrLen GetBegin() const         { return nBegin; }
-    xub_StrLen GetEnd() const           { return nBegin + nLen; }
-    xub_StrLen GetLen() const           { return nLen; }
+    sal_Int32 GetBegin() const         { return nBegin; }
+    sal_Int32 GetEnd() const           { return nBegin + nLen; }
+    sal_Int32 GetLen() const           { return nLen; }
 
     LanguageType GetCurrentLanguage() const {return aCurrLang;}
 };
diff --git a/sw/source/core/txtnode/txtedt.cxx b/sw/source/core/txtnode/txtedt.cxx
index 73bc7ff..d9977aa 100644
--- a/sw/source/core/txtnode/txtedt.cxx
+++ b/sw/source/core/txtnode/txtedt.cxx
@@ -661,9 +661,9 @@ XubString SwTxtNode::GetCurWord( xub_StrLen nPos ) const
                        static_cast<xub_StrLen>(aBndry.endPos - aBndry.startPos) );
 }
 
-SwScanner::SwScanner( const SwTxtNode& rNd, const String& rTxt, const LanguageType* pLang,
-                      const ModelToViewHelper::ConversionMap* pConvMap,
-                      sal_uInt16 nType, xub_StrLen nStart, xub_StrLen nEnde, sal_Bool bClp )
+SwScanner::SwScanner( const SwTxtNode& rNd, const rtl::OUString& rTxt,
+    const LanguageType* pLang, const ModelToViewHelper::ConversionMap* pConvMap,
+    sal_uInt16 nType, sal_Int32 nStart, sal_Int32 nEnde, sal_Bool bClp )
     : rNode( rNd ), rText( rTxt), pLanguage( pLang ), pConversionMap( pConvMap ), nLen( 0 ), nWordType( nType ), bClip( bClp )
 {
     OSL_ENSURE( rText.Len(), "SwScanner: EmptyString" );
@@ -677,7 +677,7 @@ SwScanner::SwScanner( const SwTxtNode& rNd, const String& rTxt, const LanguageTy
     else
     {
         ModelToViewHelper::ModelPosition aModelBeginPos = ModelToViewHelper::ConvertToModelPosition( pConversionMap, nBegin );
-        const xub_StrLen nModelBeginPos = (xub_StrLen)aModelBeginPos.mnPos;
+        const sal_Int32 nModelBeginPos = aModelBeginPos.mnPos;
         aCurrLang = rNd.GetLang( nModelBeginPos );
     }
 }
@@ -693,22 +693,22 @@ sal_Bool SwScanner::NextWord()
     while ( true )
     {
         // skip non-letter characters:
-        while ( nBegin < rText.Len() )
+        while ( nBegin < rText.getLength() )
         {
-            if ( !lcl_IsSkippableWhiteSpace( rText.GetChar( nBegin ) ) )
+            if ( !lcl_IsSkippableWhiteSpace( rText[nBegin] ) )
             {
                 if ( !pLanguage )
                 {
                     const sal_uInt16 nNextScriptType = pBreakIt->GetBreakIter()->getScriptType( rText, nBegin );
                     ModelToViewHelper::ModelPosition aModelBeginPos = ModelToViewHelper::ConvertToModelPosition( pConversionMap, nBegin );
-                    const xub_StrLen nBeginModelPos = (xub_StrLen)aModelBeginPos.mnPos;
+                    const sal_Int32 nBeginModelPos = aModelBeginPos.mnPos;
                     aCurrLang = rNode.GetLang( nBeginModelPos, 1, nNextScriptType );
                 }
 
                 if ( nWordType != i18n::WordType::WORD_COUNT )
                 {
                     rCC.setLocale( pBreakIt->GetLocale( aCurrLang ) );
-                    if ( rCC.isLetterNumeric( rText.GetChar( nBegin ) ) )
+                    if ( rCC.isLetterNumeric( rText[nBegin] ) )
                         break;
                 }
                 else
@@ -717,7 +717,7 @@ sal_Bool SwScanner::NextWord()
             ++nBegin;
         }
 
-        if ( nBegin >= rText.Len() || nBegin >= nEndPos )
+        if ( nBegin >= rText.getLength() || nBegin >= nEndPos )
             return sal_False;
 
         // get the word boundaries
@@ -741,21 +741,21 @@ sal_Bool SwScanner::NextWord()
     // #i89042, as discussed with HDU: don't evaluate script changes for word count. Use whole word.
     if ( nWordType == i18n::WordType::WORD_COUNT )
     {
-        nBegin = Max( static_cast< xub_StrLen >(aBound.startPos), nBegin );
+        nBegin = Max(aBound.startPos, nBegin);
         nLen   = 0;
-        if (static_cast< xub_StrLen >(aBound.endPos) > nBegin)
-            nLen = static_cast< xub_StrLen >(aBound.endPos) - nBegin;
+        if (aBound.endPos > nBegin)
+            nLen = aBound.endPos - nBegin;
     }
     else
     {
         // we have to differenciate between these cases:
         if ( aBound.startPos <= nBegin )
         {
-        OSL_ENSURE( aBound.endPos >= nBegin, "Unexpected aBound result" );
+            OSL_ENSURE( aBound.endPos >= nBegin, "Unexpected aBound result" );
 
             // restrict boundaries to script boundaries and nEndPos
             const sal_uInt16 nCurrScript = pBreakIt->GetBreakIter()->getScriptType( rText, nBegin );
-            XubString aTmpWord = rText.Copy( nBegin, static_cast<xub_StrLen>(aBound.endPos - nBegin) );
+            rtl::OUString aTmpWord = rText.copy( nBegin, aBound.endPos - nBegin );
             const sal_Int32 nScriptEnd = nBegin +
                 pBreakIt->GetBreakIter()->endOfScript( aTmpWord, 0, nCurrScript );
             const sal_Int32 nEnd = Min( aBound.endPos, nScriptEnd );
@@ -765,42 +765,42 @@ sal_Bool SwScanner::NextWord()
             if ( aBound.startPos < nBegin )
             {
                 // search from nBegin backwards until the next script change
-                aTmpWord = rText.Copy( static_cast<xub_StrLen>(aBound.startPos),
-                                       static_cast<xub_StrLen>(nBegin - aBound.startPos + 1) );
+                aTmpWord = rText.copy( aBound.startPos,
+                                       nBegin - aBound.startPos + 1 );
                 nScriptBegin = aBound.startPos +
                     pBreakIt->GetBreakIter()->beginOfScript( aTmpWord, nBegin - aBound.startPos,
                                                     nCurrScript );
             }
 
-            nBegin = (xub_StrLen)Max( aBound.startPos, nScriptBegin );
-            nLen = (xub_StrLen)(nEnd - nBegin);
+            nBegin = Max( aBound.startPos, nScriptBegin );
+            nLen = nEnd - nBegin;
         }
         else
         {
             const sal_uInt16 nCurrScript = pBreakIt->GetBreakIter()->getScriptType( rText, aBound.startPos );
-            XubString aTmpWord = rText.Copy( static_cast<xub_StrLen>(aBound.startPos),
-                                             static_cast<xub_StrLen>(aBound.endPos - aBound.startPos) );
+            rtl::OUString aTmpWord = rText.copy( aBound.startPos,
+                                             aBound.endPos - aBound.startPos );
             const sal_Int32 nScriptEnd = aBound.startPos +
                 pBreakIt->GetBreakIter()->endOfScript( aTmpWord, 0, nCurrScript );
             const sal_Int32 nEnd = Min( aBound.endPos, nScriptEnd );
-            nBegin = (xub_StrLen)aBound.startPos;
-            nLen = (xub_StrLen)(nEnd - nBegin);
+            nBegin = aBound.startPos;
+            nLen = nEnd - nBegin;
         }
     }
 
     // optionally clip the result of getWordBoundaries:
     if ( bClip )
     {
-        aBound.startPos = Max( (xub_StrLen)aBound.startPos, nStartPos );
-        aBound.endPos = Min( (xub_StrLen)aBound.endPos, nEndPos );
-        nBegin = (xub_StrLen)aBound.startPos;
-        nLen = (xub_StrLen)(aBound.endPos - nBegin);
+        aBound.startPos = Max( aBound.startPos, nStartPos );
+        aBound.endPos = Min( aBound.endPos, nEndPos );
+        nBegin = aBound.startPos;
+        nLen = aBound.endPos - nBegin;
     }
 
     if( ! nLen )
         return sal_False;
 
-    aWord = rText.Copy( nBegin, nLen );
+    aWord = rText.copy( nBegin, nLen );
 
     return sal_True;
 }
@@ -1847,10 +1847,9 @@ void SwTxtNode::CountWords( SwDocStat& rStat,
     // count words in masked and expanded text:
     if( pBreakIt->GetBreakIter().is() )
     {
-        const String aScannerText( aExpandText );
         // zero is NULL for pLanguage -----------v               last param = true for clipping
-        SwScanner aScanner( *this, aScannerText, 0, pConversionMap, i18n::WordType::WORD_COUNT,
-                            (xub_StrLen)nExpandBegin, (xub_StrLen)nExpandEnd, true );
+        SwScanner aScanner( *this, aExpandText, 0, pConversionMap, i18n::WordType::WORD_COUNT,
+                            nExpandBegin, nExpandEnd, true );
 
         // used to filter out scanner returning almost empty strings (len=1; unichar=0x0001)
         const rtl::OUString aBreakWord( CH_TXTATR_BREAKWORD );


More information about the Libreoffice-commits mailing list