1 /******************************************************************************
2 Copyright (c) 2007 netAllied GmbH, Tettnang
3 
4 Permission is hereby granted, free of charge, to any person
5 obtaining a copy of this software and associated documentation
6 files (the "Software"), to deal in the Software without
7 restriction, including without limitation the rights to use,
8 copy, modify, merge, publish, distribute, sublicense, and/or sell
9 copies of the Software, and to permit persons to whom the
10 Software is furnished to do so, subject to the following
11 conditions:
12 
13 The above copyright notice and this permission notice shall be
14 included in all copies or substantial portions of the Software.
15 
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18 OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 OTHER DEALINGS IN THE SOFTWARE.
24 ******************************************************************************/
25 
26 #ifndef __MATHML_STRING_H__
27 #define __MATHML_STRING_H__
28 
29 #include "MathMLSolverPrerequisites.h"
30 
31 #include <iostream>
32 #include <vector>
33 #include <string>
34 
35 namespace MathML
36 {
37     /** The standard string implementation.
38     */
39     typedef std::string String;
40 
41     /** CIS string implementation.
42     */
43     typedef std::wstring WideString;
44 
45     /** If wchar_t treated as native type we need an alternative for
46     for third party libs or plug-ins that aren't compiled with wchar_t
47     as native type. Usually wchar_t is mapped to unsigned short.
48     @see http://msdn2.microsoft.com/en-us/library/dh8che7s(VS.80).aspx
49     */
50     typedef std::basic_string < unsigned short, std::char_traits<unsigned short>,
51     std::allocator<unsigned short> > WideString2;
52 
53     /** A vector of strings.
54     */
55     typedef std::vector<String> StringVector;
56 
57     /** A vector of wide strings.
58     */
59     typedef std::vector<WideString> WStringVector;
60 
61     class _MATHML_SOLVER_EXPORT StringUtil
62     {
63 
64     public:
65 
66         /** @todo lastIndexOf documentation
67          @param str
68          @param pattern
69          @return
70         */
71         static String::size_type lastIndexOf( const String& str, const String& pattern );
72         /** @todo lastIndexOf documentation
73          @param str
74          @param character
75          @return
76         */
77         static String::size_type lastIndexOf( const String& str, const char character );
78 
79         /** @todo startsWith documentation
80          @param str
81          @param pattern
82          @return
83         */
84         static bool startsWith( const String& str, const String& pattern );
85         /** @todo startsWith documentation
86          @param str
87          @param character
88          @return
89         */
90         static bool startsWith( const String& str, char character );
91 
92         /** Searches the given string, and checks if the pattern is found at the end of it.
93         @param str The string to be searched.
94         @param pattern The pattern to search for.
95         @return true If pattern is found at the end of the string, otherwise false.
96         */
97         static bool endsWith( const String& str, const String& pattern );
98         /** Searches the given string, and checks if the character is found at the end of it.
99         @param str The string to be searched.
100         @param character The character to search for.
101         @return true If pattern is found at the end of the string, otherwise false.
102         */
103         static bool endsWith( const String& str, char character );
104 
105         /** Replaces parts of the given string.
106         @param str The string to be searched.
107         @param character The character to search for.
108         @param replacement The replacement string.
109         @return The new processed string.
110         */
111         static String replaceAll( const String& str, char character, const String& replacement );
112         /** Replaces parts of the given string.
113         @param str The string to be searched.
114         @param pattern The pattern to search for.
115         @param replacement The replacement string.
116         @return The new processed string.
117         */
118         static String replaceAll( const String& str, const String& pattern, const String& replacement );
119         /** Replaces parts of the given string.
120         @param str The string to be searched.
121         @param pattern The pattern to search for.
122         @param replacement The replacement character.
123         @return The new processed string.
124         */
125         static String replaceAll( const String& str, const String& pattern, char replacement );
126 
127         static String replaceAll( const String& str, char pattern, char replacement );
128 
129 
130         /** @todo valueOf documentation
131          @param value
132          @return
133         */
134         static String valueOf( unsigned char value );
135         /** @todo valueOf documentation
136          @param value
137          @return
138         */
139         static String valueOf( unsigned short value );
140         /** @todo valueOf documentation
141          @param value
142          @return
143         */
144         static String valueOf( unsigned int value );
145         /** @todo valueOf documentation
146          @param value
147          @return
148         */
149         static String valueOf( unsigned long value );
150         /** @todo valueOf documentation
151          @param value
152          @return
153         */
154         static String valueOf( unsigned long long value );
155         /** @todo valueOf documentation
156          @param value
157          @return
158         */
159         static String valueOf( char value );
160         /** @todo valueOf documentation
161          @param value
162          @return
163         */
164         static String valueOf( short value );
165         /** @todo valueOf documentation
166          @param value
167          @return
168         */
169         static String valueOf( int value );
170         /** @todo valueOf documentation
171          @param value
172          @return
173         */
174         /** @todo valueOf documentation
175          @param value
176          @return
177         */
178         static String valueOf( long value );
179 
180         /** @todo valueOf documentation
181         @param value
182         @return
183         */
184         static String valueOf( long long value );
185 
186         /** @todo valueOf documentation
187          @param value
188          @return
189         */
190         static String valueOf( float value );
191         /** @todo valueOf documentation
192          @param value
193          @return
194         */
195         static String valueOf( double value );
196 
197         /** Converts an integer to a String.
198         Does not finalize the string with std::ends to avoid a trailing blank.
199         @param value Integer to parse.
200         @return string Representation.
201         */
202         static String valueOfUnfinalized( int value );
203 
204         /**
205          Compare two strings case-insensitively using full case folding.
206          @param str1 First string to compare.
207          @param str2 Second string to compare.
208          @return A negative, zero, or positive integer indicating the comparison result.
209         */
210         static int caseCompare( const String& str1, const String& str2 );
211 
212         /** @todo toLowerCase documentation
213          @param str
214          @return
215         */
216         static void toLowerCase( String& str );
217         /** @todo toUpperCase documentation
218          @param str
219          @return
220         */
221         static void toUpperCase( String& str );
222 
223         /** @todo parseUnsignedShort documentation
224          @param str
225          @return
226         */
227         static unsigned short parseUnsignedShort( const String& str );
228         /** @todo parseUnsignedInt documentation
229          @param str
230          @return
231         */
232         static unsigned int parseUnsignedInt( const String& str );
233         /** @todo parseUnsignedLong documentation
234          @param str
235          @return
236         */
237         static unsigned long parseUnsignedLong( const String& str );
238         /** @todo parseShort documentation
239          @param str
240          @return
241         */
242         static short parseShort( const String& str );
243         /** @todo parseInt documentation
244          @param str
245          @return
246         */
247         static int parseInt( const String& str );
248         /** @todo parseLong documentation
249          @param str
250          @return
251         */
252         static long parseLong( const String& str );
253 
254         static double parseDouble( const String& str );
255 
256         /** @todo description */
257         static String removeWhitespaces( const String &string );
258 
259     private:
260         StringUtil();
261         StringUtil( const StringUtil& util );
262         const StringUtil& operator=( const StringUtil& util );
263     };
264 }
265 
266 #endif //__MATHML_STRING_H__
267