170 abort (); |
170 abort (); |
171 } |
171 } |
172 |
172 |
173 return sub; |
173 return sub; |
174 } |
174 } |
|
175 |
|
176 // ============================================================================ |
|
177 int String::first (const char* c, int a) const { |
|
178 unsigned int r = 0; |
|
179 unsigned int index = 0; |
|
180 for (; a < len (); a++) { |
|
181 if (m_string[a] == c[r]) { |
|
182 if (r == 0) |
|
183 index = a; |
|
184 |
|
185 r++; |
|
186 if (r == strlen (c)) |
|
187 return index; |
|
188 } else { |
|
189 if (r != 0) { |
|
190 // If the string sequence broke at this point, we need to |
|
191 // check this character again, for a new sequence just |
|
192 // might start right here. |
|
193 a--; |
|
194 } |
|
195 |
|
196 r = 0; |
|
197 } |
|
198 } |
|
199 |
|
200 return -1; |
|
201 } |
|
202 |
|
203 // ============================================================================ |
|
204 int String::last (const char* c, int a) const { |
|
205 if (a == -1) |
|
206 a = len(); |
|
207 |
|
208 int max = strlen (c) - 1; |
|
209 |
|
210 int r = max; |
|
211 for (; a >= 0; a--) { |
|
212 if (m_string[a] == c[r]) { |
|
213 r--; |
|
214 if (r == -1) |
|
215 return a; |
|
216 } else { |
|
217 if (r != max) |
|
218 a++; |
|
219 |
|
220 r = max; |
|
221 } |
|
222 } |
|
223 |
|
224 return -1; |
|
225 } |