sources/mystring.cpp

changeset 183
9b6a0daedfc0
parent 182
20ca0a6be175
child 190
90bf9049e5eb
equal deleted inserted replaced
182:20ca0a6be175 183:9b6a0daedfc0
37 /*! 37 /*!
38 * \returns a lower-case version of this string. 38 * \returns a lower-case version of this string.
39 */ 39 */
40 std::string to_lowercase(const std::string& string) 40 std::string to_lowercase(const std::string& string)
41 { 41 {
42 String result = string; 42 std::string result = string;
43 43
44 for (char& ch : result) 44 for (char& ch : result)
45 { 45 {
46 if (isupper(ch)) 46 if (isupper(ch))
47 ch += 'a' - 'A'; 47 ch += 'a' - 'A';
53 /*! 53 /*!
54 * \brief Joins the elements of this string list into one longer string. 54 * \brief Joins the elements of this string list into one longer string.
55 * \param delimeter The delimeter to place between the element strings. 55 * \param delimeter The delimeter to place between the element strings.
56 * \returns the catenated string. 56 * \returns the catenated string.
57 */ 57 */
58 std::string join_string_list(const StringList& strings, const std::string& delimeter) 58 std::string join_string_list(const std::vector<std::string>& strings, const std::string& delimeter)
59 { 59 {
60 std::string result; 60 std::string result;
61 61
62 for (const std::string &item : strings) 62 for (const std::string &item : strings)
63 { 63 {
171 171
172 /*! 172 /*!
173 * \param other Sub-string to find from the beginning of this string. 173 * \param other Sub-string to find from the beginning of this string.
174 * \returns whether or not this string begins with the provided sub-string. 174 * \returns whether or not this string begins with the provided sub-string.
175 */ 175 */
176 bool starts_with(const std::string& str, const String& other) 176 bool starts_with(const std::string& str, const std::string& other)
177 { 177 {
178 if (str.length() < other.length()) 178 if (str.length() < other.length())
179 return false; 179 return false;
180 else 180 else
181 return std::strncmp(str.data(), other.data(), other.length()) == 0; 181 return std::strncmp(str.data(), other.data(), other.length()) == 0;
198 /*! 198 /*!
199 * \brief Splits this string using the provided delimeter. 199 * \brief Splits this string using the provided delimeter.
200 * \param delimeter Delimeter to use for splitting. 200 * \param delimeter Delimeter to use for splitting.
201 * \returns a string list containing the split strings. 201 * \returns a string list containing the split strings.
202 */ 202 */
203 StringList split(const std::string& string, const String& delimeter) 203 std::vector<std::string> split(const std::string& string, const std::string& delimeter)
204 { 204 {
205 StringList result; 205 std::vector<std::string> result;
206 int a = 0; 206 int a = 0;
207 int b; 207 int b;
208 208
209 // Find all separators and store the text left to them. 209 // Find all separators and store the text left to them.
210 while ((b = string.find(delimeter, a)) != -1) 210 while ((b = string.find(delimeter, a)) != -1)
211 { 211 {
212 String sub = mid(string, a, b); 212 std::string sub = mid(string, a, b);
213 213
214 if (sub.length() > 0) 214 if (sub.length() > 0)
215 result.push_back(sub); 215 result.push_back(sub);
216 216
217 a = b + delimeter.length(); 217 a = b + delimeter.length();

mercurial