1
#include "MathMLSolverStableHeaders.h"
2
#include "MathMLString.h"
10
//-----------------------------------------------------------------------
11
String::size_type StringUtil::lastIndexOf( const String& str, const String& pattern )
13
String::size_type pos = String::npos;
15
for ( String::size_type i = str.find( pattern );
16
i != std::string::npos;
17
i = str.find( pattern, i + 1 )
26
//-----------------------------------------------------------------------
27
String::size_type StringUtil::lastIndexOf( const String& str, const char character )
29
String::size_type pos = String::npos;
31
for ( String::size_type i = str.find( character );
32
i != std::string::npos;
33
i = str.find( character, i + 1 )
42
//-----------------------------------------------------------------------
43
bool StringUtil::startsWith( const String& str, const String& pattern )
45
String::size_type pos = str.find( pattern );
46
return pos == 0 ? true : false;
49
//-----------------------------------------------------------------------
50
bool StringUtil::startsWith( const String& str, char character )
52
String::size_type pos = str.find( character );
53
return pos == 0 ? true : false;
56
//-----------------------------------------------------------------------
57
bool StringUtil::endsWith( const String& str, const String& pattern )
59
String::size_type pos = str.find( pattern );
61
if ( pos == String::npos )
64
return pos == ( str.size() - pattern.size() ) ? true : false;
67
//-----------------------------------------------------------------------
68
bool StringUtil::endsWith( const String& str, char character )
70
String::size_type pos = str.find( character );
71
return pos == ( str.size() - 1 ) ? true : false;
74
//-----------------------------------------------------------------
75
String StringUtil::replaceAll( const String& str, char character, const String& replacement )
78
String::size_type position = string.find_last_of( character );
80
while ( position != String::npos )
82
string.replace( position, 1, replacement );
83
position = string.find_last_of( character );
89
//-----------------------------------------------------------------
90
String StringUtil::replaceAll( const String& str, const String& pattern, const String& replacement )
94
size_t position = string.find( pattern );
96
while ( position != String::npos )
98
string.replace( position, pattern.size(), replacement );
99
position = string.find( pattern );
105
//-----------------------------------------------------------------
106
String StringUtil::replaceAll( const String& str, const String& pattern, char replacement )
109
replaceStr += replacement;
110
return replaceAll( str, pattern, replaceStr );
113
//-----------------------------------------------------------------------
114
MathML::String StringUtil::replaceAll( const String& str, char pattern, char replacement )
118
size_t position = string.find( pattern );
120
while ( position != String::npos )
122
string[ position ] = replacement;
123
position = string.find( pattern );
129
//-----------------------------------------------------------------------
130
MathML::String StringUtil::valueOf( unsigned char value )
132
std::stringstream ss;
133
ss << value << std::ends;
137
//-----------------------------------------------------------------------
138
MathML::String StringUtil::valueOf( unsigned short value )
140
std::stringstream ss;
141
ss << value << std::ends;
145
//-----------------------------------------------------------------------
146
MathML::String StringUtil::valueOf( unsigned int value )
148
std::stringstream ss;
149
ss << value << std::ends;
153
//-----------------------------------------------------------------------
154
MathML::String StringUtil::valueOf( unsigned long value )
156
std::stringstream ss;
157
ss << value << std::ends;
161
//-----------------------------------------------------------------------
162
MathML::String StringUtil::valueOf( unsigned long long value )
164
std::stringstream ss;
165
ss << value << std::ends;
169
//-----------------------------------------------------------------------
170
MathML::String StringUtil::valueOf( char value )
172
std::stringstream ss;
173
ss << value << std::ends;
177
//-----------------------------------------------------------------------
178
MathML::String StringUtil::valueOf( short value )
180
std::stringstream ss;
181
ss << value << std::ends;
185
//-----------------------------------------------------------------------
186
MathML::String StringUtil::valueOf( int value )
188
std::stringstream ss;
189
ss << value << std::ends;
193
//-----------------------------------------------------------------------
194
MathML::String StringUtil::valueOf( long value )
196
std::stringstream ss;
197
ss << value << std::ends;
201
//-----------------------------------------------------------------------
202
MathML::String StringUtil::valueOf( long long value )
204
std::stringstream ss;
205
ss << value << std::ends;
209
//-----------------------------------------------------------------------
210
MathML::String StringUtil::valueOf( float value )
212
std::stringstream ss;
213
ss << value << std::ends;
217
//-----------------------------------------------------------------------
218
MathML::String StringUtil::valueOf( double value )
220
std::stringstream ss;
221
ss << value << std::ends;
225
//-----------------------------------------------------------------------
226
int StringUtil::caseCompare( const String& str1, const String& str2 )
233
return tmp1.compare( str2 );
237
//-----------------------------------------------------------------------
238
void StringUtil::toLowerCase( String& str )
247
//-----------------------------------------------------------------------
248
void StringUtil::toUpperCase( String& str )
257
//-----------------------------------------------------------------------
258
unsigned short StringUtil::parseUnsignedShort( const String& str )
260
unsigned short value;
261
std::istringstream inStream( str );
266
//-----------------------------------------------------------------------
267
unsigned int StringUtil::parseUnsignedInt( const String& str )
270
std::istringstream inStream( str );
275
//-----------------------------------------------------------------------
276
unsigned long StringUtil::parseUnsignedLong( const String& str )
279
std::istringstream inStream( str );
284
//-----------------------------------------------------------------------
285
short StringUtil::parseShort( const String& str )
288
std::istringstream inStream( str );
293
//-----------------------------------------------------------------------
294
int StringUtil::parseInt( const String& str )
297
std::istringstream inStream( str );
302
//-----------------------------------------------------------------------
303
long StringUtil::parseLong( const String& str )
306
std::istringstream inStream( str );
311
//-----------------------------------------------------------------------
312
double StringUtil::parseDouble( const String& str )
315
std::istringstream inStream( str );
320
//-----------------------------------------------------------------
321
String StringUtil::removeWhitespaces( const String &string )
323
String whitespaces ( " \t\f\v\n\r" );
324
String result = string;
326
String::size_type found = string.find_first_of( whitespaces );
328
while ( found != String::npos )
330
result.erase( found, 1 );
331
found = result.find_first_of( whitespaces );
337
//-----------------------------------------------------------------
338
MathML::String StringUtil::valueOfUnfinalized( int value )
340
std::stringstream ss;