1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 #ifndef _PSPRINT_STRHELPER_HXX_ 28 #define _PSPRINT_STRHELPER_HXX_ 29 30 #include "vcl/dllapi.h" 31 32 #include <tools/string.hxx> 33 #include <rtl/math.hxx> 34 35 #include <cstring> 36 37 namespace psp { 38 39 String VCL_DLLPUBLIC GetCommandLineToken( int, const String& ); 40 ByteString VCL_DLLPUBLIC GetCommandLineToken( int, const ByteString& ); 41 // gets one token of a unix command line style string 42 // doublequote, singlequote and singleleftquote protect their respective 43 // contents 44 45 int VCL_DLLPUBLIC GetCommandLineTokenCount( const String& ); 46 int VCL_DLLPUBLIC GetCommandLineTokenCount( const ByteString& ); 47 // returns number of tokens (zero if empty or whitespace only) 48 49 String VCL_DLLPUBLIC WhitespaceToSpace( const String&, sal_Bool bProtect = sal_True ); 50 ByteString VCL_DLLPUBLIC WhitespaceToSpace( const ByteString&, sal_Bool bProtect = sal_True ); 51 // returns a string with multiple adjacent occurences of whitespace 52 // converted to a single space. if bProtect is sal_True (nonzero), then 53 // doublequote, singlequote and singleleftquote protect their respective 54 // contents 55 56 57 // parses the first double in the string; decimal is '.' only 58 inline double VCL_DLLPUBLIC StringToDouble( const String& rStr ) 59 { 60 rtl_math_ConversionStatus eStatus; 61 return rtl::math::stringToDouble( rStr, sal_Unicode('.'), sal_Unicode(0), &eStatus, NULL); 62 } 63 64 inline double VCL_DLLPUBLIC StringToDouble( const ByteString& rStr ) 65 { 66 rtl_math_ConversionStatus eStatus; 67 return rtl::math::stringToDouble( rtl::OStringToOUString( rStr, osl_getThreadTextEncoding() ), sal_Unicode('.'), sal_Unicode(0), &eStatus, NULL); 68 } 69 70 // fills a character buffer with the string representation of a double 71 // the buffer has to be long enough (e.g. 128 bytes) 72 // returns the string len 73 inline int VCL_DLLPUBLIC getValueOfDouble( char* pBuffer, double f, int nPrecision = 0) 74 { 75 rtl::OString aStr( rtl::math::doubleToString( f, rtl_math_StringFormat_G, nPrecision, '.', true ) ); 76 int nLen = aStr.getLength(); 77 std::strncpy( pBuffer, aStr.getStr(), nLen+1 ); // copy string including terminating zero 78 return nLen; 79 } 80 81 } // namespace 82 83 #endif // _PSPRINT_STRHELPER_HXX_ 84