summaryrefslogtreecommitdiff
path: root/svl
diff options
context:
space:
mode:
authorNorbert Thiebaud <nthiebaud@gmail.com>2012-11-05 01:31:49 -0600
committerNorbert Thiebaud <nthiebaud@gmail.com>2012-11-18 19:57:21 -0600
commitc77cebdf33b5fde38879233ee8c6fb6390bfcbb8 (patch)
tree5d66c6be03b67c2ec4885f329ca7ee0f61553946 /svl
parent52c492ca729295ab53b110edf525a3eed25872f7 (diff)
svl: convert GetQuoteEnd to OUString
Change-Id: I79bd0aecb98b7b47ee892ed4ce1b53abcd09ff44
Diffstat (limited to 'svl')
-rw-r--r--svl/inc/svl/zformat.hxx7
-rw-r--r--svl/source/numbers/zformat.cxx86
-rw-r--r--svl/source/numbers/zforscan.cxx6
3 files changed, 65 insertions, 34 deletions
diff --git a/svl/inc/svl/zformat.hxx b/svl/inc/svl/zformat.hxx
index ea15bcf9d4a8..2fbadcbfee93 100644
--- a/svl/inc/svl/zformat.hxx
+++ b/svl/inc/svl/zformat.hxx
@@ -375,9 +375,10 @@ public:
Uses <method>IsInQuote</method> internally, so you don't have to call
that prior to a call of this method.
*/
- static xub_StrLen GetQuoteEnd( const String& rString, xub_StrLen nPos,
- sal_Unicode cQuote = '"',
- sal_Unicode cEscIn = '\0', sal_Unicode cEscOut = '\\' );
+ static sal_Int32 GetQuoteEnd( const OUString& rString, sal_Int32 nPos,
+ sal_Unicode cQuote = '"',
+ sal_Unicode cEscIn = '\0',
+ sal_Unicode cEscOut = '\\' );
void SetComment( const OUString& rStr )
{ sComment = rStr; }
diff --git a/svl/source/numbers/zformat.cxx b/svl/source/numbers/zformat.cxx
index 2b0fd8e9f2bf..cecd893022b3 100644
--- a/svl/source/numbers/zformat.cxx
+++ b/svl/source/numbers/zformat.cxx
@@ -1866,48 +1866,69 @@ bool SvNumberformat::GetNewCurrencySymbol( OUString& rSymbol,
String SvNumberformat::StripNewCurrencyDelimiters( const String& rStr,
bool bQuoteSymbol )
{
- String aTmp;
- xub_StrLen nStartPos, nPos, nLen;
- nLen = rStr.Len();
+ OUString aTmp;
+ OUString aSource(rStr);
+ sal_Int32 nStartPos, nPos, nLen;
+ nLen = aSource.getLength();
nStartPos = 0;
- while ( (nPos = rStr.SearchAscii( "[$", nStartPos )) != STRING_NOTFOUND )
+ while ( (nPos = aSource.indexOf( "[$", nStartPos )) >= 0 )
{
- xub_StrLen nEnd;
- if ( (nEnd = GetQuoteEnd( rStr, nPos )) < nLen )
+ sal_Int32 nEnd;
+ if ( (nEnd = GetQuoteEnd( aSource, nPos )) >= 0 )
{
- aTmp += rStr.Copy( nStartPos, ++nEnd - nStartPos );
+ aTmp += aSource.copy( nStartPos, ++nEnd - nStartPos );
nStartPos = nEnd;
}
else
{
- aTmp += rStr.Copy( nStartPos, nPos - nStartPos );
+ aTmp += aSource.copy( nStartPos, nPos - nStartPos );
nStartPos = nPos + 2;
- xub_StrLen nDash;
+ sal_Int32 nDash;
nEnd = nStartPos - 1;
do
{
- nDash = rStr.Search( '-', ++nEnd );
- } while ( (nEnd = GetQuoteEnd( rStr, nDash )) < nLen );
- xub_StrLen nClose;
+ nDash = aSource.indexOf( '-', ++nEnd );
+ }
+ while ( (nEnd = GetQuoteEnd( aSource, nDash )) >= 0 );
+ sal_Int32 nClose;
nEnd = nStartPos - 1;
do
{
- nClose = rStr.Search( ']', ++nEnd );
- } while ( (nEnd = GetQuoteEnd( rStr, nClose )) < nLen );
- nPos = ( nDash < nClose ? nDash : nClose );
- if ( !bQuoteSymbol || rStr.GetChar( nStartPos ) == '"' )
- aTmp += rStr.Copy( nStartPos, nPos - nStartPos );
+ nClose = aSource.indexOf( ']', ++nEnd );
+ }
+ while ( (nEnd = GetQuoteEnd( aSource, nClose )) >= 0 );
+
+ if(nClose < 0)
+ {
+ /* there should always be a closing ]
+ * but the old String class would have hidden
+ * that. so be conservative too
+ */
+ nClose = nLen;
+ }
+
+ nPos = nClose;
+ if(nDash >= 0 && nDash < nClose)
+ {
+ nPos = nDash;
+ }
+ if ( !bQuoteSymbol || aSource[ nStartPos ] == '"' )
+ {
+ aTmp += aSource.copy( nStartPos, nPos - nStartPos );
+ }
else
{
- aTmp += '"';
- aTmp += rStr.Copy( nStartPos, nPos - nStartPos );
- aTmp += '"';
+ aTmp += "\"";
+ aTmp += aSource.copy( nStartPos, nPos - nStartPos );
+ aTmp += "\"";
}
nStartPos = nClose + 1;
}
}
if ( nLen > nStartPos )
- aTmp += rStr.Copy( nStartPos, nLen - nStartPos );
+ {
+ aTmp += aSource.copy( nStartPos, nLen - nStartPos );
+ }
return aTmp;
}
@@ -4858,25 +4879,32 @@ bool SvNumberformat::IsInQuote( const String& rStr, xub_StrLen nPos,
}
// static
-xub_StrLen SvNumberformat::GetQuoteEnd( const String& rStr, xub_StrLen nPos,
- sal_Unicode cQuote, sal_Unicode cEscIn, sal_Unicode cEscOut )
+sal_Int32 SvNumberformat::GetQuoteEnd( const OUString& rStr, sal_Int32 nPos,
+ sal_Unicode cQuote, sal_Unicode cEscIn,
+ sal_Unicode cEscOut )
{
- xub_StrLen nLen = rStr.Len();
+ sal_Int32 nLen = rStr.getLength();
if ( nPos >= nLen )
- return STRING_NOTFOUND;
+ {
+ return -1;
+ }
if ( !IsInQuote( rStr, nPos, cQuote, cEscIn, cEscOut ) )
{
- if ( rStr.GetChar( nPos ) == cQuote )
+ if ( rStr[ nPos ] == cQuote )
+ {
return nPos; // schliessendes cQuote
- return STRING_NOTFOUND;
+ }
+ return -1;
}
- register const sal_Unicode* p0 = rStr.GetBuffer();
+ register const sal_Unicode* p0 = rStr.getStr();
register const sal_Unicode* p = p0 + nPos;
register const sal_Unicode* p1 = p0 + nLen;
while ( p < p1 )
{
if ( *p == cQuote && p > p0 && *(p-1) != cEscIn )
- return sal::static_int_cast< xub_StrLen >(p - p0);
+ {
+ return sal::static_int_cast< sal_Int32 >(p - p0);
+ }
p++;
}
return nLen; // String Ende
diff --git a/svl/source/numbers/zforscan.cxx b/svl/source/numbers/zforscan.cxx
index b3a042664437..eb9921c0b9f6 100644
--- a/svl/source/numbers/zforscan.cxx
+++ b/svl/source/numbers/zforscan.cxx
@@ -874,8 +874,8 @@ xub_StrLen ImpSvNumberformatScan::Symbol_Division(const String& rString)
if (nCPos != STRING_NOTFOUND)
{
// in Quotes?
- xub_StrLen nQ = SvNumberformat::GetQuoteEnd( sString, nCPos );
- if ( nQ == STRING_NOTFOUND )
+ sal_Int32 nQ = SvNumberformat::GetQuoteEnd( sString, nCPos );
+ if ( nQ < 0 )
{
sal_Unicode c;
if ( nCPos == 0 ||
@@ -889,7 +889,9 @@ xub_StrLen ImpSvNumberformatScan::Symbol_Division(const String& rString)
nCPos++; // weitersuchen
}
else
+ {
nCPos = nQ + 1; // weitersuchen
+ }
}
}
nAnzStrings = 0;