update credits
[LibreOffice.git] / include / vcl / strhelper.hxx
blob0d0949a3515feb994d0d1d893c011c34c5cb8c30
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #ifndef _PSPRINT_STRHELPER_HXX_
20 #define _PSPRINT_STRHELPER_HXX_
22 #include "vcl/dllapi.h"
24 #include <tools/string.hxx>
25 #include <rtl/math.hxx>
27 #include <cstring>
29 namespace psp
31 VCL_DLLPUBLIC String GetCommandLineToken( int, const String& );
32 VCL_DLLPUBLIC OString GetCommandLineToken(int, const OString&);
33 // gets one token of a unix command line style string
34 // doublequote, singlequote and singleleftquote protect their respective
35 // contents
37 VCL_DLLPUBLIC int GetCommandLineTokenCount(const OUString&);
38 // returns number of tokens (zero if empty or whitespace only)
40 VCL_DLLPUBLIC String WhitespaceToSpace( const String&, sal_Bool bProtect = sal_True );
41 VCL_DLLPUBLIC OString WhitespaceToSpace(const OString&, sal_Bool bProtect = sal_True);
42 // returns a string with multiple adjacent occurrences of whitespace
43 // converted to a single space. if bProtect is sal_True (nonzero), then
44 // doublequote, singlequote and singleleftquote protect their respective
45 // contents
48 // parses the first double in the string; decimal is '.' only
49 VCL_DLLPUBLIC inline double StringToDouble( const String& rStr )
51 return rtl::math::stringToDouble(rStr, sal_Unicode('.'), sal_Unicode(0));
54 VCL_DLLPUBLIC inline double StringToDouble(const OString& rStr)
56 return rtl::math::stringToDouble(rStr, '.', static_cast<sal_Char>(0));
59 // fills a character buffer with the string representation of a double
60 // the buffer has to be long enough (e.g. 128 bytes)
61 // returns the string len
62 VCL_DLLPUBLIC inline int getValueOfDouble( char* pBuffer, double f, int nPrecision = 0)
64 OString aStr( rtl::math::doubleToString( f, rtl_math_StringFormat_G, nPrecision, '.', true ) );
65 int nLen = aStr.getLength();
66 std::strncpy( pBuffer, aStr.getStr(), nLen+1 ); // copy string including terminating zero
67 return nLen;
70 } // namespace
72 #endif // _PSPRINT_STRHELPER_HXX_
74 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */