LCOV - code coverage report
Current view: top level - basegfx/source/tools - stringconversiontools.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 51 64 79.7 %
Date: 2014-04-11 Functions: 5 6 83.3 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <stringconversiontools.hxx>
      21             : #include <rtl/math.hxx>
      22             : 
      23             : namespace basegfx
      24             : {
      25             :     namespace internal
      26             :     {
      27       49501 :         void lcl_skipSpaces(sal_Int32&              io_rPos,
      28             :                             const OUString&  rStr,
      29             :                             const sal_Int32         nLen)
      30             :         {
      31      151617 :             while( io_rPos < nLen &&
      32       49727 :                     ' ' == rStr[io_rPos] )
      33             :             {
      34        2888 :                 ++io_rPos;
      35             :             }
      36       49501 :         }
      37             : 
      38      139195 :         void lcl_skipSpacesAndCommas(sal_Int32&             io_rPos,
      39             :                                         const OUString& rStr,
      40             :                                         const sal_Int32         nLen)
      41             :         {
      42      609619 :             while(io_rPos < nLen
      43      235212 :                     && (' ' == rStr[io_rPos] || ',' == rStr[io_rPos]))
      44             :             {
      45       96017 :                 ++io_rPos;
      46             :             }
      47      139195 :         }
      48             : 
      49      139195 :         bool lcl_getDoubleChar(double&                  o_fRetval,
      50             :                                 sal_Int32&              io_rPos,
      51             :                                 const OUString&  rStr)
      52             :         {
      53      139195 :             sal_Unicode aChar( rStr[io_rPos] );
      54      139195 :             OUStringBuffer sNumberString;
      55      139195 :             bool separator_seen=false;
      56             : 
      57      139195 :             if('+' == aChar || '-' == aChar)
      58             :             {
      59       44057 :                 sNumberString.append(rStr[io_rPos]);
      60       44057 :                 aChar = rStr[++io_rPos];
      61             :             }
      62             : 
      63      955263 :             while(('0' <= aChar && '9' >= aChar)
      64      259369 :                      || (!separator_seen && '.' == aChar))
      65             :             {
      66      676873 :                 if ('.' == aChar) separator_seen = true;
      67      676873 :                 sNumberString.append(rStr[io_rPos]);
      68      676873 :                 io_rPos++;
      69      676873 :                 aChar = io_rPos < rStr.getLength() ? rStr[io_rPos] : 0;
      70             :             }
      71             : 
      72      139195 :             if('e' == aChar || 'E' == aChar)
      73             :             {
      74           9 :                 sNumberString.append(rStr[io_rPos]);
      75           9 :                 io_rPos++;
      76           9 :                 aChar = io_rPos < rStr.getLength() ? rStr[io_rPos] : 0;
      77             : 
      78           9 :                 if('+' == aChar || '-' == aChar)
      79             :                 {
      80           9 :                     sNumberString.append(rStr[io_rPos]);
      81           9 :                     io_rPos++;
      82           9 :                     aChar = io_rPos < rStr.getLength() ? rStr[io_rPos] : 0;
      83             :                 }
      84             : 
      85          27 :                 while('0' <= aChar && '9' >= aChar)
      86             :                 {
      87           9 :                     sNumberString.append(rStr[io_rPos]);
      88           9 :                     io_rPos++;
      89           9 :                     aChar = io_rPos < rStr.getLength() ? rStr[io_rPos] : 0;
      90             :                 }
      91             :             }
      92             : 
      93      139195 :             if(sNumberString.getLength())
      94             :             {
      95             :                 rtl_math_ConversionStatus eStatus;
      96             :                 o_fRetval = ::rtl::math::stringToDouble( sNumberString.makeStringAndClear(),
      97             :                                                             '.',
      98             :                                                             ',',
      99             :                                                             &eStatus,
     100      139195 :                                                             NULL );
     101      139195 :                 return ( eStatus == rtl_math_ConversionStatus_Ok );
     102             :             }
     103             : 
     104           0 :             return false;
     105             :         }
     106             : 
     107      139195 :         bool lcl_importDoubleAndSpaces( double&                 o_fRetval,
     108             :                                         sal_Int32&              io_rPos,
     109             :                                         const OUString&  rStr,
     110             :                                         const sal_Int32         nLen )
     111             :         {
     112      139195 :             if( !lcl_getDoubleChar(o_fRetval, io_rPos, rStr) )
     113           0 :                 return false;
     114             : 
     115      139195 :             lcl_skipSpacesAndCommas(io_rPos, rStr, nLen);
     116             : 
     117      139195 :             return true;
     118             :         }
     119             : 
     120           0 :         bool lcl_importFlagAndSpaces(sal_Int32&         o_nRetval,
     121             :                                      sal_Int32&         io_rPos,
     122             :                                      const OUString&    rStr,
     123             :                                      const sal_Int32    nLen)
     124             :         {
     125           0 :             sal_Unicode aChar( rStr[io_rPos] );
     126             : 
     127           0 :             if('0' == aChar)
     128             :             {
     129           0 :                 o_nRetval = 0;
     130           0 :                 ++io_rPos;
     131             :             }
     132           0 :             else if ('1' == aChar)
     133             :             {
     134           0 :                 o_nRetval = 1;
     135           0 :                 ++io_rPos;
     136             :             }
     137             :             else
     138           0 :                 return false;
     139             : 
     140           0 :             lcl_skipSpacesAndCommas(io_rPos, rStr, nLen);
     141             : 
     142           0 :             return true;
     143             :         }
     144             : 
     145        2942 :         void lcl_putNumberCharWithSpace( OUStringBuffer& rStr,
     146             :                                             double              fValue,
     147             :                                             double              fOldValue,
     148             :                                             bool                    bUseRelativeCoordinates )
     149             :         {
     150        2942 :             if( bUseRelativeCoordinates )
     151        2891 :                 fValue -= fOldValue;
     152             : 
     153        2942 :             const sal_Int32 aLen( rStr.getLength() );
     154        2942 :             if(aLen)
     155             :             {
     156        2942 :                 if( lcl_isOnNumberChar(rStr[aLen - 1], false) &&
     157             :                     fValue >= 0.0 )
     158             :                 {
     159        1008 :                     rStr.append( ' ' );
     160             :                 }
     161             :             }
     162             : 
     163        2942 :             lcl_putNumberChar(rStr, fValue);
     164        2942 :         }
     165             : 
     166             :     } // namespace internal
     167             : }
     168             : 
     169             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10