diff options
author | Matteo Casalin <matteo.casalin@yahoo.com> | 2015-01-04 11:18:39 +0100 |
---|---|---|
committer | Michael Stahl <mstahl@redhat.com> | 2015-02-06 22:27:58 +0000 |
commit | 78f6e6f7cc9a30138330ee1b4041480b6f2bbb25 (patch) | |
tree | 096a4adf7a39d2b815bdca5b2a9947a6fb2ab182 /sw/source/filter | |
parent | 4f7a1f5b9499d5fbeff413a4914283c2bfe7c2d9 (diff) |
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@redhat.com>
Reviewed-by: Michael Stahl <mstahl@redhat.com>
Diffstat (limited to 'sw/source/filter')
-rw-r--r-- | sw/source/filter/html/parcss1.cxx | 36 |
1 files changed, 9 insertions, 27 deletions
diff --git a/sw/source/filter/html/parcss1.cxx b/sw/source/filter/html/parcss1.cxx index e20424c36d60..4c3767ac8767 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] ); |