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 ;
53 static bool replace( std::string & s ,
const std::string & from ,
const std::string & to ,
54 size_type * pos_p =
nullptr ) ;
59 static unsigned int replaceAll( std::string & s ,
const std::string & from ,
const std::string & to ) ;
65 static unsigned int replaceAll( std::string & s ,
const char * from ,
const char * to ) ;
68 static void removeAll( std::string & ,
char ) ;
71 static void trimLeft( std::string & s ,
const std::string &
ws , size_type limit = 0U ) ;
74 static void trimRight( std::string & s ,
const std::string &
ws , size_type limit = 0U ) ;
77 static void trim( std::string & s ,
const std::string &
ws ) ;
80 static std::string
trimmed(
const std::string & s ,
const std::string &
ws ) ;
83 static bool isNumeric(
const std::string & s ,
bool allow_minus_sign =
false ) ;
91 static bool isUShort(
const std::string & s ) ;
95 static bool isUInt(
const std::string & s ) ;
99 static bool isULong(
const std::string & s ) ;
103 static bool isInt(
const std::string & s ) ;
107 static std::string
fromBool(
bool b ) ;
113 static std::string
fromInt(
int i ) ;
116 static std::string
fromLong(
long l ) ;
119 static std::string
fromShort(
short s ) ;
122 static std::string
fromUInt(
unsigned int ui ) ;
125 static std::string
fromULong(
unsigned long ul ) ;
128 static std::string
fromUShort(
unsigned short us ) ;
131 static bool toBool(
const std::string & s ) ;
136 static double toDouble(
const std::string & s ) ;
142 static int toInt(
const std::string & s ) ;
148 static long toLong(
const std::string & s ) ;
154 static short toShort(
const std::string & s ) ;
160 static unsigned int toUInt(
const std::string & s ) ;
166 static unsigned int toUInt(
const std::string & s ,
Limited ) ;
174 static unsigned int toUInt(
const std::string & s1 ,
const std::string & s2 ) ;
186 static unsigned long toULong(
const std::string & s ) ;
200 static unsigned short toUShort(
const std::string & s ) ;
206 static void toUpper( std::string & s ) ;
210 static void toLower( std::string & s ) ;
214 static std::string
upper(
const std::string & s ) ;
218 static std::string
lower(
const std::string & s ) ;
231 static std::string
printable(
const std::string & in ,
char escape =
'\\' ) ;
235 static void escape( std::string & s ,
char c_escape ,
const std::string & specials_in ,
236 const std::string & specials_out ) ;
247 static void escape( std::string & s ,
char c_escape ,
const char * specials_in ,
248 const char * specials_out ) ;
251 static void escape( std::string & s ) ;
254 static std::string
escaped(
const std::string & ,
char c_escape ,
const std::string & specials_in ,
255 const std::string & specials_out ) ;
258 static std::string
escaped(
const std::string & ,
char c_escape ,
const char * specials_in ,
259 const char * specials_out ) ;
262 static std::string
escaped(
const std::string & ) ;
265 static void unescape( std::string & s ,
char c_escape ,
const char * specials_in ,
const char * specials_out ) ;
272 static void unescape( std::string & s ) ;
276 static std::string
unescaped(
const std::string & s ) ;
279 static std::string
meta() ;
284 static std::string
readLineFrom( std::istream & stream ,
const std::string & eol = std::string() ) ;
310 static void readLineFrom( std::istream & stream ,
const std::string & eol , std::string & result ,
311 bool pre_erase_result =
true ) ;
314 static std::string
wrap( std::string text ,
315 const std::string & prefix_first_line ,
const std::string & prefix_subsequent_lines ,
316 size_type width = 70U ) ;
329 const std::string & separators ,
char escape =
'\0' ,
330 bool remove_escapes =
true ) ;
346 static std::string
dequote(
const std::string & ,
char qq =
'\"' ,
char esc =
'\\' ,
const std::string &
ws =
Str::ws() ) ;
351 static std::string
join(
const std::string & sep ,
const StringArray & strings ) ;
354 static std::string
join(
const std::string & sep ,
const std::set<std::string> & strings ) ;
357 static std::string
join(
const std::string & sep ,
const std::string & s1 ,
const std::string & s2 ,
358 const std::string & s3 = std::string() ,
const std::string & s4 = std::string() ,
const std::string & s5 = std::string() ,
359 const std::string & s6 = std::string() ,
const std::string & s7 = std::string() ,
const std::string & s8 = std::string() ,
360 const std::string & s9 = std::string() ) ;
364 static std::string
join(
const std::string & sep ,
const StringMap & ,
365 const std::string & eq = std::string(1U,
'=') ,
const std::string &
tail = std::string() ) ;
371 static std::string
head(
const std::string & in , size_type pos ,
372 const std::string & default_ = std::string() ) ;
378 static std::string
head(
const std::string & in ,
const std::string & sep ,
bool default_empty =
true ) ;
384 static std::string
tail(
const std::string & in , size_type pos ,
385 const std::string & default_ = std::string() ) ;
391 static std::string
tail(
const std::string & in ,
const std::string & sep ,
bool default_empty =
true ) ;
397 static bool match(
const std::string & ,
const std::string & ) ;
403 static bool imatch(
const std::string & ,
const std::string & ) ;
411 static bool tailMatch(
const std::string & in ,
const std::string & ending ) ;
418 static bool headMatch(
const std::string & in ,
const std::string &
head ) ;
430 static std::string
ws() ;
439 static bool isPositive(
const std::string & ) ;
442 static bool isNegative(
const std::string & ) ;
445 static size_type
ifind(
const std::string & s ,
const std::string & key ,
446 size_type pos = 0U ) ;
450 static std::string
unique( std::string s ,
char c =
' ' ,
char r =
' ' ) ;
456 static void readLineFromImp( std::istream & ,
const std::string & , std::string & ) ;
457 static unsigned short toUShortImp(
const std::string & s ,
bool & overflow ,
bool & invalid ) ;
458 static unsigned long toULongImp(
const std::string & s ,
bool & overflow ,
bool & invalid ) ;
459 static unsigned int toUIntImp(
const std::string & s ,
bool & overflow ,
bool & invalid ) ;
460 static short toShortImp(
const std::string & s ,
bool & overflow ,
bool & invalid ) ;
461 static long toLongImp(
const std::string & s ,
bool & overflow ,
bool & invalid ) ;
462 static int toIntImp(
const std::string & s ,
bool & overflow ,
bool & invalid ) ;
463 static void escapeImp( std::string & ,
char ,
const char * ,
const char * ,
bool ) ;
464 static void joinImp(
const std::string & , std::string & ,
const std::string & ) ;
static unsigned long toULong(const std::string &s, Limited)
Converts string 's' to an unsigned long.
static std::string positive()
Returns a default positive string. See isPositive().
static std::string fromBool(bool b)
Converts boolean 'b' to a string.
static size_type ifind(const std::string &s, const std::string &key, size_type pos=0U)
Returns the position of the key in 's' using a Latin-1 case-insensitive search.
static std::string printable(const std::string &in, char escape= '\\')
Returns a printable represention of the given input string.
static bool toBool(const std::string &s)
Converts string 's' to a bool.
static std::string tail(const std::string &in, size_type pos, const std::string &default_=std::string())
Returns the last part of the string after the given position.
static int toInt(const std::string &s)
Converts string 's' to an int.
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.
static bool tailMatch(const std::string &in, const std::string &ending)
Returns true if the string has the given ending (or ending is empty).
static std::string head(const std::string &in, size_type pos, const std::string &default_=std::string())
Returns the first part of the string up to just before the given position.
static bool isPositive(const std::string &)
Returns true if the string has a positive meaning, such as "1", "true", "yes".
static std::string fromDouble(double d)
Converts double 'd' to a string.
static std::string dequote(const std::string &, char qq= '\"' , char esc = '\\' , const std::string & ws = Str::ws() )
Dequotes a string by removing unescaped quotes and escaping quoted whitespace, so "qq-aaa-esc-qq-bbb-...
static bool imatch(const std::string &, const std::string &)
Returns true if the two strings are the same, ignoring Latin-1 case.
std::vector< std::string > StringArray
A std::vector of std::strings.
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'.
static void splitIntoTokens(const std::string &in, StringArray &out, const std::string &ws)
Splits the string into 'ws'-delimited tokens.
static short toShort(const std::string &s)
Converts string 's' to a short.
static bool headMatch(const std::string &in, const std::string &head)
Returns true if the string has the given start (or head is empty).
static bool isNumeric(const std::string &s, bool allow_minus_sign=false)
Returns true if every character is a decimal digit.
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...
static std::string fromInt(int i)
Converts int 'i' to a string.
static void trim(std::string &s, const std::string &ws)
Trims both ends of s, taking off any of the 'ws' characters.
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.
static std::string fromLong(long l)
Converts long 'l' to a string.
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...
static unsigned int toUInt(const std::string &s)
Converts string 's' to an unsigned int.
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.
static void toLower(std::string &s)
Replaces all Latin-1 uppercase characters in string 's' by lowercase characters.
static std::string fromUInt(unsigned int ui)
Converts unsigned int 'ui' to a string.
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'...
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.
static bool isInt(const std::string &s)
Returns true if the string can be converted into an integer without throwing an exception.
static std::string unique(std::string s, char c= ' ', char r= ' ')
Returns a string with repeated 'c' characters replaced by one 'r' character.
static double toDouble(const std::string &s)
Converts string 's' to a double.
static std::string headMatchResidue(const StringArray &in, const std::string &head)
Returns the unmatched part of the first string in the array that has the given start.
static std::string fromShort(short s)
Converts short 's' to a string.
static bool isUShort(const std::string &s)
Returns true if the string can be converted into an unsigned short without throwing an exception...
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...
static std::string fromUShort(unsigned short us)
Converts unsigned short 'us' to a string.
static bool match(const std::string &, const std::string &)
Returns true if the two strings are the same.
static std::string trimmed(const std::string &s, const std::string &ws)
Returns a trim()med version of s.
static std::string readLineFrom(std::istream &stream, const std::string &eol=std::string())
Reads a line from the stream using the given line terminator.
Overload discrimiator for G::Str::toUWhatever()
static bool isNegative(const std::string &)
Returns true if the string has a negative meaning, such as "0", "false", "no".
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...
static bool isPrintableAscii(const std::string &s)
Returns true if every character is a 7-bit, non-control character (ie.
std::map< std::string, std::string > StringMap
A std::map of std::strings.
static std::string join(const std::string &sep, const StringArray &strings)
Concatenates an array of strings with separators.
A static class which provides string helper functions.
static long toLong(const std::string &s)
Converts string 's' to a long.
static unsigned short toUShort(const std::string &s, Limited)
Converts string 's' to an unsigned short.
static std::string negative()
Returns a default negative string. See isNegative().
static bool isUInt(const std::string &s)
Returns true if the string can be converted into an unsigned integer without throwing an exception...
static void removeAll(std::string &, char)
Removes all occurrences of the character from the string.
static std::set< std::string > keySet(const StringMap &string_map)
Extracts the keys from a map of strings.
static void splitIntoFields(const std::string &in, StringArray &out, const std::string &separators, char escape= '\0', bool remove_escapes=true)
Splits the string into fields.
static bool isULong(const std::string &s)
Returns true if the string can be converted into an unsigned long without throwing an exception...
static std::string fromULong(unsigned long ul)
Converts unsigned long 'ul' to a string.
static std::string unescaped(const std::string &s)
Returns the unescape()d version of s.
static std::string meta()
Returns a list of shell meta-characters with a tilde as the first character.
static std::string ws()
Returns a string of standard whitespace characters.
static std::string toPrintableAscii(char c, char escape= '\\')
Returns a 7-bit printable representation of the given input character.
static void toUpper(std::string &s)
Replaces all Latin-1 lowercase characters in string 's' by uppercase characters.