20 inline bool startswith(
const std::string& str,
const std::string& part)
22 if (str.size() < part.size())
24 return str.substr(0, part.size()) == part;
28 inline bool endswith(
const std::string& str,
const std::string& part)
30 if (str.size() < part.size())
32 return str.substr(str.size() - part.size()) == part;
38 template<
typename ITER>
39 std::string
join(
const std::string& sep,
const ITER& begin,
const ITER& end)
41 std::stringstream
res;
43 for (ITER i = begin; i != end; ++i)
57 template<
typename ITEMS>
58 std::string
join(
const std::string& sep,
const ITEMS& items)
60 std::stringstream
res;
62 for (
const auto& i: items)
77 template<
typename FUN>
78 inline std::string
lstrip(
const std::string& str,
const FUN& classifier)
84 while (beg < str.size() && classifier(str[beg]))
87 return str.substr(beg, str.size() - beg + 1);
93 inline std::string
lstrip(
const std::string& str)
95 return lstrip(str, ::isspace);
102 template<
typename FUN>
103 inline std::string
rstrip(
const std::string& str,
const FUN& classifier)
108 size_t end = str.size();
109 while (end > 0 && classifier(str[end - 1]))
113 return std::string();
115 return str.substr(0, end);
121 inline std::string
rstrip(
const std::string& str)
123 return rstrip(str, ::isspace);
130 template<
typename FUN>
131 inline std::string
strip(
const std::string& str,
const FUN& classifier)
137 size_t end = str.size() - 1;
138 while (beg < end && classifier(str[beg]))
140 while (end >= beg && classifier(str[end]))
143 return str.substr(beg, end-beg+1);
149 inline std::string
strip(
const std::string& str)
151 return strip(str, ::isspace);
155 inline std::string
upper(
const std::string& str)
158 res.reserve(str.size());
159 for (std::string::const_iterator i = str.begin(); i != str.end(); ++i)
160 res += ::toupper(*i);
165 inline std::string
lower(
const std::string& str)
168 res.reserve(str.size());
169 for (std::string::const_iterator i = str.begin(); i != str.end(); ++i)
170 res += ::tolower(*i);
175 std::string
basename(
const std::string& pathname);
178 std::string
dirname(
const std::string& pathname);
181 void appendpath(std::string& dest,
const char* path2);
184 void appendpath(std::string& dest,
const std::string& path2);
187 template<
typename S1,
typename S2,
typename... Args>
188 void appendpath(std::string& dest, S1 first, S2 second, Args... next)
195 template<
typename... Args>
208 std::string
normpath(
const std::string& pathname);
234 Split(
const std::string& str,
const std::string& sep,
bool skip_empty=
false)
235 : str(str), sep(sep), skip_empty(skip_empty) {}
237 class const_iterator :
public std::iterator<std::input_iterator_tag, std::string>
285 std::string
decode_cstring(
const std::string& str,
size_t& lenParsed);
288 std::string
encode_url(
const std::string& str);
291 std::string
decode_url(
const std::string& str);
const_iterator end()
Return the end iterator to string split.
Definition: string.h:270
const std::string * operator->() const
Definition: string.cc:236
size_t end
Position of the first character of the next token.
Definition: string.h:244
void skip_separators()
Move end past all the consecutive separators that start at its position.
Definition: string.cc:154
std::string upper(const std::string &str)
Return an uppercased copy of str.
Definition: string.h:155
Split a string where a given substring is found.
Definition: string.h:222
std::string encode_url(const std::string &str)
Urlencode a string.
Definition: string.cc:311
std::string dirname(const std::string &pathname)
Given a pathname, return the directory name without the file name.
Definition: string.cc:18
std::string decode_base64(const std::string &str)
Decode a string encoded in Base64.
Definition: string.cc:392
std::string lower(const std::string &str)
Return a lowercased copy of str.
Definition: string.h:165
std::string rstrip(const std::string &str, const FUN &classifier)
Return the substring of 'str' without all trailing characters for which 'classifier' returns true...
Definition: string.h:103
std::string cur
Current token.
Definition: string.h:242
std::string remainder() const
Definition: string.cc:146
void appendpath(std::string &dest, const char *path2)
Append path2 to path1, adding slashes when appropriate.
Definition: string.cc:45
const_iterator begin()
Return the begin iterator to split a string on instances of sep.
Definition: string.h:267
String functions.
Definition: apt.cc:38
std::string basename(const std::string &pathname)
Given a pathname, return the file name without its path.
Definition: string.cc:9
const std::string & operator*() const
Definition: string.cc:235
std::string lstrip(const std::string &str, const FUN &classifier)
Return the substring of 'str' without all leading characters for which 'classifier' returns true...
Definition: string.h:78
const_iterator()
End iterator.
Definition: string.h:253
std::string str
String to split.
Definition: string.h:225
Split(const std::string &str, const std::string &sep, bool skip_empty=false)
Definition: string.h:234
std::string joinpath(const std::string &path1, const std::string &path2)
Definition: string.cc:97
std::string join(const std::string &sep, const ITER &begin, const ITER &end)
Stringify and join a sequence of objects.
Definition: string.h:39
std::string encode_base64(const std::string &str)
Encode a string in Base64.
Definition: string.cc:359
std::string encode_cstring(const std::string &str)
Escape the string so it can safely used as a C string inside double quotes.
Definition: string.cc:253
std::string strip(const std::string &str, const FUN &classifier)
Return the substring of 'str' without all leading and trailing characters for which 'classifier' retu...
Definition: string.h:131
std::string decode_url(const std::string &str)
Decode an urlencoded string.
Definition: string.cc:329
const Split * split
Definition: string.h:240
bool skip_empty
If true, skip empty tokens, effectively grouping consecutive separators as if they were a single one...
Definition: string.h:232
bool endswith(const std::string &str, const std::string &part)
Check if a string ends with the given substring.
Definition: string.h:28
std::string sep
Separator.
Definition: string.h:227
std::string decode_cstring(const std::string &str, size_t &lenParsed)
Unescape a C string, stopping at the first double quotes or at the end of the string.
Definition: string.cc:277
bool startswith(const std::string &str, const std::string &part)
Check if a string starts with the given substring.
Definition: string.h:20
bool operator!=(const const_iterator &ti) const
Definition: string.cc:245
~const_iterator()
Definition: string.cc:142
bool operator==(const const_iterator &ti) const
Definition: string.cc:238
set< string > & res
Definition: packagerecord.cc:73
const_iterator & operator++()
Definition: string.cc:172
std::string normpath(const std::string &pathname)
Normalise a pathname.
Definition: string.cc:104