1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 #ifndef _STRINGCONVERSIONTOOLS_HXX
23 #define _STRINGCONVERSIONTOOLS_HXX
24 
25 #include <sal/types.h>
26 #include <rtl/ustring.hxx>
27 #include <rtl/ustrbuf.hxx>
28 
29 namespace basegfx
30 {
31     namespace internal
32     {
33         void lcl_skipSpaces(sal_Int32& 				io_rPos,
34                             const ::rtl::OUString& 	rStr,
35                             const sal_Int32 		nLen);
36 
37         void lcl_skipSpacesAndCommas(sal_Int32& 			io_rPos,
38                                         const ::rtl::OUString& rStr,
39                                         const sal_Int32 		nLen);
40 
lcl_isOnNumberChar(const sal_Unicode aChar,bool bSignAllowed=true)41         inline bool lcl_isOnNumberChar(const sal_Unicode aChar, bool bSignAllowed = true)
42         {
43             const bool bPredicate( (sal_Unicode('0') <= aChar && sal_Unicode('9') >= aChar)
44                                     || (bSignAllowed && sal_Unicode('+') == aChar)
45                                     || (bSignAllowed && sal_Unicode('-') == aChar) );
46 
47             return bPredicate;
48         }
49 
lcl_isOnNumberChar(const::rtl::OUString & rStr,const sal_Int32 nPos,bool bSignAllowed=true)50         inline bool lcl_isOnNumberChar(const ::rtl::OUString& rStr, const sal_Int32 nPos, bool bSignAllowed = true)
51         {
52             return lcl_isOnNumberChar(rStr[nPos],
53                                         bSignAllowed);
54         }
55 
56         bool lcl_getDoubleChar(double& 					o_fRetval,
57                                 sal_Int32& 				io_rPos,
58                                 const ::rtl::OUString& 	rStr);
59 
60         bool lcl_importDoubleAndSpaces( double& 				o_fRetval,
61                                         sal_Int32& 				io_rPos,
62                                         const ::rtl::OUString& 	rStr,
63                                         const sal_Int32 		nLen );
64 
65         bool lcl_importNumberAndSpaces(sal_Int32&                o_nRetval,
66                                         sal_Int32& 				io_rPos,
67                                         const ::rtl::OUString& 	rStr,
68                                         const sal_Int32 		nLen);
69 
70         void lcl_skipNumber(sal_Int32& 				io_rPos,
71                             const ::rtl::OUString& 	rStr,
72                             const sal_Int32 		nLen);
73 
74         void lcl_skipDouble(sal_Int32& 				io_rPos,
75                             const ::rtl::OUString& 	rStr);
76 
lcl_skipNumberAndSpacesAndCommas(sal_Int32 & io_rPos,const::rtl::OUString & rStr,const sal_Int32 nLen)77         inline void lcl_skipNumberAndSpacesAndCommas(sal_Int32& 				io_rPos,
78                                                 const ::rtl::OUString& 	rStr,
79                                                 const sal_Int32 			nLen)
80         {
81             lcl_skipNumber(io_rPos, rStr, nLen);
82             lcl_skipSpacesAndCommas(io_rPos, rStr, nLen);
83         }
84 
85         // #100617# Allow to skip doubles, too.
lcl_skipDoubleAndSpacesAndCommas(sal_Int32 & io_rPos,const::rtl::OUString & rStr,const sal_Int32 nLen)86         inline void lcl_skipDoubleAndSpacesAndCommas(sal_Int32& 				io_rPos,
87                                                 const ::rtl::OUString& 	rStr,
88                                                 const sal_Int32 			nLen)
89         {
90             lcl_skipDouble(io_rPos, rStr);
91             lcl_skipSpacesAndCommas(io_rPos, rStr, nLen);
92         }
93 
lcl_putNumberChar(::rtl::OUStringBuffer & rStr,double fValue)94         inline void lcl_putNumberChar( ::rtl::OUStringBuffer& rStr,
95                                 double 		 	       fValue )
96         {
97             rStr.append( fValue );
98         }
99 
100         void lcl_putNumberCharWithSpace( ::rtl::OUStringBuffer& rStr,
101                                             double 		        fValue,
102                                             double 		        fOldValue,
103                                             bool 			        bUseRelativeCoordinates );
104 
lcl_getCommand(sal_Char cUpperCaseCommand,sal_Char cLowerCaseCommand,bool bUseRelativeCoordinates)105         inline sal_Unicode lcl_getCommand( sal_Char cUpperCaseCommand,
106                                             sal_Char cLowerCaseCommand,
107                                             bool 	bUseRelativeCoordinates )
108         {
109             return bUseRelativeCoordinates ? cLowerCaseCommand : cUpperCaseCommand;
110         }
111     } // namespace internal
112 } // namespace basegfx
113 
114 #endif /* _STRINGCONVERSIONTOOLS_HXX */
115