Date: prev next · Thread: first prev next last
2011 Archives by date, by thread · List index


Hello all,

Tonight I tried to remove some uses of setCharAt so that it can
eventually be removed, and I ran across a few cases that I would like
to get another pair of eyes on. Especially in one particular case, I
added a guard to make sure that the index was within range and I want
to make sure that it is necessary or if something more involved is
required. The patch is attached, and I remembered to add [PATCH] to
the subject this time :)

August Sodora
augsod@gmail.com
(201) 280-8138
From 6e9f990565c46f7dc46e8e3aae1a50122f3104c2 Mon Sep 17 00:00:00 2001
From: August Sodora <augsod@gmail.com>
Date: Sat, 26 Nov 2011 02:03:23 -0500
Subject: [PATCH] Remove uses of OUString::setCharAt

---
 basic/source/sbx/sbxcurr.cxx                     |   10 +++---
 sdext/source/pdfimport/tree/imagecontainer.cxx   |   14 ++++----
 svl/source/misc/lngmisc.cxx                      |    6 ++-
 writerfilter/source/dmapper/ConversionHelper.cxx |   38 +++++++++++-----------
 4 files changed, 35 insertions(+), 33 deletions(-)

diff --git a/basic/source/sbx/sbxcurr.cxx b/basic/source/sbx/sbxcurr.cxx
index c227681..2a1f915 100644
--- a/basic/source/sbx/sbxcurr.cxx
+++ b/basic/source/sbx/sbxcurr.cxx
@@ -87,13 +87,13 @@ static rtl::OUString ImpCurrencyToString( const sal_Int64 &rVal )
     for ( sal_Int32 charCpyIndex = aAbsStr.getLength() - 1; nInsertIndex >= nEndIndex;  
++nDigitCount )
     {
         if ( nDigitCount == 4 )
-            aBuf.setCharAt( nInsertIndex--, cDecimalSep );
+            aBuf[nInsertIndex--] = cDecimalSep;
 #if MAYBEFUTURE
         if ( nDigitCount > 4 && ! ( ( nDigitCount - 4  ) % 3) )
-            aBuf.setCharAt( nInsertIndex--, cThousandSep );
+            aBuf[nInsertIndex--] = cThousandSep;
 #endif
         if ( nDigitCount < initialLen )
-            aBuf.setCharAt( nInsertIndex--, aAbsStr[ charCpyIndex-- ] );
+            aBuf[nInsertIndex--] = aAbsStr[ charCpyIndex-- ];
         else
         // Handle leading 0's to right of decimal point
         // Note: in VBA the stringification is a little more complex
@@ -106,10 +106,10 @@ static rtl::OUString ImpCurrencyToString( const sal_Int64 &rVal )
         // 0     0.0000     0
         // 0.1   0.1000     0.1
 
-            aBuf.setCharAt( nInsertIndex--, (sal_Unicode)'0' );
+            aBuf[nInsertIndex--] = (sal_Unicode)'0';
     }
     if ( isNeg )
-            aBuf.setCharAt( nInsertIndex, (sal_Unicode)'-' );
+            aBuf[nInsertIndex] = (sal_Unicode)'-';
 
     aAbsStr = aBuf.makeStringAndClear();
     return aAbsStr;
diff --git a/sdext/source/pdfimport/tree/imagecontainer.cxx 
b/sdext/source/pdfimport/tree/imagecontainer.cxx
index 9be7bb5..0d0f461 100644
--- a/sdext/source/pdfimport/tree/imagecontainer.cxx
+++ b/sdext/source/pdfimport/tree/imagecontainer.cxx
@@ -75,16 +75,16 @@ rtl::OUString encodeBase64( const sal_Int8* i_pBuffer, const sal_uInt32 i_nBuffe
         aBuf.appendAscii("====");
 
         sal_uInt8 nIndex (static_cast<sal_uInt8>((nBinary & 0xFC0000) >> 18));
-        aBuf.setCharAt(nBufPos, aBase64EncodeTable [nIndex]);
+        aBuf[nBufPos] = aBase64EncodeTable [nIndex];
 
         nIndex = static_cast<sal_uInt8>((nBinary & 0x3F000) >> 12);
-        aBuf.setCharAt(nBufPos+1, aBase64EncodeTable [nIndex]);
+        aBuf[nBufPos+1] = aBase64EncodeTable [nIndex];
 
         nIndex = static_cast<sal_uInt8>((nBinary & 0xFC0) >> 6);
-        aBuf.setCharAt(nBufPos+2, aBase64EncodeTable [nIndex]);
+        aBuf[nBufPos+2] = aBase64EncodeTable [nIndex];
 
         nIndex = static_cast<sal_uInt8>((nBinary & 0x3F));
-        aBuf.setCharAt(nBufPos+3, aBase64EncodeTable [nIndex]);
+        aBuf[nBufPos+3] = aBase64EncodeTable [nIndex];
     }
     if( nRemain > 0 )
     {
@@ -100,15 +100,15 @@ rtl::OUString encodeBase64( const sal_Int8* i_pBuffer, const sal_uInt32 
i_nBuffe
                 break;
         }
         sal_uInt8 nIndex (static_cast<sal_uInt8>((nBinary & 0xFC0000) >> 18));
-        aBuf.setCharAt(nBufPos, aBase64EncodeTable [nIndex]);
+        aBuf[nBufPos] = aBase64EncodeTable [nIndex];
 
         nIndex = static_cast<sal_uInt8>((nBinary & 0x3F000) >> 12);
-        aBuf.setCharAt(nBufPos+1, aBase64EncodeTable [nIndex]);
+        aBuf[nBufPos+1] = aBase64EncodeTable [nIndex];
 
         if( nRemain == 2 )
         {
             nIndex = static_cast<sal_uInt8>((nBinary & 0xFC0) >> 6);
-            aBuf.setCharAt(nBufPos+2, aBase64EncodeTable [nIndex]);
+            aBuf[nBufPos+2] = aBase64EncodeTable [nIndex];
         }
     }
 
diff --git a/svl/source/misc/lngmisc.cxx b/svl/source/misc/lngmisc.cxx
index ca1b68a..147eee0 100644
--- a/svl/source/misc/lngmisc.cxx
+++ b/svl/source/misc/lngmisc.cxx
@@ -85,7 +85,8 @@ sal_Bool RemoveControlChars( OUString &rTxt )
             if (!IsControlChar( cChar ))
             {
                 DBG_ASSERT( nCnt < nSize, "index out of range" );
-                aBuf.setCharAt( nCnt++, cChar );
+                if(nCnt < nSize)
+                    aBuf[nCnt++] = cChar;
             }
         }
         DBG_ASSERT( nCnt == nSize, "wrong size" );
@@ -120,7 +121,8 @@ sal_Bool ReplaceControlChars( rtl::OUString &rTxt, sal_Char /*aRplcChar*/ )
                 if (IsControlChar( cChar ))
                     cChar = ' ';
                 DBG_ASSERT( nCnt < nLen, "index out of range" );
-                aBuf.setCharAt( nCnt++, cChar );
+                if(nCnt < nLen)
+                    aBuf[nCnt++] = cChar;
             }
         }
         aBuf.setLength( nCnt );
diff --git a/writerfilter/source/dmapper/ConversionHelper.cxx 
b/writerfilter/source/dmapper/ConversionHelper.cxx
index a1ebac5..a803477 100644
--- a/writerfilter/source/dmapper/ConversionHelper.cxx
+++ b/writerfilter/source/dmapper/ConversionHelper.cxx
@@ -224,9 +224,9 @@ void lcl_SwapQuotesInField(::rtl::OUString &rFmt)
     for (sal_Int32 nI = 0; nI < nLen; ++nI)
     {
         if ((pFmt[nI] == '\"') && (!nI || pFmt[nI-1] != '\\'))
-            aBuffer.setCharAt(nI, '\'');
+            aBuffer[nI] = '\'';
         else if ((pFmt[nI] == '\'') && (!nI || pFmt[nI-1] != '\\'))
-            aBuffer.setCharAt(nI, '\"');
+            aBuffer[nI] = '\"';
     }
     rFmt = aBuffer.makeStringAndClear();
 }
@@ -235,8 +235,8 @@ bool lcl_IsNotAM(::rtl::OUString& rFmt, sal_Int32 nPos)
     return (
             (nPos == rFmt.getLength() - 1) ||
             (
-            (rFmt.getStr()[nPos+1] != 'M') &&
-            (rFmt.getStr()[nPos+1] != 'm')
+            (rFmt[nPos+1] != 'M') &&
+            (rFmt[nPos+1] != 'm')
             )
         );
 }
@@ -253,34 +253,34 @@ bool lcl_IsNotAM(::rtl::OUString& rFmt, sal_Int32 nPos)
     sal_Int32 nLen = sFormat.getLength();
     sal_Int32 nI = 0;
 //    const sal_Unicode* pFormat = sFormat.getStr();
-    ::rtl::OUStringBuffer aNewFormat( sFormat.getStr() );
+    ::rtl::OUStringBuffer aNewFormat( sFormat );
     while (nI < nLen)
     {
-        if (aNewFormat.charAt(nI) == '\\')
+        if (aNewFormat[nI] == '\\')
             nI++;
-        else if (aNewFormat.charAt(nI) == '\"')
+        else if (aNewFormat[nI] == '\"')
         {
             ++nI;
             //While not at the end and not at an unescaped end quote
-            while ((nI < nLen) && (!(aNewFormat.charAt(nI) == '\"') && (aNewFormat.charAt(nI-1) != 
'\\')))
+            while ((nI < nLen) && (!(aNewFormat[nI] == '\"') && (aNewFormat[nI-1] != '\\')))
                 ++nI;
         }
         else //normal unquoted section
         {
-            sal_Unicode nChar = aNewFormat.charAt(nI);
+            sal_Unicode nChar = aNewFormat[nI];
             if (nChar == 'O')
             {
-                aNewFormat.setCharAt(nI, 'M');
+                aNewFormat[nI] = 'M';
                 bForceNatNum = true;
             }
             else if (nChar == 'o')
             {
-                aNewFormat.setCharAt(nI, 'm');
+                aNewFormat[nI] = 'm';
                 bForceNatNum = true;
             }
             else if ((nChar == 'A') && lcl_IsNotAM(sFormat, nI))
             {
-                aNewFormat.setCharAt(nI, 'D');
+                aNewFormat[nI] = 'D';
                 bForceNatNum = true;
             }
             else if ((nChar == 'g') || (nChar == 'G'))
@@ -289,11 +289,11 @@ bool lcl_IsNotAM(::rtl::OUString& rFmt, sal_Int32 nPos)
                 bForceJapanese = true;
             else if (nChar == 'E')
             {
-                if ((nI != nLen-1) && (aNewFormat.charAt(nI+1) == 'E'))
+                if ((nI != nLen-1) && (aNewFormat[nI+1] == 'E'))
                 {
                     //todo: this cannot be the right way to replace a part of the string!
-                    aNewFormat.setCharAt( nI, 'Y' );
-                    aNewFormat.setCharAt( nI + 1, 'Y' );
+                    aNewFormat[nI] = 'Y';
+                    aNewFormat[nI + 1] = 'Y';
                     aNewFormat.insert(nI + 2, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("YY")));
                     nLen+=2;
                     nI+=3;
@@ -302,11 +302,11 @@ bool lcl_IsNotAM(::rtl::OUString& rFmt, sal_Int32 nPos)
             }
             else if (nChar == 'e')
             {
-                if ((nI != nLen-1) && (aNewFormat.charAt(nI+1) == 'e'))
+                if ((nI != nLen-1) && (aNewFormat[nI+1] == 'e'))
                 {
                     //todo: this cannot be the right way to replace a part of the string!
-                    aNewFormat.setCharAt( nI, 'y' );
-                    aNewFormat.setCharAt( nI + 1, 'y' );
+                    aNewFormat[nI] = 'y';
+                    aNewFormat[nI + 1] = 'y';
                     aNewFormat.insert(nI + 2, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("yy")));
                     nLen+=2;
                     nI+=3;
@@ -317,7 +317,7 @@ bool lcl_IsNotAM(::rtl::OUString& rFmt, sal_Int32 nPos)
             {
                 // MM We have to escape '/' in case it's used as a char
                 //todo: this cannot be the right way to replace a part of the string!
-                aNewFormat.setCharAt( nI, '\\' );
+                aNewFormat[nI] = '\\';
                 aNewFormat.insert(nI + 1, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/")));
                 nI++;
                 nLen++;
-- 
1.7.4.4


Context


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.