A static class which provides string helper functions. More...
#include <gstr.h>
Public Types | |
typedef std::string::size_type | size_type |
Static Public Member Functions | |
static bool | replace (std::string &s, const std::string &from, const std::string &to, size_type *pos_p=NULL) |
Replaces 'from' with 'to', starting at offset '*pos_p'. More... | |
static unsigned int | replaceAll (std::string &s, const std::string &from, const std::string &to) |
Does a global replace on string 's', replacing all occurences of sub-string 'from' with 'to'. More... | |
static unsigned int | replaceAll (std::string &s, const char *from, const char *to) |
A c-string overload, provided for performance reasons. More... | |
static void | removeAll (std::string &, char) |
Removes all occurrences of the character from the string. More... | |
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. More... | |
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. More... | |
static void | trim (std::string &s, const std::string &ws) |
Trims both ends of s, taking off any of the 'ws' characters. More... | |
static std::string | trimmed (const std::string &s, const std::string &ws) |
Returns a trim()med version of s. More... | |
static bool | isNumeric (const std::string &s, bool allow_minus_sign=false) |
Returns true if every character is a decimal digit. More... | |
static bool | isPrintableAscii (const std::string &s) |
Returns true if every character is a 7-bit, non-control character (ie. More... | |
static bool | isUShort (const std::string &s) |
Returns true if the string can be converted into an unsigned short without throwing an exception. More... | |
static bool | isUInt (const std::string &s) |
Returns true if the string can be converted into an unsigned integer without throwing an exception. More... | |
static bool | isULong (const std::string &s) |
Returns true if the string can be converted into an unsigned long without throwing an exception. More... | |
static std::string | fromBool (bool b) |
Converts boolean 'b' to a string. More... | |
static std::string | fromDouble (double d) |
Converts double 'd' to a string. More... | |
static std::string | fromInt (int i) |
Converts int 'i' to a string. More... | |
static std::string | fromLong (long l) |
Converts long 'l' to a string. More... | |
static std::string | fromShort (short s) |
Converts short 's' to a string. More... | |
static std::string | fromUInt (unsigned int ui) |
Converts unsigned int 'ui' to a string. More... | |
static std::string | fromULong (unsigned long ul) |
Converts unsigned long 'ul' to a string. More... | |
static std::string | fromUShort (unsigned short us) |
Converts unsigned short 'us' to a string. More... | |
static bool | toBool (const std::string &s) |
Converts string 's' to a bool. More... | |
static double | toDouble (const std::string &s) |
Converts string 's' to a double. More... | |
static int | toInt (const std::string &s) |
Converts string 's' to an int. More... | |
static long | toLong (const std::string &s) |
Converts string 's' to a long. More... | |
static short | toShort (const std::string &s) |
Converts string 's' to a short. More... | |
static unsigned int | toUInt (const std::string &s, bool limited=false) |
Converts string 's' to an unsigned int. More... | |
static unsigned long | toULong (const std::string &s, bool limited=false) |
Converts string 's' to an unsigned long. More... | |
static unsigned short | toUShort (const std::string &s, bool limited=false) |
Converts string 's' to an unsigned short. More... | |
static void | toUpper (std::string &s) |
Replaces all lowercase characters in string 's' by uppercase characters. More... | |
static void | toLower (std::string &s) |
Replaces all uppercase characters in string 's' by lowercase characters. More... | |
static std::string | upper (const std::string &s) |
Returns a copy of 's' in which all lowercase characters have been replaced by uppercase characters. More... | |
static std::string | lower (const std::string &s) |
Returns a copy of 's' in which all uppercase characters have been replaced by lowercase characters. More... | |
static std::string | toPrintableAscii (char c, char escape= '\\') |
Returns a 7-bit printable representation of the given input character. More... | |
static std::string | toPrintableAscii (const std::string &in, char escape= '\\') |
Returns a 7-bit printable representation of the given input string. More... | |
static std::string | toPrintableAscii (const std::wstring &in, wchar_t escape=L'\\') |
Returns a 7-bit printable representation of the given wide input string. More... | |
static std::string | printable (const std::string &in, char escape= '\\') |
Returns a printable represention of the given input string. More... | |
static void | escape (std::string &, const std::string &specials, char escape= '\\') |
Prefixes each occurrence of one of the special characters with the escape character. More... | |
static std::string | escaped (const std::string &, const std::string &specials, char escape= '\\') |
Prefixes each occurrence of one of the special characters with the escape character. More... | |
static std::string | readLineFrom (std::istream &stream, const std::string &eol=std::string()) |
Reads a line from the stream using the given line terminator. More... | |
static void | readLineFrom (std::istream &stream, const std::string &eol, std::string &result, bool pre_erase_result=true) |
An overload which avoids string copying. More... | |
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. More... | |
static void | splitIntoTokens (const std::string &in, Strings &out, const std::string &ws) |
Splits the string into 'ws'-delimited tokens. More... | |
static void | splitIntoTokens (const std::string &in, StringArray &out, const std::string &ws) |
Overload for vector<string>. More... | |
static void | splitIntoFields (const std::string &in, Strings &out, const std::string &seperators, char escape= '\0', bool discard_bogus_escapes=true) |
Splits the string into fields. More... | |
static void | splitIntoFields (const std::string &in, StringArray &out, const std::string &seperators, char escape= '\0', bool discard_bogus_escapes=true) |
Overload for vector<string>. More... | |
static std::string | join (const Strings &strings, const std::string &sep) |
Concatenates a set of strings. More... | |
static std::string | join (const StringArray &strings, const std::string &sep) |
Concatenates a set of strings. More... | |
static Strings | keys (const StringMap &string_map) |
Extracts the keys from a map of strings. More... | |
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. More... | |
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. More... | |
static bool | tailMatch (const std::string &in, const std::string &ending) |
Returns true if the given string has the given ending. More... | |
static std::string | ws () |
A convenience function returning standard whitespace characters. More... | |
typedef std::string::size_type G::Str::size_type |
|
static |
|
static |
|
static |
|
static |
|
static |
Converts int 'i' to a string.
Definition at line 236 of file gstr.cpp.
Referenced by G::Pam::Error::Error(), and GNet::MonitorImp::findCertificate().
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
Returns the first part of the string up to just before the given position.
The character at pos is not returned. Returns the supplied default if pos is npos.
Definition at line 834 of file gstr.cpp.
Referenced by GAuth::SaslServerBasic::apply(), GAuth::SaslServerPamImp::apply(), Main::Configuration::listeningInterfaces(), GSmtp::ExecutableVerifier::verify(), and GSmtp::NetworkVerifier::verify().
|
static |
Returns true if every character is a decimal digit.
Empty strings return true.
Definition at line 152 of file gstr.cpp.
Referenced by GNet::Resolver::resolve().
|
static |
Returns true if every character is a 7-bit, non-control character (ie.
0x20<=c<0x7f). Empty strings return true.
Definition at line 167 of file gstr.cpp.
Referenced by GNet::ResolverImp::onData().
|
static |
Returns true if the string can be converted into an unsigned integer without throwing an exception.
Definition at line 190 of file gstr.cpp.
Referenced by GSmtp::FactoryParser::check(), GNet::Resolver::resolve(), and GNet::AddressImp::wildcards().
|
static |
|
static |
|
static |
Concatenates a set of strings.
Definition at line 799 of file gstr.cpp.
Referenced by G::StringMapReader::at(), G::Executable::displayString(), GAuth::SaslServerBasicImp::mechanisms(), GAuth::SaslClient::preferred(), and GSmtp::NetworkVerifier::verify().
|
static |
|
static |
|
static |
|
static |
Returns a printable represention of the given input string.
Typically used to prevent escape sequences getting into log files.
Definition at line 507 of file gstr.cpp.
Referenced by GAuth::SaslServerBasic::apply(), GPop::ServerProtocol::apply(), GSmtp::ServerProtocol::apply(), GSmtp::ClientProtocol::apply(), GSmtp::ClientProtocolReply::error(), GSmtp::RequestClient::onReceive(), GSmtp::SpamClient::onReceive(), GSmtp::Client::onReceive(), and GSsl::Certificate::str().
|
static |
Reads a line from the stream using the given line terminator.
The line terminator is not part of the returned string. The terminator defaults to the newline.
Note that alternatives in the standard library such as std::istream::getline() or std::getline(stream,string) in the standard "string" header are limited to a single character as the terminator.
The stream's fail bit is set if (1) an empty string was returned because the stream was already at eof or (2) the string overflowed. Therefore, ignoring overflow, if the stream ends in an incomplete line that line fragment is returned with the stream's eof flag set but the fail bit reset and the next attempted read will return an empty string with the fail bit set. If the stream ends with a complete line then the last line is returned with eof and fail bits reset and the next attempted read will return an empty string with eof and fail bits set.
If we don't worry too much about the 'bad' state and note that the boolean tests on a stream test its 'fail' flag (not eof) we can use a read loop like "while(s.good()){read(s);if(s)...}".
|
static |
|
static |
|
static |
|
static |
Does a global replace on string 's', replacing all occurences of sub-string 'from' with 'to'.
Returns the number of substitutions made. Consider using in a while loop if 'from' is more than one character.
Definition at line 78 of file gstr.cpp.
Referenced by GSmtp::ClientProtocolReply::ClientProtocolReply(), G::Executable::Executable(), filter_run(), and GSsl::Certificate::str().
|
static |
|
static |
Splits the string into fields.
Duplicated, leading and trailing separator characters are all significant. Ths output array is cleared first.
If a non-null escape character is given then any escaped separator is not used for splitting. If the 'discard...' parameter is true then escapes will never appear in the output except for where there were originally double escapes. This is the preferred behaviour but it can create problems if doing nested splitting – the escapes are lost by the time the sub-strings are split.
Definition at line 765 of file gstr.cpp.
Referenced by GSmtp::VerifierStatus::parse(), GNet::AddressImp::validString(), Main::CommandLine::value(), and GNet::AddressImp::wildcards().
|
static |
|
static |
Splits the string into 'ws'-delimited tokens.
The behaviour is like strtok() in that adjacent delimiters count as one and leading and trailing delimiters are ignored. Ths output array is cleared first.
Definition at line 714 of file gstr.cpp.
Referenced by GAuth::SaslServerBasic::apply(), G::Executable::Executable(), and G::Md5::hmac().
|
static |
|
static |
Returns the last part of the string after the given position.
The character at pos is not returned. Returns the supplied default if pos is npos.
Definition at line 842 of file gstr.cpp.
Referenced by GAuth::SaslServerBasic::apply(), GAuth::SaslServerPamImp::apply(), Main::Configuration::clientInterface(), Main::Configuration::listeningInterfaces(), GSmtp::FactoryParser::parse(), GSmtp::ExecutableVerifier::verify(), and GSmtp::NetworkVerifier::verify().
|
static |
Returns true if the given string has the given ending.
Definition at line 850 of file gstr.cpp.
Referenced by G::DirectoryList::readType().
|
static |
|
static |
|
static |
Converts string 's' to an int.
Exception: Overflow Exception: InvalidFormat
Definition at line 310 of file gstr.cpp.
Referenced by GSmtp::ClientProtocolReply::ClientProtocolReply().
|
static |
|
static |
|
static |
Returns a 7-bit printable representation of the given input character.
Definition at line 521 of file gstr.cpp.
Referenced by G::hostname().
|
static |
|
static |
|
static |
|
static |
Converts string 's' to an unsigned int.
If 'limited' is true then very large numeric strings are limited to the maximum value of the numeric type, without an Overflow exception.
Exception: Overflow Exception: InvalidFormat
Definition at line 346 of file gstr.cpp.
Referenced by GSmtp::ProcessorFactory::newProcessor(), GNet::Resolver::resolve(), Main::CommandLine::value(), GNet::AddressImp::wildcards(), and G::GetOpt::wrapDefault().
|
static |
|
static |
Replaces all lowercase characters in string 's' by uppercase characters.
Definition at line 422 of file gstr.cpp.
Referenced by GSmtp::ClientProtocolReply::textContains().
|
static |
|
static |
Trims both ends of s, taking off any of the 'ws' characters.
Definition at line 133 of file gstr.cpp.
Referenced by GNet::ResolverImp::onData().
|
static |
Trims the lhs of s, taking off up to 'limit' of the 'ws' characters.
Definition at line 111 of file gstr.cpp.
Referenced by GSmtp::ClientProtocolReply::ClientProtocolReply().
|
static |
|
static |
|
static |
Returns a copy of 's' in which all lowercase characters have been replaced by uppercase characters.
Definition at line 426 of file gstr.cpp.
Referenced by GAuth::SaslClient::preferred(), GSmtp::ExecutableVerifier::verify(), and GSmtp::NetworkVerifier::verify().
|
static |
Does word-wrapping.
The return value is a string with embedded newlines.
Definition at line 633 of file gstr.cpp.
Referenced by G::GetOpt::usageSummary().
|
static |