52 |
54 |
53 // ------------------------------------------------------------------------------------------------- |
55 // ------------------------------------------------------------------------------------------------- |
54 // |
56 // |
55 String String::strip (const List<char>& unwanted) |
57 String String::strip (const List<char>& unwanted) |
56 { |
58 { |
57 String copy (m_string); |
59 String result (m_string); |
58 |
60 |
59 for (char c : unwanted) |
61 for (int i = 0; i < unwanted.size(); ++i) |
60 { |
62 { |
61 for (int pos = 0; (pos = copy.find (String (c))) != -1;) |
63 String c = unwanted[i]; |
62 copy.remove_at (pos--); |
64 |
63 } |
65 for (int pos = 0; (pos = result.find (c)) != -1;) |
64 |
66 result.remove_at (pos--); |
65 return copy; |
67 } |
|
68 |
|
69 return result; |
66 } |
70 } |
67 |
71 |
68 // ------------------------------------------------------------------------------------------------- |
72 // ------------------------------------------------------------------------------------------------- |
69 // |
73 // |
70 String String::to_uppercase() const |
74 String String::to_uppercase() const |
71 { |
75 { |
72 String newstr (m_string); |
76 String result (m_string); |
73 |
77 |
74 for (char& c : newstr) |
78 for (int i = 0; i < result.length(); ++i) |
75 { |
79 { |
76 if (c >= 'a' and c <= 'z') |
80 if (islower (result[i])) |
77 c -= 'a' - 'A'; |
81 result[i] -= 'a' - 'A'; |
78 } |
82 } |
79 |
83 |
80 return newstr; |
84 return result; |
81 } |
85 } |
82 |
86 |
83 // ------------------------------------------------------------------------------------------------- |
87 // ------------------------------------------------------------------------------------------------- |
84 // |
88 // |
85 String String::to_lowercase() const |
89 String String::to_lowercase() const |
86 { |
90 { |
87 String newstr (m_string); |
91 String result (m_string); |
88 |
92 |
89 for (char& c : newstr) |
93 for (int i = 0; i < result.length(); ++i) |
90 { |
94 { |
91 if (c >= 'A' and c <= 'Z') |
95 if (isupper (result[i])) |
92 c += 'a' - 'A'; |
96 result[i] += 'a' - 'A'; |
93 } |
97 } |
94 |
98 |
95 return newstr; |
99 return result; |
96 } |
100 } |
97 |
101 |
98 // ------------------------------------------------------------------------------------------------- |
102 // ------------------------------------------------------------------------------------------------- |
99 // |
103 // |
100 StringList String::split (char del) const |
104 StringList String::split (char del) const |
142 |
146 |
143 // ------------------------------------------------------------------------------------------------- |
147 // ------------------------------------------------------------------------------------------------- |
144 // |
148 // |
145 int String::count (char needle) const |
149 int String::count (char needle) const |
146 { |
150 { |
147 int needles = 0; |
151 int result = 0; |
148 |
152 |
149 for (const char & c : m_string) |
153 for (int i = 0; i < length(); ++i) |
150 if (c == needle) |
154 { |
151 needles++; |
155 if (m_string[i] == needle) |
152 |
156 result++; |
153 return needles; |
157 } |
|
158 |
|
159 return result; |
154 } |
160 } |
155 |
161 |
156 // ------------------------------------------------------------------------------------------------- |
162 // ------------------------------------------------------------------------------------------------- |
157 // |
163 // |
158 String String::mid (long a, long b) const |
164 String String::mid (long a, long b) const |