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 ,
54 const std::string & from ,
const std::string & to ,
55 size_type * pos_p =
nullptr ) ;
60 static unsigned int replaceAll( std::string & s ,
const std::string & from ,
const std::string & to ) ;
66 static unsigned int replaceAll( std::string & s ,
const char * from ,
const char * to ) ;
69 static void removeAll( std::string & ,
char ) ;
72 static void trimLeft( std::string & s ,
const std::string &
ws , size_type limit = 0U ) ;
75 static void trimRight( std::string & s ,
const std::string &
ws , size_type limit = 0U ) ;
78 static void trim( std::string & s ,
const std::string &
ws ) ;
81 static std::string
trimmed(
const std::string & s ,
const std::string &
ws ) ;
84 static bool isNumeric(
const std::string & s ,
bool allow_minus_sign =
false ) ;
92 static bool isUShort(
const std::string & s ) ;
96 static bool isUInt(
const std::string & s ) ;
100 static bool isULong(
const std::string & s ) ;
104 static bool isInt(
const std::string & s ) ;
108 static std::string
fromBool(
bool b ) ;
114 static std::string
fromInt(
int i ) ;
117 static std::string
fromLong(
long l ) ;
120 static std::string
fromShort(
short s ) ;
123 static std::string
fromUInt(
unsigned int ui ) ;
126 static std::string
fromULong(
unsigned long ul ) ;
129 static std::string
fromUShort(
unsigned short us ) ;
132 static bool toBool(
const std::string & s ) ;
136 static double toDouble(
const std::string & s ) ;
140 static int toInt(
const std::string & s ) ;
144 static long toLong(
const std::string & s ) ;
148 static short toShort(
const std::string & s ) ;
152 static unsigned int toUInt(
const std::string & s ) ;
156 static unsigned int toUInt(
const std::string & s ,
Limited ) ;
163 static unsigned int toUInt(
const std::string & s1 ,
const std::string & s2 ) ;
174 static unsigned long toULong(
const std::string & s ) ;
185 static unsigned short toUShort(
const std::string & s ) ;
189 static void toUpper( std::string & s ) ;
193 static void toLower( std::string & s ) ;
197 static std::string
upper(
const std::string & s ) ;
201 static std::string
lower(
const std::string & s ) ;
214 static std::string
printable(
const std::string & in ,
char escape =
'\\' ) ;
218 static void escape( std::string & s ,
char c_escape ,
const std::string & specials_in ,
219 const std::string & specials_out ) ;
230 static void escape( std::string & s ,
char c_escape ,
const char * specials_in ,
231 const char * specials_out ) ;
234 static void escape( std::string & s ) ;
237 static std::string
escaped(
const std::string & ,
char c_escape ,
const std::string & specials_in ,
238 const std::string & specials_out ) ;
241 static std::string
escaped(
const std::string & ,
char c_escape ,
const char * specials_in ,
242 const char * specials_out ) ;
245 static std::string
escaped(
const std::string & ) ;
248 static void unescape( std::string & s ,
char c_escape ,
const char * specials_in ,
const char * specials_out ) ;
255 static void unescape( std::string & s ) ;
259 static std::string
unescaped(
const std::string & s ) ;
262 static std::string
meta() ;
265 static std::string
readLineFrom( std::istream & stream ,
const std::string & eol = std::string() ) ;
291 static void readLineFrom( std::istream & stream ,
const std::string & eol , std::string & result ,
292 bool pre_erase_result =
true ) ;
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 ) ;
310 const std::string & seperators ,
char escape =
'\0' ,
311 bool remove_escapes =
true ) ;
323 static bool splitMatch(
const std::string & in ,
const std::string & s ,
const std::string &
ws =
Str::ws() ) ;
326 static std::string
splitMatchTail(
const std::string & in ,
const std::string & s ,
331 static std::string
join(
const std::string & sep ,
const StringArray & strings ) ;
334 static std::string
join(
const std::string & sep ,
const std::set<std::string> & strings ) ;
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() ) ;
346 static std::string
head(
const std::string & in , std::string::size_type pos ,
347 const std::string & default_ = std::string() ) ;
352 static std::string
head(
const std::string & in ,
const std::string & sep ,
bool default_empty =
true ) ;
358 static std::string
tail(
const std::string & in , std::string::size_type pos ,
359 const std::string & default_ = std::string() ) ;
364 static std::string
tail(
const std::string & in ,
const std::string & sep ,
bool default_empty =
true ) ;
370 static bool tailMatch(
const std::string & in ,
const std::string & ending ) ;
373 static std::string
ws() ;
382 static bool isPositive(
const std::string & ) ;
385 static bool isNegative(
const std::string & ) ;
388 static bool imatch(
const std::string & ,
const std::string & ) ;
391 static std::string::size_type
ifind(
const std::string & s ,
const std::string & key ,
392 std::string::size_type pos = 0U ) ;
395 static std::string
unique( std::string s ,
char c =
' ' ,
char r =
' ' ) ;
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 & ) ;
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 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 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 given string has the given ending.
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 bool imatch(const std::string &, const std::string &)
Returns true if the two strings are the same, ignoring 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 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 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.
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 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.
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' charaters replaced by one 'r' character.
static double toDouble(const std::string &s)
Converts string 's' to a double.
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'.
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 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 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...
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.
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 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().
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 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, typically used with escape().
static std::string ws()
A convenience function returning standard whitespace characters.
static std::string toPrintableAscii(char c, char escape= '\\')
Returns a 7-bit printable representation of the given input character.
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.
static void toUpper(std::string &s)
Replaces all Latin-1 lowercase characters in string 's' by uppercase characters.