1*1f882ec4SArmin Le Grand /************************************************************** 2*1f882ec4SArmin Le Grand * 3*1f882ec4SArmin Le Grand * Licensed to the Apache Software Foundation (ASF) under one 4*1f882ec4SArmin Le Grand * or more contributor license agreements. See the NOTICE file 5*1f882ec4SArmin Le Grand * distributed with this work for additional information 6*1f882ec4SArmin Le Grand * regarding copyright ownership. The ASF licenses this file 7*1f882ec4SArmin Le Grand * to you under the Apache License, Version 2.0 (the 8*1f882ec4SArmin Le Grand * "License"); you may not use this file except in compliance 9*1f882ec4SArmin Le Grand * with the License. You may obtain a copy of the License at 10*1f882ec4SArmin Le Grand * 11*1f882ec4SArmin Le Grand * http://www.apache.org/licenses/LICENSE-2.0 12*1f882ec4SArmin Le Grand * 13*1f882ec4SArmin Le Grand * Unless required by applicable law or agreed to in writing, 14*1f882ec4SArmin Le Grand * software distributed under the License is distributed on an 15*1f882ec4SArmin Le Grand * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*1f882ec4SArmin Le Grand * KIND, either express or implied. See the License for the 17*1f882ec4SArmin Le Grand * specific language governing permissions and limitations 18*1f882ec4SArmin Le Grand * under the License. 19*1f882ec4SArmin Le Grand * 20*1f882ec4SArmin Le Grand *************************************************************/ 21*1f882ec4SArmin Le Grand 22*1f882ec4SArmin Le Grand // MARKER(update_precomp.py): autogen include statement, do not remove 23*1f882ec4SArmin Le Grand #include "precompiled_basegfx.hxx" 24*1f882ec4SArmin Le Grand 25*1f882ec4SArmin Le Grand #include <stringconversiontools.hxx> 26*1f882ec4SArmin Le Grand #include <rtl/math.hxx> 27*1f882ec4SArmin Le Grand 28*1f882ec4SArmin Le Grand namespace basegfx 29*1f882ec4SArmin Le Grand { 30*1f882ec4SArmin Le Grand namespace internal 31*1f882ec4SArmin Le Grand { lcl_skipSpaces(sal_Int32 & io_rPos,const::rtl::OUString & rStr,const sal_Int32 nLen)32*1f882ec4SArmin Le Grand void lcl_skipSpaces(sal_Int32& io_rPos, 33*1f882ec4SArmin Le Grand const ::rtl::OUString& rStr, 34*1f882ec4SArmin Le Grand const sal_Int32 nLen) 35*1f882ec4SArmin Le Grand { 36*1f882ec4SArmin Le Grand while( io_rPos < nLen && 37*1f882ec4SArmin Le Grand sal_Unicode(' ') == rStr[io_rPos] ) 38*1f882ec4SArmin Le Grand { 39*1f882ec4SArmin Le Grand ++io_rPos; 40*1f882ec4SArmin Le Grand } 41*1f882ec4SArmin Le Grand } 42*1f882ec4SArmin Le Grand lcl_skipSpacesAndCommas(sal_Int32 & io_rPos,const::rtl::OUString & rStr,const sal_Int32 nLen)43*1f882ec4SArmin Le Grand void lcl_skipSpacesAndCommas(sal_Int32& io_rPos, 44*1f882ec4SArmin Le Grand const ::rtl::OUString& rStr, 45*1f882ec4SArmin Le Grand const sal_Int32 nLen) 46*1f882ec4SArmin Le Grand { 47*1f882ec4SArmin Le Grand while(io_rPos < nLen 48*1f882ec4SArmin Le Grand && (sal_Unicode(' ') == rStr[io_rPos] || sal_Unicode(',') == rStr[io_rPos])) 49*1f882ec4SArmin Le Grand { 50*1f882ec4SArmin Le Grand ++io_rPos; 51*1f882ec4SArmin Le Grand } 52*1f882ec4SArmin Le Grand } 53*1f882ec4SArmin Le Grand lcl_getDoubleChar(double & o_fRetval,sal_Int32 & io_rPos,const::rtl::OUString & rStr)54*1f882ec4SArmin Le Grand bool lcl_getDoubleChar(double& o_fRetval, 55*1f882ec4SArmin Le Grand sal_Int32& io_rPos, 56*1f882ec4SArmin Le Grand const ::rtl::OUString& rStr) 57*1f882ec4SArmin Le Grand { 58*1f882ec4SArmin Le Grand sal_Unicode aChar( rStr[io_rPos] ); 59*1f882ec4SArmin Le Grand ::rtl::OUStringBuffer sNumberString; 60*1f882ec4SArmin Le Grand 61*1f882ec4SArmin Le Grand if(sal_Unicode('+') == aChar || sal_Unicode('-') == aChar) 62*1f882ec4SArmin Le Grand { 63*1f882ec4SArmin Le Grand sNumberString.append(rStr[io_rPos]); 64*1f882ec4SArmin Le Grand aChar = rStr[++io_rPos]; 65*1f882ec4SArmin Le Grand } 66*1f882ec4SArmin Le Grand 67*1f882ec4SArmin Le Grand while((sal_Unicode('0') <= aChar && sal_Unicode('9') >= aChar) 68*1f882ec4SArmin Le Grand || sal_Unicode('.') == aChar) 69*1f882ec4SArmin Le Grand { 70*1f882ec4SArmin Le Grand sNumberString.append(rStr[io_rPos]); 71*1f882ec4SArmin Le Grand aChar = rStr[++io_rPos]; 72*1f882ec4SArmin Le Grand } 73*1f882ec4SArmin Le Grand 74*1f882ec4SArmin Le Grand if(sal_Unicode('e') == aChar || sal_Unicode('E') == aChar) 75*1f882ec4SArmin Le Grand { 76*1f882ec4SArmin Le Grand sNumberString.append(rStr[io_rPos]); 77*1f882ec4SArmin Le Grand aChar = rStr[++io_rPos]; 78*1f882ec4SArmin Le Grand 79*1f882ec4SArmin Le Grand if(sal_Unicode('+') == aChar || sal_Unicode('-') == aChar) 80*1f882ec4SArmin Le Grand { 81*1f882ec4SArmin Le Grand sNumberString.append(rStr[io_rPos]); 82*1f882ec4SArmin Le Grand aChar = rStr[++io_rPos]; 83*1f882ec4SArmin Le Grand } 84*1f882ec4SArmin Le Grand 85*1f882ec4SArmin Le Grand while(sal_Unicode('0') <= aChar && sal_Unicode('9') >= aChar) 86*1f882ec4SArmin Le Grand { 87*1f882ec4SArmin Le Grand sNumberString.append(rStr[io_rPos]); 88*1f882ec4SArmin Le Grand aChar = rStr[++io_rPos]; 89*1f882ec4SArmin Le Grand } 90*1f882ec4SArmin Le Grand } 91*1f882ec4SArmin Le Grand 92*1f882ec4SArmin Le Grand if(sNumberString.getLength()) 93*1f882ec4SArmin Le Grand { 94*1f882ec4SArmin Le Grand rtl_math_ConversionStatus eStatus; 95*1f882ec4SArmin Le Grand o_fRetval = ::rtl::math::stringToDouble( sNumberString.makeStringAndClear(), 96*1f882ec4SArmin Le Grand (sal_Unicode)('.'), 97*1f882ec4SArmin Le Grand (sal_Unicode)(','), 98*1f882ec4SArmin Le Grand &eStatus, 99*1f882ec4SArmin Le Grand NULL ); 100*1f882ec4SArmin Le Grand return ( eStatus == rtl_math_ConversionStatus_Ok ); 101*1f882ec4SArmin Le Grand } 102*1f882ec4SArmin Le Grand 103*1f882ec4SArmin Le Grand return false; 104*1f882ec4SArmin Le Grand } 105*1f882ec4SArmin Le Grand lcl_importDoubleAndSpaces(double & o_fRetval,sal_Int32 & io_rPos,const::rtl::OUString & rStr,const sal_Int32 nLen)106*1f882ec4SArmin Le Grand bool lcl_importDoubleAndSpaces( double& o_fRetval, 107*1f882ec4SArmin Le Grand sal_Int32& io_rPos, 108*1f882ec4SArmin Le Grand const ::rtl::OUString& rStr, 109*1f882ec4SArmin Le Grand const sal_Int32 nLen ) 110*1f882ec4SArmin Le Grand { 111*1f882ec4SArmin Le Grand if( !lcl_getDoubleChar(o_fRetval, io_rPos, rStr) ) 112*1f882ec4SArmin Le Grand return false; 113*1f882ec4SArmin Le Grand 114*1f882ec4SArmin Le Grand lcl_skipSpacesAndCommas(io_rPos, rStr, nLen); 115*1f882ec4SArmin Le Grand 116*1f882ec4SArmin Le Grand return true; 117*1f882ec4SArmin Le Grand } 118*1f882ec4SArmin Le Grand lcl_importNumberAndSpaces(sal_Int32 & o_nRetval,sal_Int32 & io_rPos,const::rtl::OUString & rStr,const sal_Int32 nLen)119*1f882ec4SArmin Le Grand bool lcl_importNumberAndSpaces(sal_Int32& o_nRetval, 120*1f882ec4SArmin Le Grand sal_Int32& io_rPos, 121*1f882ec4SArmin Le Grand const ::rtl::OUString& rStr, 122*1f882ec4SArmin Le Grand const sal_Int32 nLen) 123*1f882ec4SArmin Le Grand { 124*1f882ec4SArmin Le Grand sal_Unicode aChar( rStr[io_rPos] ); 125*1f882ec4SArmin Le Grand ::rtl::OUStringBuffer sNumberString; 126*1f882ec4SArmin Le Grand 127*1f882ec4SArmin Le Grand if(sal_Unicode('+') == aChar || sal_Unicode('-') == aChar) 128*1f882ec4SArmin Le Grand { 129*1f882ec4SArmin Le Grand sNumberString.append(rStr[io_rPos]); 130*1f882ec4SArmin Le Grand aChar = rStr[++io_rPos]; 131*1f882ec4SArmin Le Grand } 132*1f882ec4SArmin Le Grand 133*1f882ec4SArmin Le Grand while(sal_Unicode('0') <= aChar && sal_Unicode('9') >= aChar) 134*1f882ec4SArmin Le Grand { 135*1f882ec4SArmin Le Grand sNumberString.append(rStr[io_rPos]); 136*1f882ec4SArmin Le Grand aChar = rStr[++io_rPos]; 137*1f882ec4SArmin Le Grand } 138*1f882ec4SArmin Le Grand 139*1f882ec4SArmin Le Grand if(sNumberString.getLength()) 140*1f882ec4SArmin Le Grand { 141*1f882ec4SArmin Le Grand o_nRetval = sNumberString.makeStringAndClear().toInt32(); 142*1f882ec4SArmin Le Grand lcl_skipSpacesAndCommas(io_rPos, rStr, nLen); 143*1f882ec4SArmin Le Grand 144*1f882ec4SArmin Le Grand return true; 145*1f882ec4SArmin Le Grand } 146*1f882ec4SArmin Le Grand 147*1f882ec4SArmin Le Grand return false; 148*1f882ec4SArmin Le Grand } 149*1f882ec4SArmin Le Grand lcl_skipNumber(sal_Int32 & io_rPos,const::rtl::OUString & rStr,const sal_Int32 nLen)150*1f882ec4SArmin Le Grand void lcl_skipNumber(sal_Int32& io_rPos, 151*1f882ec4SArmin Le Grand const ::rtl::OUString& rStr, 152*1f882ec4SArmin Le Grand const sal_Int32 nLen) 153*1f882ec4SArmin Le Grand { 154*1f882ec4SArmin Le Grand bool bSignAllowed(true); 155*1f882ec4SArmin Le Grand 156*1f882ec4SArmin Le Grand while(io_rPos < nLen && lcl_isOnNumberChar(rStr, io_rPos, bSignAllowed)) 157*1f882ec4SArmin Le Grand { 158*1f882ec4SArmin Le Grand bSignAllowed = false; 159*1f882ec4SArmin Le Grand ++io_rPos; 160*1f882ec4SArmin Le Grand } 161*1f882ec4SArmin Le Grand } 162*1f882ec4SArmin Le Grand lcl_skipDouble(sal_Int32 & io_rPos,const::rtl::OUString & rStr)163*1f882ec4SArmin Le Grand void lcl_skipDouble(sal_Int32& io_rPos, 164*1f882ec4SArmin Le Grand const ::rtl::OUString& rStr) 165*1f882ec4SArmin Le Grand { 166*1f882ec4SArmin Le Grand sal_Unicode aChar( rStr[io_rPos] ); 167*1f882ec4SArmin Le Grand 168*1f882ec4SArmin Le Grand if(sal_Unicode('+') == aChar || sal_Unicode('-') == aChar) 169*1f882ec4SArmin Le Grand aChar = rStr[++io_rPos]; 170*1f882ec4SArmin Le Grand 171*1f882ec4SArmin Le Grand while((sal_Unicode('0') <= aChar && sal_Unicode('9') >= aChar) 172*1f882ec4SArmin Le Grand || sal_Unicode('.') == aChar) 173*1f882ec4SArmin Le Grand { 174*1f882ec4SArmin Le Grand aChar = rStr[++io_rPos]; 175*1f882ec4SArmin Le Grand } 176*1f882ec4SArmin Le Grand 177*1f882ec4SArmin Le Grand if(sal_Unicode('e') == aChar || sal_Unicode('E') == aChar) 178*1f882ec4SArmin Le Grand { 179*1f882ec4SArmin Le Grand aChar = rStr[++io_rPos]; 180*1f882ec4SArmin Le Grand 181*1f882ec4SArmin Le Grand if(sal_Unicode('+') == aChar || sal_Unicode('-') == aChar) 182*1f882ec4SArmin Le Grand aChar = rStr[++io_rPos]; 183*1f882ec4SArmin Le Grand 184*1f882ec4SArmin Le Grand while(sal_Unicode('0') <= aChar && sal_Unicode('9') >= aChar) 185*1f882ec4SArmin Le Grand { 186*1f882ec4SArmin Le Grand aChar = rStr[++io_rPos]; 187*1f882ec4SArmin Le Grand } 188*1f882ec4SArmin Le Grand } 189*1f882ec4SArmin Le Grand } 190*1f882ec4SArmin Le Grand lcl_putNumberCharWithSpace(::rtl::OUStringBuffer & rStr,double fValue,double fOldValue,bool bUseRelativeCoordinates)191*1f882ec4SArmin Le Grand void lcl_putNumberCharWithSpace( ::rtl::OUStringBuffer& rStr, 192*1f882ec4SArmin Le Grand double fValue, 193*1f882ec4SArmin Le Grand double fOldValue, 194*1f882ec4SArmin Le Grand bool bUseRelativeCoordinates ) 195*1f882ec4SArmin Le Grand { 196*1f882ec4SArmin Le Grand if( bUseRelativeCoordinates ) 197*1f882ec4SArmin Le Grand fValue -= fOldValue; 198*1f882ec4SArmin Le Grand 199*1f882ec4SArmin Le Grand const sal_Int32 aLen( rStr.getLength() ); 200*1f882ec4SArmin Le Grand if(aLen) 201*1f882ec4SArmin Le Grand { 202*1f882ec4SArmin Le Grand if( lcl_isOnNumberChar(rStr.charAt(aLen - 1), false) && 203*1f882ec4SArmin Le Grand fValue >= 0.0 ) 204*1f882ec4SArmin Le Grand { 205*1f882ec4SArmin Le Grand rStr.append( sal_Unicode(' ') ); 206*1f882ec4SArmin Le Grand } 207*1f882ec4SArmin Le Grand } 208*1f882ec4SArmin Le Grand 209*1f882ec4SArmin Le Grand lcl_putNumberChar(rStr, fValue); 210*1f882ec4SArmin Le Grand } 211*1f882ec4SArmin Le Grand } // namespace internal 212*1f882ec4SArmin Le Grand } 213*1f882ec4SArmin Le Grand 214*1f882ec4SArmin Le Grand // eof 215