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


I've attached a revised patch that should fix the pLine issue. The
assignment to pLine is now redundant and all the checks in pLine can
probably be more appropriately expressed in terms of aLine anyway. I'm
not sure how ToUpperAscii affects this patch, do you mind explaining a
little further?

August Sodora
augsod@gmail.com
(201) 280-8138



On Tue, Oct 4, 2011 at 6:27 AM, Caolán McNamara <caolanm@redhat.com> wrote:
On Tue, 2011-10-04 at 10:57 +0200, Jan Holesovsky wrote:
BTW, another horror in the original code is:

ch1 = aSym.ToUpperAscii().GetBuffer()[0];

ie. we convert the entire string to upper case, and then throw all that
away but the first char.

[Byte]String::ToUpperAscii, see tools/source/string/strimp.cxx, modifies
the string it operates on and returns a reference to *this, i.e.

aSym = "hello";
aSym.ToUpperAscii();;
//aSym contains "HELLO" now

I mean, it doesn't return an uppercased copy, but returns itself, which
has been uppercased.

C.


From 21cf5ccc288e6eaead273dd9d54325e250f678f7 Mon Sep 17 00:00:00 2001
From: August Sodora <augsod@gmail.com>
Date: Sun, 2 Oct 2011 19:48:31 -0400
Subject: [PATCH 1/2] String->OUString

---
 basic/source/comp/exprtree.cxx |    2 +-
 basic/source/comp/parser.cxx   |    6 +++---
 basic/source/comp/scanner.cxx  |   37 ++++++++++++++++++++-----------------
 basic/source/comp/token.cxx    |   39 ++++++++++++++++++++++-----------------
 basic/source/inc/expr.hxx      |    2 +-
 basic/source/inc/scanner.hxx   |    4 ++--
 basic/source/inc/token.hxx     |    2 +-
 sal/inc/rtl/ustring.hxx        |    5 +++++
 8 files changed, 55 insertions(+), 42 deletions(-)

diff --git a/basic/source/comp/exprtree.cxx b/basic/source/comp/exprtree.cxx
index 1c7ec1b..2acf90cc 100644
--- a/basic/source/comp/exprtree.cxx
+++ b/basic/source/comp/exprtree.cxx
@@ -208,7 +208,7 @@ SbiExprNode* SbiExpression::Term( const KeywordSymbolInfo* pKeywordSymbolInfo )
     SbiToken eTok = (pKeywordSymbolInfo == NULL) ? pParser->Next() : pKeywordSymbolInfo->m_eTok;
     // memorize the parsing's begin
     pParser->LockColumn();
-    String aSym( (pKeywordSymbolInfo == NULL) ? pParser->GetSym() : 
pKeywordSymbolInfo->m_aKeywordSymbol );
+    ::rtl::OUString aSym( (pKeywordSymbolInfo == NULL) ? pParser->GetSym() : 
pKeywordSymbolInfo->m_aKeywordSymbol );
     SbxDataType eType = (pKeywordSymbolInfo == NULL) ? pParser->GetType() : 
pKeywordSymbolInfo->m_eSbxDataType;
     SbiParameters* pPar = NULL;
     SbiExprListVector* pvMoreParLcl = NULL;
diff --git a/basic/source/comp/parser.cxx b/basic/source/comp/parser.cxx
index b8fb78f..3b09dc5 100644
--- a/basic/source/comp/parser.cxx
+++ b/basic/source/comp/parser.cxx
@@ -676,7 +676,7 @@ void SbiParser::DefXXX()
     while( !bAbort )
     {
         if( Next() != SYMBOL ) break;
-        ch1 = aSym.ToUpperAscii().GetBuffer()[0];
+        ch1 = aSym.toAsciiUpperCase().getStr()[0];
         ch2 = 0;
         if( Peek() == MINUS )
         {
@@ -684,7 +684,7 @@ void SbiParser::DefXXX()
             if( Next() != SYMBOL ) Error( SbERR_SYMBOL_EXPECTED );
             else
             {
-                ch2 = aSym.ToUpperAscii().GetBuffer()[0];
+                ch2 = aSym.toAsciiUpperCase().getStr()[0];
                 if( ch2 < ch1 ) Error( SbERR_SYNTAX ), ch2 = 0;
             }
         }
@@ -784,7 +784,7 @@ void SbiParser::Option()
             SbiToken eTok = Next();
             if( eTok == BINARY )
                 bText = sal_False;
-            else if( eTok == SYMBOL && GetSym().EqualsIgnoreCaseAscii("text") )
+            else if( eTok == SYMBOL && 
GetSym().equalsIgnoreAsciiCaseAsciiL(RTL_CONSTASCII_STRINGPARAM("text")) )
                 bText = sal_True;
             else
                 Error( SbERR_EXPECTED, "Text/Binary" );
diff --git a/basic/source/comp/scanner.cxx b/basic/source/comp/scanner.cxx
index 1dec4db..6a6e714 100644
--- a/basic/source/comp/scanner.cxx
+++ b/basic/source/comp/scanner.cxx
@@ -173,7 +173,7 @@ sal_Bool SbiScanner::NextSym()
     bHash = sal_False;
 
     eScanType = SbxVARIANT;
-    aSym.Erase();
+    aSym = ::rtl::OUString();
     bSymbol =
     bNumber = bSpaces = sal_False;
 
@@ -241,7 +241,7 @@ sal_Bool SbiScanner::NextSym()
         aSym = aLine.copy( n, nCol - n );
 
         // Special handling for "go to"
-        if( bCompatible && *pLine && aSym.EqualsIgnoreCaseAscii( "go" ) )
+        if( bCompatible && *pLine && aSym.equalsIgnoreAsciiCaseAsciiL( RTL_CONSTASCII_STRINGPARAM( 
"go" ) ) )
         {
             const sal_Unicode* pTestLine = pLine;
             short nTestCol = nCol;
@@ -256,7 +256,7 @@ sal_Bool SbiScanner::NextSym()
                 String aTestSym = aLine.copy( nTestCol, 2 );
                 if( aTestSym.EqualsIgnoreCaseAscii( "to" ) )
                 {
-                    aSym = String::CreateFromAscii( "goto" );
+                    aSym = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "goto" ) );
                     pLine = pTestLine + 2;
                     nCol = nTestCol + 2;
                 }
@@ -266,10 +266,8 @@ sal_Bool SbiScanner::NextSym()
         // replace closing '_' by space when end of line is following
         // (wrong line continuation otherwise)
         if( !bUsedForHilite && !*pLine && *(pLine-1) == '_' )
-        {
-            aSym.GetBufferAccess();     // #109693 force copy if necessary
             *((sal_Unicode*)(pLine-1)) = ' ';       // cast because of const
-        }
+
         // type recognition?
         // don't test the exclamation mark
         // if there's a symbol behind it
@@ -384,7 +382,9 @@ sal_Bool SbiScanner::NextSym()
                 break;
             default :
                 // treated as an operator
-                pLine--; nCol--; nCol1 = nCol-1; aSym = '&'; return SYMBOL;
+                pLine--; nCol--; nCol1 = nCol-1; 
+                aSym = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("&")); 
+                return SYMBOL;
         }
         bNumber = sal_True;
         long l = 0;
@@ -448,15 +448,17 @@ sal_Bool SbiScanner::NextSym()
         else
             aSym = aLine.copy( n, nCol - n - 1 );
         // get out duplicate string delimiters
-        String s( cSep );
-        s += cSep;
-        sal_uInt16 nIdx = 0;
+        ::rtl::OUString s = ::rtl::OUString::valueOf( static_cast<sal_Unicode>( cSep ) );
+        s += s;
+        sal_Int32 nIdx = 0;
         do
         {
-            nIdx = aSym.Search( s, nIdx );
-            if( nIdx == STRING_NOTFOUND )
+            ::rtl::OUStringBuffer aSymBuf(aSym);
+            nIdx = aSym.indexOf( s, nIdx );
+            if( nIdx < 0 )
                 break;
-            aSym.Erase( nIdx, 1 );
+            aSymBuf.remove( nIdx, 1 );
+            aSym = aSymBuf.makeStringAndClear();
             nIdx++;
         }
         while( true );
@@ -487,10 +489,11 @@ sal_Bool SbiScanner::NextSym()
 PrevLineCommentLbl:
 
     if( bPrevLineExtentsComment || (eScanType != SbxSTRING &&
-        ( aSym.GetBuffer()[0] == '\'' || aSym.EqualsIgnoreCaseAscii( "REM" ) ) ) )
+                                    ( aSym.getStr()[0] == '\'' || 
+                                      aSym.equalsIgnoreAsciiCaseAsciiL( 
RTL_CONSTASCII_STRINGPARAM( "REM" ) ) ) ) )
     {
         bPrevLineExtentsComment = sal_False;
-        aSym = String::CreateFromAscii( "REM" );
+        aSym = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "REM" ));
         sal_uInt16 nLen = String( pLine ).Len();
         if( bCompatible && pLine[ nLen - 1 ] == '_' && pLine[ nLen - 2 ] == ' ' )
             bPrevLineExtentsComment = sal_True;
@@ -505,7 +508,7 @@ eoln:
     {
         pLine = NULL;
         bool bRes = NextSym();
-        if( bVBASupportOn && aSym.GetBuffer()[0] == '.' )
+        if( bVBASupportOn && aSym.getStr()[0] == '.' )
         {
             // object _
             //    .Method
@@ -521,7 +524,7 @@ eoln:
         nLine = nOldLine;
         nCol1 = nOldCol1;
         nCol2 = nOldCol2;
-        aSym = '\n';
+        aSym = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\n"));
         nColLock = 0;
         return sal_True;
     }
diff --git a/basic/source/comp/token.cxx b/basic/source/comp/token.cxx
index 1027d5b..3bf1037 100644
--- a/basic/source/comp/token.cxx
+++ b/basic/source/comp/token.cxx
@@ -281,19 +281,25 @@ SbiToken SbiTokenizer::Peek()
 
 // For decompilation. Numbers and symbols return an empty string.
 
-const String& SbiTokenizer::Symbol( SbiToken t )
+const ::rtl::OUString& SbiTokenizer::Symbol( SbiToken t )
 {
     // character token?
     if( t < FIRSTKWD )
     {
-        aSym = (char) t;
+        aSym = ::rtl::OUString::valueOf(sal::static_int_cast<sal_Unicode>(t));
         return aSym;
     }
     switch( t )
     {
-        case NEG   : aSym = '-'; return aSym;
-        case EOS   : aSym = String::CreateFromAscii( ":/CRLF" ); return aSym;
-        case EOLN  : aSym = String::CreateFromAscii( "CRLF" ); return aSym;
+        case NEG   : 
+            aSym = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("-"));
+            return aSym;
+        case EOS   : 
+            aSym = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(":/CRLF"));
+            return aSym;
+        case EOLN  : 
+            aSym = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("CRLF"));
+            return aSym;
         default: break;
     }
     TokenTable* tp = pTokTable;
@@ -301,12 +307,12 @@ const String& SbiTokenizer::Symbol( SbiToken t )
     {
         if( tp->t == t )
         {
-            aSym = String::CreateFromAscii( tp->s );
+            aSym = ::rtl::OUString::createFromAscii( tp->s );
             return aSym;
         }
     }
-    const sal_Unicode *p = aSym.GetBuffer();
-    if (*p <= ' ') aSym = String::CreateFromAscii( "???" );
+    const sal_Unicode *p = aSym.getStr();
+    if (*p <= ' ') aSym = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("???"));
     return aSym;
 }
 
@@ -337,7 +343,7 @@ SbiToken SbiTokenizer::Next()
         return eCurTok = EOLN;
     }
 
-    if( aSym.GetBuffer()[0] == '\n' )
+    if( aSym.getStr()[0] == '\n' )
     {
         bEos = sal_True; return eCurTok = EOLN;
     }
@@ -350,9 +356,9 @@ SbiToken SbiTokenizer::Next()
         return eCurTok = FIXSTRING;
     // Special cases of characters that are between "Z" and "a". ICompare()
     // evaluates the position of these characters in different ways.
-    else if( aSym.GetBuffer()[0] == '^' )
+    else if( aSym.getStr()[0] == '^' )
         return eCurTok = EXPON;
-    else if( aSym.GetBuffer()[0] == '\\' )
+    else if( aSym.getStr()[0] == '\\' )
         return eCurTok = IDIV;
     else
     {
@@ -367,17 +373,16 @@ SbiToken SbiTokenizer::Next()
         {
             delta = (ub - lb) >> 1;
             tp = &pTokTable[ lb + delta ];
-            StringCompare res = aSym.CompareIgnoreCaseToAscii( tp->s );
+            sal_Int32 res = aSym.compareToIgnoreAsciiCaseAscii( tp->s );
 
-            if( res == COMPARE_EQUAL )
+            if( res == 0 )
                 goto special;
 
-            if( res == COMPARE_LESS )
+            if( res < 0 )
             {
                 if ((ub - lb) == 2) ub = lb;
                 else ub = ub - delta;
             }
-
             else
             {
                 if ((ub -lb) == 2) lb = ub;
@@ -385,7 +390,7 @@ SbiToken SbiTokenizer::Next()
             }
         } while( delta );
         // Symbol? if not >= token
-        sal_Unicode ch = aSym.GetBuffer()[0];
+        sal_Unicode ch = aSym.getStr()[0];
         if( !BasicSimpleCharClass::isAlpha( ch, bCompatible ) && !bSymbol )
             return eCurTok = (SbiToken) (ch & 0x00FF);
         return eCurTok = SYMBOL;
@@ -457,7 +462,7 @@ special:
     if( bCompatible )
     {
         // #129904 Suppress system
-        if( eTok == STOP && aSym.CompareIgnoreCaseToAscii( "system" ) == COMPARE_EQUAL )
+        if( eTok == STOP && aSym.equalsIgnoreAsciiCaseAsciiL( RTL_CONSTASCII_STRINGPARAM( "system" 
) ) )
             eCurTok = SYMBOL;
 
         if( eTok == GET && bStartOfLine )
diff --git a/basic/source/inc/expr.hxx b/basic/source/inc/expr.hxx
index 3cc12b0..0a7d4aa 100644
--- a/basic/source/inc/expr.hxx
+++ b/basic/source/inc/expr.hxx
@@ -55,7 +55,7 @@ struct SbVar {
 
 struct KeywordSymbolInfo
 {
-    String          m_aKeywordSymbol;
+    ::rtl::OUString m_aKeywordSymbol;
     SbxDataType     m_eSbxDataType;
     SbiToken        m_eTok;
 };
diff --git a/basic/source/inc/scanner.hxx b/basic/source/inc/scanner.hxx
index 06447fa..baba425 100644
--- a/basic/source/inc/scanner.hxx
+++ b/basic/source/inc/scanner.hxx
@@ -46,7 +46,7 @@ class SbiScanner
     const sal_Unicode* pLine;
     const sal_Unicode* pSaveLine;
 protected:
-    String aSym;
+    ::rtl::OUString aSym;
     String aError;
     SbxDataType eScanType;
     StarBASIC* pBasic;                  // instance for error callbacks
@@ -96,7 +96,7 @@ public:
     sal_Bool  DoesColonFollow();
 
     sal_Bool NextSym();
-    const String& GetSym()          { return aSym;  }
+    const ::rtl::OUString& GetSym() { return aSym;  }
     SbxDataType GetType()           { return eScanType; }
     double    GetDbl()              { return nVal;  }
 };
diff --git a/basic/source/inc/token.hxx b/basic/source/inc/token.hxx
index 666c8e4..1048176 100644
--- a/basic/source/inc/token.hxx
+++ b/basic/source/inc/token.hxx
@@ -155,7 +155,7 @@ public:
     inline sal_Bool IsEos()             { return bEos; }
 
     void  Push( SbiToken );
-    const String& Symbol( SbiToken );   // reconversion
+    const ::rtl::OUString& Symbol( SbiToken );   // reconversion
 
     SbiToken Peek();                    // read the next token
     SbiToken Next();                    // read a token
diff --git a/sal/inc/rtl/ustring.hxx b/sal/inc/rtl/ustring.hxx
index ed268d9..1587077 100644
--- a/sal/inc/rtl/ustring.hxx
+++ b/sal/inc/rtl/ustring.hxx
@@ -596,6 +596,11 @@ public:
         return rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length, 
asciiStr ) == 0;
     }
 
+    sal_Int32 compareToIgnoreAsciiCaseAscii( const sal_Char * asciiStr ) const SAL_THROW(())
+    {
+        return rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length, 
asciiStr );
+    }
+
     /**
       Perform a ASCII lowercase comparison of two strings.
 
-- 
1.7.4.4


From d22cd12f92584c1627896d0511b88fb676dbae16 Mon Sep 17 00:00:00 2001
From: August Sodora <augsod@gmail.com>
Date: Tue, 4 Oct 2011 15:41:03 -0400
Subject: [PATCH 2/2] Corrected GetBufferAccess issue

---
 basic/source/comp/scanner.cxx |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)

diff --git a/basic/source/comp/scanner.cxx b/basic/source/comp/scanner.cxx
index 6a6e714..eb652e9 100644
--- a/basic/source/comp/scanner.cxx
+++ b/basic/source/comp/scanner.cxx
@@ -265,8 +265,13 @@ sal_Bool SbiScanner::NextSym()
 
         // replace closing '_' by space when end of line is following
         // (wrong line continuation otherwise)
-        if( !bUsedForHilite && !*pLine && *(pLine-1) == '_' )
+        if( !bUsedForHilite && nCol == aLine.getLength() && aLine.getStr()[nCol - 1] == '_' )
+        {
             *((sal_Unicode*)(pLine-1)) = ' ';       // cast because of const
+            ::rtl::OUStringBuffer aLineBuf(aLine);
+            aLineBuf.setCharAt(nCol - 1, ' ');
+            aLine = aLineBuf.makeStringAndClear();
+        }
 
         // type recognition?
         // don't test the exclamation mark
-- 
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.