LCOV - code coverage report
Current view: top level - basegfx/source/tools - stringconversiontools.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 64 0.0 %
Date: 2014-04-14 Functions: 0 6 0.0 %
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           0 :         void lcl_skipSpaces(sal_Int32&              io_rPos,
      28             :                             const OUString&  rStr,
      29             :                             const sal_Int32         nLen)
      30             :         {
      31           0 :             while( io_rPos < nLen &&
      32           0 :                     ' ' == rStr[io_rPos] )
      33             :             {
      34           0 :                 ++io_rPos;
      35             :             }
      36           0 :         }
      37             : 
      38           0 :         void lcl_skipSpacesAndCommas(sal_Int32&             io_rPos,
      39             :                                         const OUString& rStr,
      40             :                                         const sal_Int32         nLen)
      41             :         {
      42           0 :             while(io_rPos < nLen
      43           0 :                     && (' ' == rStr[io_rPos] || ',' == rStr[io_rPos]))
      44             :             {
      45           0 :                 ++io_rPos;
      46             :             }
      47           0 :         }
      48             : 
      49           0 :         bool lcl_getDoubleChar(double&                  o_fRetval,
      50             :                                 sal_Int32&              io_rPos,
      51             :                                 const OUString&  rStr)
      52             :         {
      53           0 :             sal_Unicode aChar( rStr[io_rPos] );
      54           0 :             OUStringBuffer sNumberString;
      55           0 :             bool separator_seen=false;
      56             : 
      57           0 :             if('+' == aChar || '-' == aChar)
      58             :             {
      59           0 :                 sNumberString.append(rStr[io_rPos]);
      60           0 :                 aChar = rStr[++io_rPos];
      61             :             }
      62             : 
      63           0 :             while(('0' <= aChar && '9' >= aChar)
      64           0 :                      || (!separator_seen && '.' == aChar))
      65             :             {
      66           0 :                 if ('.' == aChar) separator_seen = true;
      67           0 :                 sNumberString.append(rStr[io_rPos]);
      68           0 :                 io_rPos++;
      69           0 :                 aChar = io_rPos < rStr.getLength() ? rStr[io_rPos] : 0;
      70             :             }
      71             : 
      72           0 :             if('e' == aChar || 'E' == aChar)
      73             :             {
      74           0 :                 sNumberString.append(rStr[io_rPos]);
      75           0 :                 io_rPos++;
      76           0 :                 aChar = io_rPos < rStr.getLength() ? rStr[io_rPos] : 0;
      77             : 
      78           0 :                 if('+' == aChar || '-' == aChar)
      79             :                 {
      80           0 :                     sNumberString.append(rStr[io_rPos]);
      81           0 :                     io_rPos++;
      82           0 :                     aChar = io_rPos < rStr.getLength() ? rStr[io_rPos] : 0;
      83             :                 }
      84             : 
      85           0 :                 while('0' <= aChar && '9' >= aChar)
      86             :                 {
      87           0 :                     sNumberString.append(rStr[io_rPos]);
      88           0 :                     io_rPos++;
      89           0 :                     aChar = io_rPos < rStr.getLength() ? rStr[io_rPos] : 0;
      90             :                 }
      91             :             }
      92             : 
      93           0 :             if(sNumberString.getLength())
      94             :             {
      95             :                 rtl_math_ConversionStatus eStatus;
      96             :                 o_fRetval = ::rtl::math::stringToDouble( sNumberString.makeStringAndClear(),
      97             :                                                             '.',
      98             :                                                             ',',
      99             :                                                             &eStatus,
     100           0 :                                                             NULL );
     101           0 :                 return ( eStatus == rtl_math_ConversionStatus_Ok );
     102             :             }
     103             : 
     104           0 :             return false;
     105             :         }
     106             : 
     107           0 :         bool lcl_importDoubleAndSpaces( double&                 o_fRetval,
     108             :                                         sal_Int32&              io_rPos,
     109             :                                         const OUString&  rStr,
     110             :                                         const sal_Int32         nLen )
     111             :         {
     112           0 :             if( !lcl_getDoubleChar(o_fRetval, io_rPos, rStr) )
     113           0 :                 return false;
     114             : 
     115           0 :             lcl_skipSpacesAndCommas(io_rPos, rStr, nLen);
     116             : 
     117           0 :             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           0 :         void lcl_putNumberCharWithSpace( OUStringBuffer& rStr,
     146             :                                             double              fValue,
     147             :                                             double              fOldValue,
     148             :                                             bool                    bUseRelativeCoordinates )
     149             :         {
     150           0 :             if( bUseRelativeCoordinates )
     151           0 :                 fValue -= fOldValue;
     152             : 
     153           0 :             const sal_Int32 aLen( rStr.getLength() );
     154           0 :             if(aLen)
     155             :             {
     156           0 :                 if( lcl_isOnNumberChar(rStr[aLen - 1], false) &&
     157             :                     fValue >= 0.0 )
     158             :                 {
     159           0 :                     rStr.append( ' ' );
     160             :                 }
     161             :             }
     162             : 
     163           0 :             lcl_putNumberChar(rStr, fValue);
     164           0 :         }
     165             : 
     166             :     } // namespace internal
     167             : }
     168             : 
     169             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10