[Libreoffice-commits] core.git: sw/source
Matteo Casalin
matteo.casalin at yahoo.com
Fri Feb 6 14:28:24 PST 2015
sw/source/filter/html/parcss1.cxx | 36 +++++++++---------------------------
1 file changed, 9 insertions(+), 27 deletions(-)
New commits:
commit 78f6e6f7cc9a30138330ee1b4041480b6f2bbb25
Author: Matteo Casalin <matteo.casalin at yahoo.com>
Date: Sun Jan 4 11:18:39 2015 +0100
Simplify CSS1Expression::GetColor for CSS1_RGB case
Relies on toInt32 features:
* Skip control characters at the beginning of the token
* Stop conversion at first non-digit character
Also avoid conversion of negative values to 255, due to downcast to
unsigned 16-bits value
Change-Id: I2029e35dd779220bd3fb74d5173b1482b571f76c
Reviewed-on: https://gerrit.libreoffice.org/13730
Tested-by: Michael Stahl <mstahl at redhat.com>
Reviewed-by: Michael Stahl <mstahl at redhat.com>
diff --git a/sw/source/filter/html/parcss1.cxx b/sw/source/filter/html/parcss1.cxx
index e20424c..4c3767a 100644
--- a/sw/source/filter/html/parcss1.cxx
+++ b/sw/source/filter/html/parcss1.cxx
@@ -1276,34 +1276,17 @@ bool CSS1Expression::GetColor( Color &rColor ) const
break;
}
- OUString aColorStr(aValue.copy(4, aValue.getLength() - 5));
-
- sal_Int32 nPos = 0;
- int nCol = 0;
-
- while( nCol < 3 && nPos < aColorStr.getLength() )
+ sal_Int32 nPos = 4; // start after "rgb("
+ for ( int nCol = 0; nCol < 3 && nPos > 0; ++nCol )
{
- sal_Unicode c;
- while( nPos < aColorStr.getLength() &&
- ((c=aColorStr[nPos]) == ' ' || c == '\t' ||
- c == '\n' || c== '\r' ) )
- nPos++;
-
- sal_Int32 nEnd = aColorStr.indexOf( ',', nPos );
- OUString aNumber;
- if( nEnd == -1 )
- {
- aNumber = aColorStr.copy(nPos);
- nPos = aColorStr.getLength();
- }
- else
+ const OUString aNumber = aValue.getToken(0, ',', nPos);
+
+ sal_Int32 nNumber = aNumber.toInt32();
+ if( nNumber<0 )
{
- aNumber = aColorStr.copy( nPos, nEnd-nPos );
- nPos = nEnd+1;
+ nNumber = 0;
}
-
- sal_uInt16 nNumber = (sal_uInt16)aNumber.toInt32();
- if( aNumber.indexOf('%') >= 0 )
+ else if( aNumber.indexOf('%') >= 0 )
{
if( nNumber > 100 )
nNumber = 100;
@@ -1313,8 +1296,7 @@ bool CSS1Expression::GetColor( Color &rColor ) const
else if( nNumber > 255 )
nNumber = 255;
- aColors[nCol] = (sal_uInt8)nNumber;
- nCol ++;
+ aColors[nCol] = static_cast<sal_uInt8>(nNumber);
}
rColor.SetRed( aColors[0] );
More information about the Libreoffice-commits
mailing list