12 #include <LibCyberRadio/Common/Pythonesque.h> 31 size_t found = ret.find_first_not_of(chars);
32 if ( found != std::string::npos ) {
33 ret = ret.substr(found);
47 size_t found = ret.find_last_not_of(chars);
48 if ( found != std::string::npos ) {
62 std::string
Pythonesque::Replace(
const std::string& str,
const std::string &oldstr,
const std::string& newstr,
int count)
65 std::string::size_type pos = buf.find(oldstr);
68 while ( (pos != std::string::npos) && (replaces < count) )
70 buf.replace(pos, oldstr.length(), newstr);
71 pos = buf.find(oldstr, pos + newstr.length());
81 std::string::size_type pos = buf.find(sep);
85 while ( (pos != std::string::npos) && (splits < maxsplit) )
87 tmp = buf.substr(0, pos);
90 buf = buf.substr(pos + sep.length());
100 std::ostringstream oss;
101 for (
int i = 0; i < (int)vec.size(); i++)
104 if ( i != (
int)vec.size()-1 ) oss << sep;
111 std::string buf = str.substr(start, end);
112 std::string::size_type pos = buf.find(prefix);
114 if ( str.size() == 0 )
116 else if ( prefix.size() == 0 )
123 std::string buf = str.substr(start, end);
124 std::string::size_type pos = buf.rfind(suffix);
126 if ( str.size() == 0 )
128 else if ( suffix.size() == 0 )
130 return ( pos == (buf.length() - suffix.length()) );
135 std::string ret =
"";
139 if ( path.find(
"\\") != std::string::npos )
141 else if ( path.find(
"/") != std::string::npos )
152 if ( vec.size() > 0 )
153 ret = vec[vec.size()-1];
static std::string Rstrip(const std::string &str, const std::string &chars=" \\\)
Strips trailing whitespace from the given string.
static std::string Strip(const std::string &str, const std::string &chars=" \\\)
Strips both leading and trailing whitespace from the given string.
virtual ~Pythonesque(void)
Destructor.
static std::string Replace(const std::string &str, const std::string &oldstr, const std::string &newstr, int count=INT_MAX)
Replaces occurrences of one substring with another within the given string.
static BasicStringList Split(const std::string &str, const std::string &sep, int maxsplit=INT_MAX)
Splits the given string into a list of string tokens.
BASIC_LIST_CONTAINER< std::string > BasicStringList
Type representing a list of strings.
Pythonesque(void)
Protected constructor; prevents class instantiation.
static bool Startswith(const std::string &str, const std::string &prefix, int start=0, int end=INT_MAX)
Determines if the given string starts with the specified prefix.
static bool Endswith(const std::string &str, const std::string &suffix, int start=0, int end=INT_MAX)
Determines if the given string ends with the specified suffix.
Defines functionality for LibCyberRadio applications.
static std::string Lstrip(const std::string &str, const std::string &chars=" \\\)
Strips leading whitespace from the given string.
static std::string Basename(const std::string &path)
Gets the base name (the file name itself, without leading path components) from the given file path...
static std::string Join(const BasicStringList &vec, const std::string &sep)
Joins a list of string tokens, concatenating them into a single string.