Mon, 03 Mar 2014 17:02:38 +0200
- reserved 'constexpr' as a keyword because I know I will need it someday
88 | 1 | /* |
2 | Copyright 2012-2014 Santeri Piippo | |
3 | All rights reserved. | |
4 | ||
5 | Redistribution and use in source and binary forms, with or without | |
6 | modification, are permitted provided that the following conditions | |
7 | are met: | |
8 | ||
9 | 1. Redistributions of source code must retain the above copyright | |
10 | notice, this list of conditions and the following disclaimer. | |
11 | 2. Redistributions in binary form must reproduce the above copyright | |
12 | notice, this list of conditions and the following disclaimer in the | |
13 | documentation and/or other materials provided with the distribution. | |
14 | 3. The name of the author may not be used to endorse or promote products | |
15 | derived from this software without specific prior written permission. | |
16 | ||
17 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | |
18 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |
19 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | |
20 | IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | |
21 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | |
22 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
23 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
24 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | |
26 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
27 | */ | |
28 | ||
29 | #include <cstring> | |
30 | #include "Main.h" | |
31 | #include "String.h" | |
32 | ||
33 | // ============================================================================= | |
34 | // | |
115
9be16e1c1e44
- reformatting... again
Teemu Piippo <crimsondusk64@gmail.com>
parents:
89
diff
changeset
|
35 | int String::compare (const String& other) const |
88 | 36 | { |
115
9be16e1c1e44
- reformatting... again
Teemu Piippo <crimsondusk64@gmail.com>
parents:
89
diff
changeset
|
37 | return m_string.compare (other.stdString()); |
88 | 38 | } |
39 | ||
40 | // ============================================================================= | |
41 | // | |
115
9be16e1c1e44
- reformatting... again
Teemu Piippo <crimsondusk64@gmail.com>
parents:
89
diff
changeset
|
42 | void String::trim (int n) |
88 | 43 | { |
44 | if (n > 0) | |
115
9be16e1c1e44
- reformatting... again
Teemu Piippo <crimsondusk64@gmail.com>
parents:
89
diff
changeset
|
45 | m_string = mid (0, length() - n).stdString(); |
88 | 46 | else |
115
9be16e1c1e44
- reformatting... again
Teemu Piippo <crimsondusk64@gmail.com>
parents:
89
diff
changeset
|
47 | m_string = mid (n, -1).stdString(); |
88 | 48 | } |
49 | ||
50 | // ============================================================================= | |
51 | // | |
115
9be16e1c1e44
- reformatting... again
Teemu Piippo <crimsondusk64@gmail.com>
parents:
89
diff
changeset
|
52 | String String::strip (const List< char >& unwanted) |
88 | 53 | { |
115
9be16e1c1e44
- reformatting... again
Teemu Piippo <crimsondusk64@gmail.com>
parents:
89
diff
changeset
|
54 | String copy (m_string); |
88 | 55 | |
56 | for (char c : unwanted) | |
115
9be16e1c1e44
- reformatting... again
Teemu Piippo <crimsondusk64@gmail.com>
parents:
89
diff
changeset
|
57 | for (int i = 0; i < copy.length(); ++i) |
88 | 58 | if (copy[i] == c) |
115
9be16e1c1e44
- reformatting... again
Teemu Piippo <crimsondusk64@gmail.com>
parents:
89
diff
changeset
|
59 | copy.removeAt (i); |
88 | 60 | |
61 | /* | |
89
029a330a9bef
- blargh. buffers weren't initialized properly
Teemu Piippo <crimsondusk64@gmail.com>
parents:
88
diff
changeset
|
62 | int pos = 0; |
029a330a9bef
- blargh. buffers weren't initialized properly
Teemu Piippo <crimsondusk64@gmail.com>
parents:
88
diff
changeset
|
63 | while ((pos = copy.First (c)) != -1) |
029a330a9bef
- blargh. buffers weren't initialized properly
Teemu Piippo <crimsondusk64@gmail.com>
parents:
88
diff
changeset
|
64 | copy.RemoveAt (pos--); |
88 | 65 | */ |
66 | ||
67 | return copy; | |
68 | } | |
69 | ||
70 | // ============================================================================= | |
71 | // | |
115
9be16e1c1e44
- reformatting... again
Teemu Piippo <crimsondusk64@gmail.com>
parents:
89
diff
changeset
|
72 | String String::toUppercase() const |
88 | 73 | { |
115
9be16e1c1e44
- reformatting... again
Teemu Piippo <crimsondusk64@gmail.com>
parents:
89
diff
changeset
|
74 | String newstr = m_string; |
88 | 75 | |
89
029a330a9bef
- blargh. buffers weren't initialized properly
Teemu Piippo <crimsondusk64@gmail.com>
parents:
88
diff
changeset
|
76 | for (char& c : newstr) |
88 | 77 | if (c >= 'a' && c <= 'z') |
78 | c -= 'a' - 'A'; | |
79 | ||
80 | return newstr; | |
81 | } | |
82 | ||
83 | // ============================================================================= | |
84 | // | |
115
9be16e1c1e44
- reformatting... again
Teemu Piippo <crimsondusk64@gmail.com>
parents:
89
diff
changeset
|
85 | String String::toLowercase() const |
88 | 86 | { |
115
9be16e1c1e44
- reformatting... again
Teemu Piippo <crimsondusk64@gmail.com>
parents:
89
diff
changeset
|
87 | String newstr = m_string; |
88 | 88 | |
89 | for (char & c : newstr) | |
90 | if (c >= 'A' && c <= 'Z') | |
91 | c += 'a' - 'A'; | |
92 | ||
93 | return newstr; | |
94 | } | |
95 | ||
96 | // ============================================================================= | |
97 | // | |
115
9be16e1c1e44
- reformatting... again
Teemu Piippo <crimsondusk64@gmail.com>
parents:
89
diff
changeset
|
98 | StringList String::split (char del) const |
88 | 99 | { |
100 | String delimstr; | |
101 | delimstr += del; | |
115
9be16e1c1e44
- reformatting... again
Teemu Piippo <crimsondusk64@gmail.com>
parents:
89
diff
changeset
|
102 | return split (delimstr); |
88 | 103 | } |
104 | ||
105 | // ============================================================================= | |
106 | // | |
115
9be16e1c1e44
- reformatting... again
Teemu Piippo <crimsondusk64@gmail.com>
parents:
89
diff
changeset
|
107 | StringList String::split (const String& del) const |
88 | 108 | { |
109 | StringList res; | |
110 | long a = 0; | |
111 | ||
112 | // Find all separators and store the text left to them. | |
113 | for (;;) | |
114 | { | |
115
9be16e1c1e44
- reformatting... again
Teemu Piippo <crimsondusk64@gmail.com>
parents:
89
diff
changeset
|
115 | long b = firstIndexOf (del, a); |
88 | 116 | |
117 | if (b == -1) | |
118 | break; | |
119 | ||
115
9be16e1c1e44
- reformatting... again
Teemu Piippo <crimsondusk64@gmail.com>
parents:
89
diff
changeset
|
120 | String sub = mid (a, b); |
88 | 121 | |
115
9be16e1c1e44
- reformatting... again
Teemu Piippo <crimsondusk64@gmail.com>
parents:
89
diff
changeset
|
122 | if (sub.length() > 0) |
9be16e1c1e44
- reformatting... again
Teemu Piippo <crimsondusk64@gmail.com>
parents:
89
diff
changeset
|
123 | res.append (mid (a, b)); |
88 | 124 | |
115
9be16e1c1e44
- reformatting... again
Teemu Piippo <crimsondusk64@gmail.com>
parents:
89
diff
changeset
|
125 | a = b + del.length(); |
88 | 126 | } |
127 | ||
128 | // Add the string at the right of the last separator | |
115
9be16e1c1e44
- reformatting... again
Teemu Piippo <crimsondusk64@gmail.com>
parents:
89
diff
changeset
|
129 | if (a < (int) length()) |
9be16e1c1e44
- reformatting... again
Teemu Piippo <crimsondusk64@gmail.com>
parents:
89
diff
changeset
|
130 | res.append (mid (a, length())); |
88 | 131 | |
132 | return res; | |
133 | } | |
134 | ||
135 | // ============================================================================= | |
136 | // | |
115
9be16e1c1e44
- reformatting... again
Teemu Piippo <crimsondusk64@gmail.com>
parents:
89
diff
changeset
|
137 | void String::replace (const char* a, const char* b) |
88 | 138 | { |
139 | long pos; | |
140 | ||
115
9be16e1c1e44
- reformatting... again
Teemu Piippo <crimsondusk64@gmail.com>
parents:
89
diff
changeset
|
141 | while ((pos = firstIndexOf (a)) != -1) |
9be16e1c1e44
- reformatting... again
Teemu Piippo <crimsondusk64@gmail.com>
parents:
89
diff
changeset
|
142 | m_string = m_string.replace (pos, strlen (a), b); |
88 | 143 | } |
144 | ||
145 | // ============================================================================= | |
146 | // | |
115
9be16e1c1e44
- reformatting... again
Teemu Piippo <crimsondusk64@gmail.com>
parents:
89
diff
changeset
|
147 | int String::count (char needle) const |
88 | 148 | { |
149 | int needles = 0; | |
150 | ||
115
9be16e1c1e44
- reformatting... again
Teemu Piippo <crimsondusk64@gmail.com>
parents:
89
diff
changeset
|
151 | for (const char & c : m_string) |
88 | 152 | if (c == needle) |
153 | needles++; | |
154 | ||
155 | return needles; | |
156 | } | |
157 | ||
158 | // ============================================================================= | |
159 | // | |
115
9be16e1c1e44
- reformatting... again
Teemu Piippo <crimsondusk64@gmail.com>
parents:
89
diff
changeset
|
160 | String String::mid (long a, long b) const |
88 | 161 | { |
162 | if (b == -1) | |
115
9be16e1c1e44
- reformatting... again
Teemu Piippo <crimsondusk64@gmail.com>
parents:
89
diff
changeset
|
163 | b = length(); |
88 | 164 | |
165 | if (b == a) | |
166 | return ""; | |
167 | ||
168 | if (b < a) | |
169 | { | |
170 | // Swap the variables | |
171 | int c = a; | |
172 | a = b; | |
173 | b = c; | |
174 | } | |
175 | ||
176 | char* newstr = new char[b - a + 1]; | |
115
9be16e1c1e44
- reformatting... again
Teemu Piippo <crimsondusk64@gmail.com>
parents:
89
diff
changeset
|
177 | strncpy (newstr, m_string.c_str() + a, b - a); |
88 | 178 | newstr[b - a] = '\0'; |
179 | ||
180 | String other (newstr); | |
181 | delete[] newstr; | |
182 | return other; | |
183 | } | |
184 | ||
185 | // ============================================================================= | |
186 | // | |
115
9be16e1c1e44
- reformatting... again
Teemu Piippo <crimsondusk64@gmail.com>
parents:
89
diff
changeset
|
187 | int String::wordPosition (int n) const |
88 | 188 | { |
189 | int count = 0; | |
190 | ||
115
9be16e1c1e44
- reformatting... again
Teemu Piippo <crimsondusk64@gmail.com>
parents:
89
diff
changeset
|
191 | for (int i = 0; i < length(); ++i) |
88 | 192 | { |
115
9be16e1c1e44
- reformatting... again
Teemu Piippo <crimsondusk64@gmail.com>
parents:
89
diff
changeset
|
193 | if (m_string[i] != ' ') |
88 | 194 | continue; |
195 | ||
196 | if (++count < n) | |
197 | continue; | |
198 | ||
199 | return i; | |
200 | } | |
201 | ||
202 | return -1; | |
203 | } | |
204 | ||
205 | // ============================================================================= | |
206 | // | |
115
9be16e1c1e44
- reformatting... again
Teemu Piippo <crimsondusk64@gmail.com>
parents:
89
diff
changeset
|
207 | int String::firstIndexOf (const char* c, int a) const |
88 | 208 | { |
115
9be16e1c1e44
- reformatting... again
Teemu Piippo <crimsondusk64@gmail.com>
parents:
89
diff
changeset
|
209 | for (; a < length(); a++) |
9be16e1c1e44
- reformatting... again
Teemu Piippo <crimsondusk64@gmail.com>
parents:
89
diff
changeset
|
210 | if (m_string[a] == c[0] && strncmp (m_string.c_str() + a, c, strlen (c)) == 0) |
88 | 211 | return a; |
212 | ||
213 | return -1; | |
214 | } | |
215 | ||
216 | // ============================================================================= | |
217 | // | |
115
9be16e1c1e44
- reformatting... again
Teemu Piippo <crimsondusk64@gmail.com>
parents:
89
diff
changeset
|
218 | int String::lastIndexOf (const char* c, int a) const |
88 | 219 | { |
115
9be16e1c1e44
- reformatting... again
Teemu Piippo <crimsondusk64@gmail.com>
parents:
89
diff
changeset
|
220 | if (a == -1 || a >= length()) |
9be16e1c1e44
- reformatting... again
Teemu Piippo <crimsondusk64@gmail.com>
parents:
89
diff
changeset
|
221 | a = length() - 1; |
88 | 222 | |
223 | for (; a > 0; a--) | |
115
9be16e1c1e44
- reformatting... again
Teemu Piippo <crimsondusk64@gmail.com>
parents:
89
diff
changeset
|
224 | if (m_string[a] == c[0] && strncmp (m_string.c_str() + a, c, strlen (c)) == 0) |
88 | 225 | return a; |
226 | ||
227 | return -1; | |
228 | } | |
229 | ||
230 | // ============================================================================= | |
231 | // | |
115
9be16e1c1e44
- reformatting... again
Teemu Piippo <crimsondusk64@gmail.com>
parents:
89
diff
changeset
|
232 | void String::dump() const |
88 | 233 | { |
115
9be16e1c1e44
- reformatting... again
Teemu Piippo <crimsondusk64@gmail.com>
parents:
89
diff
changeset
|
234 | print ("`%1`:\n", chars()); |
88 | 235 | int i = 0; |
236 | ||
115
9be16e1c1e44
- reformatting... again
Teemu Piippo <crimsondusk64@gmail.com>
parents:
89
diff
changeset
|
237 | for (char u : m_string) |
9be16e1c1e44
- reformatting... again
Teemu Piippo <crimsondusk64@gmail.com>
parents:
89
diff
changeset
|
238 | print ("\t%1. [%d2] `%3`\n", i++, u, String (u)); |
88 | 239 | } |
240 | ||
241 | // ============================================================================= | |
242 | // | |
115
9be16e1c1e44
- reformatting... again
Teemu Piippo <crimsondusk64@gmail.com>
parents:
89
diff
changeset
|
243 | long String::toLong (bool* ok, int base) const |
88 | 244 | { |
245 | errno = 0; | |
246 | char* endptr; | |
115
9be16e1c1e44
- reformatting... again
Teemu Piippo <crimsondusk64@gmail.com>
parents:
89
diff
changeset
|
247 | long i = strtol (m_string.c_str(), &endptr, base); |
88 | 248 | |
249 | if (ok) | |
250 | *ok = (errno == 0 && *endptr == '\0'); | |
251 | ||
252 | return i; | |
253 | } | |
254 | ||
255 | // ============================================================================= | |
256 | // | |
115
9be16e1c1e44
- reformatting... again
Teemu Piippo <crimsondusk64@gmail.com>
parents:
89
diff
changeset
|
257 | float String::toFloat (bool* ok) const |
88 | 258 | { |
259 | errno = 0; | |
260 | char* endptr; | |
115
9be16e1c1e44
- reformatting... again
Teemu Piippo <crimsondusk64@gmail.com>
parents:
89
diff
changeset
|
261 | float i = strtof (m_string.c_str(), &endptr); |
88 | 262 | |
263 | if (ok) | |
264 | *ok = (errno == 0 && *endptr == '\0'); | |
265 | ||
266 | return i; | |
267 | } | |
268 | ||
269 | // ============================================================================= | |
270 | // | |
115
9be16e1c1e44
- reformatting... again
Teemu Piippo <crimsondusk64@gmail.com>
parents:
89
diff
changeset
|
271 | double String::toDouble (bool* ok) const |
88 | 272 | { |
273 | errno = 0; | |
274 | char* endptr; | |
115
9be16e1c1e44
- reformatting... again
Teemu Piippo <crimsondusk64@gmail.com>
parents:
89
diff
changeset
|
275 | double i = strtod (m_string.c_str(), &endptr); |
88 | 276 | |
277 | if (ok) | |
278 | *ok = (errno == 0 && *endptr == '\0'); | |
279 | ||
280 | return i; | |
281 | } | |
282 | ||
283 | // ============================================================================= | |
284 | // | |
285 | String String::operator+ (const String& data) const | |
286 | { | |
287 | String newString = *this; | |
115
9be16e1c1e44
- reformatting... again
Teemu Piippo <crimsondusk64@gmail.com>
parents:
89
diff
changeset
|
288 | newString.append (data); |
88 | 289 | return newString; |
290 | } | |
291 | ||
292 | // ============================================================================= | |
293 | // | |
294 | String String::operator+ (const char* data) const | |
295 | { | |
296 | String newstr = *this; | |
115
9be16e1c1e44
- reformatting... again
Teemu Piippo <crimsondusk64@gmail.com>
parents:
89
diff
changeset
|
297 | newstr.append (data); |
88 | 298 | return newstr; |
299 | } | |
300 | ||
301 | // ============================================================================= | |
302 | // | |
115
9be16e1c1e44
- reformatting... again
Teemu Piippo <crimsondusk64@gmail.com>
parents:
89
diff
changeset
|
303 | bool String::isNumeric() const |
88 | 304 | { |
305 | bool gotDot = false; | |
306 | ||
115
9be16e1c1e44
- reformatting... again
Teemu Piippo <crimsondusk64@gmail.com>
parents:
89
diff
changeset
|
307 | for (const char & c : m_string) |
88 | 308 | { |
309 | // Allow leading hyphen for negatives | |
115
9be16e1c1e44
- reformatting... again
Teemu Piippo <crimsondusk64@gmail.com>
parents:
89
diff
changeset
|
310 | if (&c == &m_string[0] && c == '-') |
88 | 311 | continue; |
312 | ||
313 | // Check for decimal point | |
314 | if (!gotDot && c == '.') | |
315 | { | |
316 | gotDot = true; | |
317 | continue; | |
318 | } | |
319 | ||
320 | if (c >= '0' && c <= '9') | |
321 | continue; // Digit | |
322 | ||
323 | // If the above cases didn't catch this character, it was | |
324 | // illegal and this is therefore not a number. | |
325 | return false; | |
326 | } | |
327 | ||
328 | return true; | |
329 | } | |
330 | ||
331 | // ============================================================================= | |
332 | // | |
115
9be16e1c1e44
- reformatting... again
Teemu Piippo <crimsondusk64@gmail.com>
parents:
89
diff
changeset
|
333 | bool String::endsWith (const String& other) |
88 | 334 | { |
115
9be16e1c1e44
- reformatting... again
Teemu Piippo <crimsondusk64@gmail.com>
parents:
89
diff
changeset
|
335 | if (length() < other.length()) |
88 | 336 | return false; |
337 | ||
115
9be16e1c1e44
- reformatting... again
Teemu Piippo <crimsondusk64@gmail.com>
parents:
89
diff
changeset
|
338 | const int ofs = length() - other.length(); |
9be16e1c1e44
- reformatting... again
Teemu Piippo <crimsondusk64@gmail.com>
parents:
89
diff
changeset
|
339 | return strncmp (chars() + ofs, other.chars(), other.length()) == 0; |
88 | 340 | } |
341 | ||
342 | // ============================================================================= | |
343 | // | |
115
9be16e1c1e44
- reformatting... again
Teemu Piippo <crimsondusk64@gmail.com>
parents:
89
diff
changeset
|
344 | bool String::startsWith (const String& other) |
88 | 345 | { |
115
9be16e1c1e44
- reformatting... again
Teemu Piippo <crimsondusk64@gmail.com>
parents:
89
diff
changeset
|
346 | if (length() < other.length()) |
88 | 347 | return false; |
348 | ||
115
9be16e1c1e44
- reformatting... again
Teemu Piippo <crimsondusk64@gmail.com>
parents:
89
diff
changeset
|
349 | return strncmp (chars(), other.chars(), other.length()) == 0; |
88 | 350 | } |
351 | ||
352 | // ============================================================================= | |
353 | // | |
115
9be16e1c1e44
- reformatting... again
Teemu Piippo <crimsondusk64@gmail.com>
parents:
89
diff
changeset
|
354 | void String::sprintf (const char* fmtstr, ...) |
88 | 355 | { |
356 | char* buf; | |
357 | int bufsize = 256; | |
358 | va_list va; | |
359 | va_start (va, fmtstr); | |
360 | ||
361 | do | |
362 | buf = new char[bufsize]; | |
363 | while (vsnprintf (buf, bufsize, fmtstr, va) >= bufsize); | |
364 | ||
365 | va_end (va); | |
115
9be16e1c1e44
- reformatting... again
Teemu Piippo <crimsondusk64@gmail.com>
parents:
89
diff
changeset
|
366 | m_string = buf; |
88 | 367 | delete[] buf; |
368 | } | |
369 | ||
370 | // ============================================================================= | |
371 | // | |
115
9be16e1c1e44
- reformatting... again
Teemu Piippo <crimsondusk64@gmail.com>
parents:
89
diff
changeset
|
372 | String StringList::join (const String& delim) |
88 | 373 | { |
374 | String result; | |
375 | ||
115
9be16e1c1e44
- reformatting... again
Teemu Piippo <crimsondusk64@gmail.com>
parents:
89
diff
changeset
|
376 | for (const String& it : deque()) |
88 | 377 | { |
115
9be16e1c1e44
- reformatting... again
Teemu Piippo <crimsondusk64@gmail.com>
parents:
89
diff
changeset
|
378 | if (result.isEmpty() == false) |
88 | 379 | result += delim; |
380 | ||
381 | result += it; | |
382 | } | |
383 | ||
384 | return result; | |
385 | } | |
386 | ||
387 | // ============================================================================= | |
388 | // | |
115
9be16e1c1e44
- reformatting... again
Teemu Piippo <crimsondusk64@gmail.com>
parents:
89
diff
changeset
|
389 | bool String::maskAgainst (const String& pattern) const |
88 | 390 | { |
391 | // Elevate to uppercase for case-insensitive matching | |
115
9be16e1c1e44
- reformatting... again
Teemu Piippo <crimsondusk64@gmail.com>
parents:
89
diff
changeset
|
392 | String pattern_upper = pattern.toUppercase(); |
9be16e1c1e44
- reformatting... again
Teemu Piippo <crimsondusk64@gmail.com>
parents:
89
diff
changeset
|
393 | String this_upper = toUppercase(); |
9be16e1c1e44
- reformatting... again
Teemu Piippo <crimsondusk64@gmail.com>
parents:
89
diff
changeset
|
394 | const char* maskstring = pattern_upper.chars(); |
88 | 395 | const char* mptr = &maskstring[0]; |
396 | ||
115
9be16e1c1e44
- reformatting... again
Teemu Piippo <crimsondusk64@gmail.com>
parents:
89
diff
changeset
|
397 | for (const char* sptr = this_upper.chars(); *sptr != '\0'; sptr++) |
88 | 398 | { |
399 | if (*mptr == '?') | |
400 | { | |
401 | if (*(sptr + 1) == '\0') | |
402 | { | |
403 | // ? demands that there's a character here and there wasn't. | |
404 | // Therefore, mask matching fails | |
405 | return false; | |
406 | } | |
407 | } | |
408 | elif (*mptr == '*') | |
409 | { | |
410 | char end = *(++mptr); | |
411 | ||
412 | // If '*' is the final character of the message, all of the remaining | |
413 | // string matches against the '*'. We don't need to bother checking | |
414 | // the string any further. | |
415 | if (end == '\0') | |
416 | return true; | |
417 | ||
418 | // Skip to the end character | |
419 | while (*sptr != end && *sptr != '\0') | |
420 | sptr++; | |
421 | ||
422 | // String ended while the mask still had stuff | |
423 | if (*sptr == '\0') | |
424 | return false; | |
425 | } | |
426 | elif (*sptr != *mptr) | |
427 | return false; | |
428 | ||
429 | mptr++; | |
430 | } | |
431 | ||
432 | return true; | |
433 | } | |
434 | ||
435 | // ============================================================================= | |
436 | // | |
115
9be16e1c1e44
- reformatting... again
Teemu Piippo <crimsondusk64@gmail.com>
parents:
89
diff
changeset
|
437 | String String::fromNumber (int a) |
88 | 438 | { |
439 | char buf[32]; | |
115
9be16e1c1e44
- reformatting... again
Teemu Piippo <crimsondusk64@gmail.com>
parents:
89
diff
changeset
|
440 | ::sprintf (buf, "%d", a); |
88 | 441 | return String (buf); |
442 | } | |
443 | ||
444 | // ============================================================================= | |
445 | // | |
115
9be16e1c1e44
- reformatting... again
Teemu Piippo <crimsondusk64@gmail.com>
parents:
89
diff
changeset
|
446 | String String::fromNumber (long a) |
88 | 447 | { |
448 | char buf[32]; | |
115
9be16e1c1e44
- reformatting... again
Teemu Piippo <crimsondusk64@gmail.com>
parents:
89
diff
changeset
|
449 | ::sprintf (buf, "%ld", a); |
88 | 450 | return String (buf); |
451 | } |