xref: /aoo41x/main/vcl/inc/vcl/strhelper.hxx (revision 0d63794c)
1*0d63794cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*0d63794cSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*0d63794cSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*0d63794cSAndrew Rist  * distributed with this work for additional information
6*0d63794cSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*0d63794cSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*0d63794cSAndrew Rist  * "License"); you may not use this file except in compliance
9*0d63794cSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*0d63794cSAndrew Rist  *
11*0d63794cSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*0d63794cSAndrew Rist  *
13*0d63794cSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*0d63794cSAndrew Rist  * software distributed under the License is distributed on an
15*0d63794cSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*0d63794cSAndrew Rist  * KIND, either express or implied.  See the License for the
17*0d63794cSAndrew Rist  * specific language governing permissions and limitations
18*0d63794cSAndrew Rist  * under the License.
19*0d63794cSAndrew Rist  *
20*0d63794cSAndrew Rist  *************************************************************/
21*0d63794cSAndrew Rist 
22*0d63794cSAndrew Rist 
23cdf0e10cSrcweir #ifndef _PSPRINT_STRHELPER_HXX_
24cdf0e10cSrcweir #define _PSPRINT_STRHELPER_HXX_
25cdf0e10cSrcweir 
26cdf0e10cSrcweir #include "vcl/dllapi.h"
27cdf0e10cSrcweir 
28cdf0e10cSrcweir #include <tools/string.hxx>
29cdf0e10cSrcweir #include <rtl/math.hxx>
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #include <cstring>
32cdf0e10cSrcweir 
33cdf0e10cSrcweir namespace psp {
34cdf0e10cSrcweir 
35cdf0e10cSrcweir String VCL_DLLPUBLIC GetCommandLineToken( int, const String& );
36cdf0e10cSrcweir ByteString VCL_DLLPUBLIC GetCommandLineToken( int, const ByteString& );
37cdf0e10cSrcweir // gets one token of a unix command line style string
38cdf0e10cSrcweir // doublequote, singlequote and singleleftquote protect their respective
39cdf0e10cSrcweir // contents
40cdf0e10cSrcweir 
41cdf0e10cSrcweir int VCL_DLLPUBLIC GetCommandLineTokenCount( const String& );
42cdf0e10cSrcweir int VCL_DLLPUBLIC GetCommandLineTokenCount( const ByteString& );
43cdf0e10cSrcweir // returns number of tokens (zero if empty or whitespace only)
44cdf0e10cSrcweir 
45cdf0e10cSrcweir String VCL_DLLPUBLIC WhitespaceToSpace( const String&, sal_Bool bProtect = sal_True );
46cdf0e10cSrcweir ByteString VCL_DLLPUBLIC WhitespaceToSpace( const ByteString&, sal_Bool bProtect = sal_True );
47cdf0e10cSrcweir // returns a string with multiple adjacent occurences of whitespace
48cdf0e10cSrcweir // converted to a single space. if bProtect is sal_True (nonzero), then
49cdf0e10cSrcweir // doublequote, singlequote and singleleftquote protect their respective
50cdf0e10cSrcweir // contents
51cdf0e10cSrcweir 
52cdf0e10cSrcweir 
53cdf0e10cSrcweir // parses the first double in the string; decimal is '.' only
StringToDouble(const String & rStr)54cdf0e10cSrcweir inline double VCL_DLLPUBLIC StringToDouble( const String& rStr )
55cdf0e10cSrcweir {
56cdf0e10cSrcweir     rtl_math_ConversionStatus eStatus;
57cdf0e10cSrcweir     return rtl::math::stringToDouble( rStr, sal_Unicode('.'), sal_Unicode(0), &eStatus, NULL);
58cdf0e10cSrcweir }
59cdf0e10cSrcweir 
StringToDouble(const ByteString & rStr)60cdf0e10cSrcweir inline double VCL_DLLPUBLIC StringToDouble( const ByteString& rStr )
61cdf0e10cSrcweir {
62cdf0e10cSrcweir     rtl_math_ConversionStatus eStatus;
63cdf0e10cSrcweir     return rtl::math::stringToDouble( rtl::OStringToOUString( rStr, osl_getThreadTextEncoding() ), sal_Unicode('.'), sal_Unicode(0), &eStatus, NULL);
64cdf0e10cSrcweir }
65cdf0e10cSrcweir 
66cdf0e10cSrcweir // fills a character buffer with the string representation of a double
67cdf0e10cSrcweir // the buffer has to be long enough (e.g. 128 bytes)
68cdf0e10cSrcweir // returns the string len
getValueOfDouble(char * pBuffer,double f,int nPrecision=0)69cdf0e10cSrcweir inline int VCL_DLLPUBLIC getValueOfDouble( char* pBuffer, double f, int nPrecision = 0)
70cdf0e10cSrcweir {
71cdf0e10cSrcweir     rtl::OString aStr( rtl::math::doubleToString( f, rtl_math_StringFormat_G, nPrecision, '.', true ) );
72cdf0e10cSrcweir     int nLen = aStr.getLength();
73cdf0e10cSrcweir     std::strncpy( pBuffer, aStr.getStr(), nLen+1 ); // copy string including terminating zero
74cdf0e10cSrcweir     return nLen;
75cdf0e10cSrcweir }
76cdf0e10cSrcweir 
77cdf0e10cSrcweir } // namespace
78cdf0e10cSrcweir 
79cdf0e10cSrcweir #endif // _PSPRINT_STRHELPER_HXX_
80