VideoTools
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
gstr.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2017 Graeme Walker
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 // ===
17 ///
18 /// \file gstr.h
19 ///
20 
21 #ifndef G_STR_H
22 #define G_STR_H
23 
24 #include "gdef.h"
25 #include "gexception.h"
26 #include "gstrings.h"
27 #include <string>
28 #include <sstream>
29 #include <iostream>
30 #include <list>
31 #include <vector>
32 #include <set>
33 
34 namespace G
35 {
36  class Str ;
37 }
38 
39 /// \class G::Str
40 /// A static class which provides string helper functions.
41 ///
42 class G::Str
43 {
44 public:
45  G_EXCEPTION_CLASS( Overflow , "string conversion error: over/underflow" ) ;
46  G_EXCEPTION_CLASS( InvalidFormat, "string conversion error: invalid format" ) ;
47  G_EXCEPTION_CLASS( NotEmpty, "internal error: string container not empty" ) ;
48  typedef std::string::size_type size_type ;
49 
50  struct Limited /// Overload discrimiator for G::Str::toUWhatever()
51  {} ;
52 
53  static bool replace( std::string & s ,
54  const std::string & from , const std::string & to ,
55  size_type * pos_p = nullptr ) ;
56  ///< Replaces 'from' with 'to', starting at offset '*pos_p'.
57  ///< Returns true if a substitution was made, and adjusts
58  ///< '*pos_p' by to.length().
59 
60  static unsigned int replaceAll( std::string & s , const std::string & from , const std::string & to ) ;
61  ///< Does a global replace on string 's', replacing all
62  ///< occurances of sub-string 'from' with 'to'. Returns
63  ///< the number of substitutions made. Consider using
64  ///< in a while loop if 'from' is more than one character.
65 
66  static unsigned int replaceAll( std::string & s , const char * from , const char * to ) ;
67  ///< A c-string overload, provided for performance reasons.
68 
69  static void removeAll( std::string & , char ) ;
70  ///< Removes all occurrences of the character from the string.
71 
72  static void trimLeft( std::string & s , const std::string & ws , size_type limit = 0U ) ;
73  ///< Trims the lhs of s, taking off up to 'limit' of the 'ws' characters.
74 
75  static void trimRight( std::string & s , const std::string & ws , size_type limit = 0U ) ;
76  ///< Trims the rhs of s, taking off up to 'limit' of the 'ws' characters.
77 
78  static void trim( std::string & s , const std::string & ws ) ;
79  ///< Trims both ends of s, taking off any of the 'ws' characters.
80 
81  static std::string trimmed( const std::string & s , const std::string & ws ) ;
82  ///< Returns a trim()med version of s.
83 
84  static bool isNumeric( const std::string & s , bool allow_minus_sign = false ) ;
85  ///< Returns true if every character is a decimal digit.
86  ///< Empty strings return true.
87 
88  static bool isPrintableAscii( const std::string & s ) ;
89  ///< Returns true if every character is a 7-bit, non-control
90  ///< character (ie. 0x20<=c<0x7f). Empty strings return true.
91 
92  static bool isUShort( const std::string & s ) ;
93  ///< Returns true if the string can be converted into
94  ///< an unsigned short without throwing an exception.
95 
96  static bool isUInt( const std::string & s ) ;
97  ///< Returns true if the string can be converted into
98  ///< an unsigned integer without throwing an exception.
99 
100  static bool isULong( const std::string & s ) ;
101  ///< Returns true if the string can be converted into
102  ///< an unsigned long without throwing an exception.
103 
104  static bool isInt( const std::string & s ) ;
105  ///< Returns true if the string can be converted into
106  ///< an integer without throwing an exception.
107 
108  static std::string fromBool( bool b ) ;
109  ///< Converts boolean 'b' to a string.
110 
111  static std::string fromDouble( double d ) ;
112  ///< Converts double 'd' to a string.
113 
114  static std::string fromInt( int i ) ;
115  ///< Converts int 'i' to a string.
116 
117  static std::string fromLong( long l ) ;
118  ///< Converts long 'l' to a string.
119 
120  static std::string fromShort( short s ) ;
121  ///< Converts short 's' to a string.
122 
123  static std::string fromUInt( unsigned int ui ) ;
124  ///< Converts unsigned int 'ui' to a string.
125 
126  static std::string fromULong( unsigned long ul ) ;
127  ///< Converts unsigned long 'ul' to a string.
128 
129  static std::string fromUShort( unsigned short us ) ;
130  ///< Converts unsigned short 'us' to a string.
131 
132  static bool toBool( const std::string & s ) ;
133  ///< Converts string 's' to a bool.
134  ///<
135 
136  static double toDouble( const std::string & s ) ;
137  ///< Converts string 's' to a double.
138  ///<
139 
140  static int toInt( const std::string & s ) ;
141  ///< Converts string 's' to an int.
142  ///<
143 
144  static long toLong( const std::string & s ) ;
145  ///< Converts string 's' to a long.
146  ///<
147 
148  static short toShort( const std::string & s ) ;
149  ///< Converts string 's' to a short.
150  ///<
151 
152  static unsigned int toUInt( const std::string & s ) ;
153  ///< Converts string 's' to an unsigned int.
154  ///<
155 
156  static unsigned int toUInt( const std::string & s , Limited ) ;
157  ///< Converts string 's' to an unsigned int.
158  ///<
159  ///< Very large numeric strings are limited to the maximum
160  ///< value of the numeric type, without an Overflow exception.
161  ///<
162 
163  static unsigned int toUInt( const std::string & s1 , const std::string & s2 ) ;
164  ///< Overload that converts the first string if it can be converted
165  ///< without throwing, or otherwise the second string.
166 
167  static unsigned long toULong( const std::string & s , Limited ) ;
168  ///< Converts string 's' to an unsigned long.
169  ///<
170  ///< Very large numeric strings are limited to the maximum value
171  ///< of the numeric type, without an Overflow exception.
172  ///<
173 
174  static unsigned long toULong( const std::string & s ) ;
175  ///< Converts string 's' to an unsigned long.
176  ///<
177 
178  static unsigned short toUShort( const std::string & s , Limited ) ;
179  ///< Converts string 's' to an unsigned short.
180  ///<
181  ///< Very large numeric strings are limited to the maximum value
182  ///< of the numeric type, without an Overflow exception.
183  ///<
184 
185  static unsigned short toUShort( const std::string & s ) ;
186  ///< Converts string 's' to an unsigned short.
187  ///<
188 
189  static void toUpper( std::string & s ) ;
190  ///< Replaces all Latin-1 lowercase characters in string 's' by
191  ///< uppercase characters.
192 
193  static void toLower( std::string & s ) ;
194  ///< Replaces all Latin-1 uppercase characters in string 's' by
195  ///< lowercase characters.
196 
197  static std::string upper( const std::string & s ) ;
198  ///< Returns a copy of 's' in which all Latin-1 lowercase characters
199  ///< have been replaced by uppercase characters.
200 
201  static std::string lower( const std::string & s ) ;
202  ///< Returns a copy of 's' in which all Latin-1 uppercase characters
203  ///< have been replaced by lowercase characters.
204 
205  static std::string toPrintableAscii( char c , char escape = '\\' ) ;
206  ///< Returns a 7-bit printable representation of the given input character.
207 
208  static std::string toPrintableAscii( const std::string & in , char escape = '\\' ) ;
209  ///< Returns a 7-bit printable representation of the given input string.
210 
211  static std::string toPrintableAscii( const std::wstring & in , wchar_t escape = L'\\' ) ;
212  ///< Returns a 7-bit printable representation of the given wide input string.
213 
214  static std::string printable( const std::string & in , char escape = '\\' ) ;
215  ///< Returns a printable represention of the given input string.
216  ///< Typically used to prevent escape sequences getting into log files.
217 
218  static void escape( std::string & s , char c_escape , const std::string & specials_in ,
219  const std::string & specials_out ) ;
220  ///< Prefixes each occurrence of one of the special-in characters with
221  ///< the escape character and its corresponding special-out character.
222  ///<
223  ///< If the specials-in string contains the nul character it must be
224  ///< at the end, otherwise the two specials strings must be the same
225  ///< length. The specials-out string cannot contain the nul character.
226  ///<
227  ///< The specials-in string should normally include the escape character
228  ///< itself, otherwise unescaping will not recover the original.
229 
230  static void escape( std::string & s , char c_escape , const char * specials_in ,
231  const char * specials_out ) ;
232  ///< Overload for c-style 'special' strings.
233 
234  static void escape( std::string & s ) ;
235  ///< Overload for 'normal' backslash escaping of whitespace.
236 
237  static std::string escaped( const std::string & , char c_escape , const std::string & specials_in ,
238  const std::string & specials_out ) ;
239  ///< Returns the escape()d string.
240 
241  static std::string escaped( const std::string & , char c_escape , const char * specials_in ,
242  const char * specials_out ) ;
243  ///< Returns the escape()d string.
244 
245  static std::string escaped( const std::string & ) ;
246  ///< Returns the escape()d string.
247 
248  static void unescape( std::string & s , char c_escape , const char * specials_in , const char * specials_out ) ;
249  ///< Unescapes the string by replacing e-e with e, e-special-in with
250  ///< special-out, and e-other with other.
251  ///<
252  ///< If the specials-out string includes the nul character then it must be at
253  ///< the end, otherwise the two specials strings must be the same length.
254 
255  static void unescape( std::string & s ) ;
256  ///< Overload for "normal" unescaping where the string has backslash escaping
257  ///< of whitespace.
258 
259  static std::string unescaped( const std::string & s ) ;
260  ///< Returns the unescape()d version of s.
261 
262  static std::string meta() ;
263  ///< Returns a list of shell meta-characters, typically used with escape().
264 
265  static std::string readLineFrom( std::istream & stream , const std::string & eol = std::string() ) ;
266  ///< Reads a line from the stream using the given line terminator.
267  ///< The line terminator is not part of the returned string.
268  ///< The terminator defaults to the newline.
269  ///<
270  ///< Note that alternatives in the standard library such as
271  ///< std::istream::getline() or std::getline(stream,string)
272  ///< in the standard "string" header are limited to a single
273  ///< character as the terminator.
274  ///<
275  ///< The stream's fail bit is set if (1) an empty string was
276  ///< returned because the stream was already at eof or (2)
277  ///< the string overflowed. Therefore, ignoring overflow, if
278  ///< the stream ends in an incomplete line that line fragment
279  ///< is returned with the stream's eof flag set but the fail bit
280  ///< reset and the next attempted read will return an empty string
281  ///< with the fail bit set. If the stream ends with a complete
282  ///< line then the last line is returned with eof and fail
283  ///< bits reset and the next attempted read will return
284  ///< an empty string with eof and fail bits set.
285  ///<
286  ///< Boolean tests on a stream are equivalent to using fail(),
287  ///< and fail() tests for failbit or badbit, so to process
288  ///< even incomplete lines at the end we can use a read
289  ///< loop like "while(s.good()){read(s);if(s)...}".
290 
291  static void readLineFrom( std::istream & stream , const std::string & eol , std::string & result ,
292  bool pre_erase_result = true ) ;
293  ///< An overload which avoids string copying.
294 
295  static std::string wrap( std::string text ,
296  const std::string & prefix_first_line , const std::string & prefix_subsequent_lines ,
297  size_type width = 70U ) ;
298  ///< Does word-wrapping. The return value is a string with
299  ///< embedded newlines.
300 
301  static void splitIntoTokens( const std::string & in , StringArray & out , const std::string & ws ) ;
302  ///< Splits the string into 'ws'-delimited tokens. The behaviour is like
303  ///< strtok() in that adjacent delimiters count as one and leading and
304  ///< trailing delimiters are ignored. The output array is cleared first.
305 
306  static StringArray splitIntoTokens( const std::string & in , const std::string & ws = Str::ws() ) ;
307  ///< Overload that returns by value.
308 
309  static void splitIntoFields( const std::string & in , StringArray & out ,
310  const std::string & seperators , char escape = '\0' ,
311  bool remove_escapes = true ) ;
312  ///< Splits the string into fields. Duplicated, leading and trailing
313  ///< separator characters are all significant. Ths output array is
314  ///< cleared first.
315  ///<
316  ///< If a non-null escape character is given then escaped separators do not
317  ///< result in a split. If the 'remove-escapes' parameter is true then all
318  ///< unescaped escapes are removed from the output; this is generally the
319  ///< preferred behaviour for nested escaping. If the 'remove-escapes'
320  ///< parameter is false then escapes are not removed; unescaped escapes
321  ///< are used to prevent splitting but they remain in the output.
322 
323  static bool splitMatch( const std::string & in , const std::string & s , const std::string & ws = Str::ws() ) ;
324  ///< Returns true if any of the split parts of 'in' are equal to 's'.
325 
326  static std::string splitMatchTail( const std::string & in , const std::string & s ,
327  const std::string & ws = Str::ws() ) ;
328  ///< Splits the input string into parts and looks for a part that starts with 's'
329  ///< and returns the trailing substring.
330 
331  static std::string join( const std::string & sep , const StringArray & strings ) ;
332  ///< Concatenates an array of strings.
333 
334  static std::string join( const std::string & sep , const std::set<std::string> & strings ) ;
335  ///< Concatenates a set of strings.
336 
337  static std::string join( const std::string & sep , const std::string & s1 , const std::string & s2 ,
338  const std::string & s3 = std::string() , const std::string & s4 = std::string() , const std::string & s5 = std::string() ,
339  const std::string & s6 = std::string() , const std::string & s7 = std::string() , const std::string & s8 = std::string() ,
340  const std::string & s9 = std::string() ) ;
341  ///< Concatenates a small number of strings.
342 
343  static std::set<std::string> keySet( const StringMap & string_map ) ;
344  ///< Extracts the keys from a map of strings.
345 
346  static std::string head( const std::string & in , std::string::size_type pos ,
347  const std::string & default_ = std::string() ) ;
348  ///< Returns the first part of the string up to just before the given position.
349  ///< The character at pos is not returned. Returns the supplied default
350  ///< if pos is npos. Returns the whole string if pos is off the end.
351 
352  static std::string head( const std::string & in , const std::string & sep , bool default_empty = true ) ;
353  ///< Overload taking a separator string, and with the default
354  ///< as either the input string or the empty string. If the
355  ///< separator occurs more than once in the input then only the
356  ///< first occurence is relevant.
357 
358  static std::string tail( const std::string & in , std::string::size_type pos ,
359  const std::string & default_ = std::string() ) ;
360  ///< Returns the last part of the string after the given position.
361  ///< The character at pos is not returned. Returns the supplied default
362  ///< if pos is npos. Returns the empty string if pos if off the end.
363 
364  static std::string tail( const std::string & in , const std::string & sep , bool default_empty = true ) ;
365  ///< Overload taking a separator string, and with the default
366  ///< as either the input string or the empty string. If the
367  ///< separator occurs more than once in the input then only the
368  ///< first occurence is relevant.
369 
370  static bool tailMatch( const std::string & in , const std::string & ending ) ;
371  ///< Returns true if the given string has the given ending.
372 
373  static std::string ws() ;
374  ///< A convenience function returning standard whitespace characters.
375 
376  static std::string positive() ;
377  ///< Returns a default positive string. See isPositive().
378 
379  static std::string negative() ;
380  ///< Returns a default negative string. See isNegative().
381 
382  static bool isPositive( const std::string & ) ;
383  ///< Returns true if the string has a positive meaning, such as "1", "true", "yes".
384 
385  static bool isNegative( const std::string & ) ;
386  ///< Returns true if the string has a negative meaning, such as "0", "false", "no".
387 
388  static bool imatch( const std::string & , const std::string & ) ;
389  ///< Returns true if the two strings are the same, ignoring case.
390 
391  static std::string::size_type ifind( const std::string & s , const std::string & key ,
392  std::string::size_type pos = 0U ) ;
393  ///< Does a case-insensitive std::string::find().
394 
395  static std::string unique( std::string s , char c = ' ' , char r = ' ' ) ;
396  ///< Returns a string with repeated 'c' charaters replaced by
397  ///< one 'r' character. Single 'c' characters are not replaced.
398 
399 private:
400  Str() ; // not implemented
401  static void readLineFromImp( std::istream & , const std::string & , std::string & ) ;
402  static unsigned short toUShortImp( const std::string & s , bool & overflow , bool & invalid ) ;
403  static unsigned long toULongImp( const std::string & s , bool & overflow , bool & invalid ) ;
404  static unsigned int toUIntImp( const std::string & s , bool & overflow , bool & invalid ) ;
405  static short toShortImp( const std::string & s , bool & overflow , bool & invalid ) ;
406  static long toLongImp( const std::string & s , bool & overflow , bool & invalid ) ;
407  static int toIntImp( const std::string & s , bool & overflow , bool & invalid ) ;
408  static void escapeImp( std::string & , char , const char * , const char * , bool ) ;
409  static void joinImp( const std::string & , std::string & , const std::string & ) ;
410 } ;
411 
412 #endif
static unsigned long toULong(const std::string &s, Limited)
Converts string 's' to an unsigned long.
Definition: gstr.cpp:471
static std::string positive()
Returns a default positive string. See isPositive().
Definition: gstr.cpp:1075
static std::string fromBool(bool b)
Converts boolean 'b' to a string.
Definition: gstr.cpp:282
static std::string printable(const std::string &in, char escape= '\\')
Returns a printable represention of the given input string.
Definition: gstr.cpp:663
static bool toBool(const std::string &s)
Converts string 's' to a bool.
Definition: gstr.cpp:336
static int toInt(const std::string &s)
Converts string 's' to an int.
Definition: gstr.cpp:368
static std::string wrap(std::string text, const std::string &prefix_first_line, const std::string &prefix_subsequent_lines, size_type width=70U)
Does word-wrapping.
Definition: gstr.cpp:787
static bool tailMatch(const std::string &in, const std::string &ending)
Returns true if the given string has the given ending.
Definition: gstr.cpp:1066
static bool isPositive(const std::string &)
Returns true if the string has a positive meaning, such as "1", "true", "yes".
Definition: gstr.cpp:1085
static std::string fromDouble(double d)
Converts double 'd' to a string.
Definition: gstr.cpp:287
static bool imatch(const std::string &, const std::string &)
Returns true if the two strings are the same, ignoring case.
Definition: gstr.cpp:1107
std::vector< std::string > StringArray
A std::vector of std::strings.
Definition: gstrings.h:33
static bool replace(std::string &s, const std::string &from, const std::string &to, size_type *pos_p=nullptr)
Replaces 'from' with 'to', starting at offset '*pos_p'.
Definition: gstr.cpp:134
static void splitIntoTokens(const std::string &in, StringArray &out, const std::string &ws)
Splits the string into 'ws'-delimited tokens.
Definition: gstr.cpp:868
static short toShort(const std::string &s)
Converts string 's' to a short.
Definition: gstr.cpp:412
static bool isNumeric(const std::string &s, bool allow_minus_sign=false)
Returns true if every character is a decimal digit.
Definition: gstr.cpp:228
static void escape(std::string &s, char c_escape, const std::string &specials_in, const std::string &specials_out)
Prefixes each occurrence of one of the special-in characters with the escape character and its corres...
Definition: gstr.cpp:66
static std::string fromInt(int i)
Converts int 'i' to a string.
Definition: gstr.cpp:294
static std::string tail(const std::string &in, std::string::size_type pos, const std::string &default_=std::string())
Returns the last part of the string after the given position.
Definition: gstr.cpp:1051
static void trim(std::string &s, const std::string &ws)
Trims both ends of s, taking off any of the 'ws' characters.
Definition: gstr.cpp:208
static void trimLeft(std::string &s, const std::string &ws, size_type limit=0U)
Trims the lhs of s, taking off up to 'limit' of the 'ws' characters.
Definition: gstr.cpp:186
static std::string fromLong(long l)
Converts long 'l' to a string.
Definition: gstr.cpp:301
static std::string lower(const std::string &s)
Returns a copy of 's' in which all Latin-1 uppercase characters have been replaced by lowercase chara...
Definition: gstr.cpp:561
static unsigned int toUInt(const std::string &s)
Converts string 's' to an unsigned int.
Definition: gstr.cpp:450
static std::string escaped(const std::string &, char c_escape, const std::string &specials_in, const std::string &specials_out)
Returns the escape()d string.
Definition: gstr.cpp:41
static void toLower(std::string &s)
Replaces all Latin-1 uppercase characters in string 's' by lowercase characters.
Definition: gstr.cpp:556
static std::string fromUInt(unsigned int ui)
Converts unsigned int 'ui' to a string.
Definition: gstr.cpp:315
static unsigned int replaceAll(std::string &s, const std::string &from, const std::string &to)
Does a global replace on string 's', replacing all occurances of sub-string 'from' with 'to'...
Definition: gstr.cpp:157
static std::string head(const std::string &in, std::string::size_type pos, const std::string &default_=std::string())
Returns the first part of the string up to just before the given position.
Definition: gstr.cpp:1037
static void trimRight(std::string &s, const std::string &ws, size_type limit=0U)
Trims the rhs of s, taking off up to 'limit' of the 'ws' characters.
Definition: gstr.cpp:197
static bool isInt(const std::string &s)
Returns true if the string can be converted into an integer without throwing an exception.
Definition: gstr.cpp:250
static std::string unique(std::string s, char c= ' ', char r= ' ')
Returns a string with repeated 'c' charaters replaced by one 'r' character.
Definition: gstr.cpp:1144
static double toDouble(const std::string &s)
Converts string 's' to a double.
Definition: gstr.cpp:354
static bool splitMatch(const std::string &in, const std::string &s, const std::string &ws=Str::ws())
Returns true if any of the split parts of 'in' are equal to 's'.
Definition: gstr.cpp:927
static std::string fromShort(short s)
Converts short 's' to a string.
Definition: gstr.cpp:308
static bool isUShort(const std::string &s)
Returns true if the string can be converted into an unsigned short without throwing an exception...
Definition: gstr.cpp:258
static std::string upper(const std::string &s)
Returns a copy of 's' in which all Latin-1 lowercase characters have been replaced by uppercase chara...
Definition: gstr.cpp:581
static std::string fromUShort(unsigned short us)
Converts unsigned short 'us' to a string.
Definition: gstr.cpp:329
static std::string trimmed(const std::string &s, const std::string &ws)
Returns a trim()med version of s.
Definition: gstr.cpp:213
static std::string readLineFrom(std::istream &stream, const std::string &eol=std::string())
Reads a line from the stream using the given line terminator.
Definition: gstr.cpp:695
Overload discrimiator for G::Str::toUWhatever()
Definition: gstr.h:50
static bool isNegative(const std::string &)
Returns true if the string has a negative meaning, such as "0", "false", "no".
Definition: gstr.cpp:1091
static void unescape(std::string &s, char c_escape, const char *specials_in, const char *specials_out)
Unescapes the string by replacing e-e with e, e-special-in with special-out, and e-other with other...
Definition: gstr.cpp:104
static std::string splitMatchTail(const std::string &in, const std::string &s, const std::string &ws=Str::ws())
Splits the input string into parts and looks for a part that starts with 's' and returns the trailing...
Definition: gstr.cpp:934
static bool isPrintableAscii(const std::string &s)
Returns true if every character is a 7-bit, non-control character (ie.
Definition: gstr.cpp:244
std::map< std::string, std::string > StringMap
A std::map of std::strings.
Definition: gstrings.h:34
static std::string join(const std::string &sep, const StringArray &strings)
Concatenates an array of strings.
Definition: gstr.cpp:972
A static class which provides string helper functions.
Definition: gstr.h:42
static long toLong(const std::string &s)
Converts string 's' to a long.
Definition: gstr.cpp:389
static unsigned short toUShort(const std::string &s, Limited)
Converts string 's' to an unsigned short.
Definition: gstr.cpp:515
static std::string negative()
Returns a default negative string. See isNegative().
Definition: gstr.cpp:1080
static bool isUInt(const std::string &s)
Returns true if the string can be converted into an unsigned integer without throwing an exception...
Definition: gstr.cpp:266
static std::string::size_type ifind(const std::string &s, const std::string &key, std::string::size_type pos=0U)
Does a case-insensitive std::string::find().
Definition: gstr.cpp:1112
static void removeAll(std::string &, char)
Removes all occurrences of the character from the string.
Definition: gstr.cpp:180
static std::set< std::string > keySet(const StringMap &string_map)
Extracts the keys from a map of strings.
Definition: gstr.cpp:1020
static bool isULong(const std::string &s)
Returns true if the string can be converted into an unsigned long without throwing an exception...
Definition: gstr.cpp:274
static std::string fromULong(unsigned long ul)
Converts unsigned long 'ul' to a string.
Definition: gstr.cpp:322
static std::string unescaped(const std::string &s)
Returns the unescape()d version of s.
Definition: gstr.cpp:127
static std::string meta()
Returns a list of shell meta-characters, typically used with escape().
Definition: gstr.cpp:1032
static std::string ws()
A convenience function returning standard whitespace characters.
Definition: gstr.cpp:1027
static std::string toPrintableAscii(char c, char escape= '\\')
Returns a 7-bit printable representation of the given input character.
Definition: gstr.cpp:679
static void splitIntoFields(const std::string &in, StringArray &out, const std::string &seperators, char escape= '\0', bool remove_escapes=true)
Splits the string into fields.
Definition: gstr.cpp:921
static void toUpper(std::string &s)
Replaces all Latin-1 lowercase characters in string 's' by uppercase characters.
Definition: gstr.cpp:576