sources/mystring.cpp

changeset 179
7fc34735178e
parent 158
de7574d292ad
child 181
e254398fcc7c
equal deleted inserted replaced
173:248fba6d1e76 179:7fc34735178e
46 { 46 {
47 return m_string.compare (other.stdString()); 47 return m_string.compare (other.stdString());
48 } 48 }
49 49
50 /*! 50 /*!
51 * \brief Removes all instances of an unwanted character from this string.
52 * \param unwanted Character to remove.
53 */
54 void String::strip (char unwanted)
55 {
56 for (int pos = 0; (pos = find (unwanted)) != -1;)
57 removeAt (pos--);
58 }
59
60 /*!
61 * \brief Removes all instances of multiple characters from this string.
62 * \param unwanted Characters to remove.
63 */
64 void String::strip (const List<char>& unwanted)
65 {
66 for (char character : unwanted)
67 strip(character);
68 }
69
70 /*!
71 * \returns an upper-case version of this string. 51 * \returns an upper-case version of this string.
72 */ 52 */
73 String String::toUpperCase() const 53 String String::toUpperCase() const
74 { 54 {
75 String result (m_string); 55 String result (m_string);
126 while ((b = find (delimeter, a)) != -1) 106 while ((b = find (delimeter, a)) != -1)
127 { 107 {
128 String sub = mid (a, b); 108 String sub = mid (a, b);
129 109
130 if (sub.length() > 0) 110 if (sub.length() > 0)
131 result << sub; 111 result.push_back(sub);
132 112
133 a = b + delimeter.length(); 113 a = b + delimeter.length();
134 } 114 }
135 115
136 // Add the string at the right of the last separator 116 // Add the string at the right of the last separator
137 if (a < (int) length()) 117 if (a < (int) length())
138 result.append (mid (a, length())); 118 result.push_back(mid(a, length()));
139 119
140 return result; 120 return result;
141 } 121 }
142 122
143 /*! 123 /*!
407 /*! 387 /*!
408 * \brief Joins the elements of this string list into one longer string. 388 * \brief Joins the elements of this string list into one longer string.
409 * \param delimeter The delimeter to place between the element strings. 389 * \param delimeter The delimeter to place between the element strings.
410 * \returns the catenated string. 390 * \returns the catenated string.
411 */ 391 */
412 String StringList::join (const String& delimeter) 392 String join_string_list(const StringList& strings, const String& delimeter)
413 { 393 {
414 String result; 394 String result;
415 395
416 for (const String &item : container()) 396 for (const String &item : strings)
417 { 397 {
418 if (result.isEmpty() == false) 398 if (result.isEmpty() == false)
419 result += delimeter; 399 result += delimeter;
420 400
421 result += item; 401 result += item;

mercurial