Sat, 09 Jan 2016 02:20:28 +0200
CVar watching stuff works now, fixed compilation
1
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1 | /* |
73
07dda51a7a8e
Update license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents:
69
diff
changeset
|
2 | Copyright 2014, 2015 Teemu Piippo |
1
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
3 | All rights reserved. |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
4 | |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
5 | Redistribution and use in source and binary forms, with or without |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
6 | modification, are permitted provided that the following conditions |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
7 | are met: |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
8 | |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
9 | 1. Redistributions of source code must retain the above copyright |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
10 | notice, this list of conditions and the following disclaimer. |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
11 | 2. Redistributions in binary form must reproduce the above copyright |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
12 | notice, this list of conditions and the following disclaimer in the |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
13 | documentation and/or other materials provided with the distribution. |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
14 | 3. Neither the name of the copyright holder nor the names of its |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
15 | contributors may be used to endorse or promote products derived from |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
16 | this software without specific prior written permission. |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
17 | |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
19 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
20 | TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
21 | PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
22 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
23 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
24 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
25 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
26 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
27 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
29 | */ |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
30 | |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
31 | #include <cstring> |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
32 | #include "main.h" |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
33 | #include "mystring.h" |
10
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
5
diff
changeset
|
34 | #include "md5.h" |
1
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
35 | |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
36 | // ------------------------------------------------------------------------------------------------- |
5 | 37 | // |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
66
diff
changeset
|
38 | int String::compare (const String& other) const |
1
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
39 | { |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
40 | return m_string.compare (other.std_string()); |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
41 | } |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
42 | |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
43 | // ------------------------------------------------------------------------------------------------- |
5 | 44 | // |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
66
diff
changeset
|
45 | void String::trim (int n) |
1
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
46 | { |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
47 | if (n > 0) |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
48 | m_string = mid (0, length() - n).std_string(); |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
49 | else |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
50 | m_string = mid (n, -1).std_string(); |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
51 | } |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
52 | |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
53 | // ------------------------------------------------------------------------------------------------- |
5 | 54 | // |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
66
diff
changeset
|
55 | String String::strip (const List<char>& unwanted) |
1
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
56 | { |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
57 | String copy (m_string); |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
58 | |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
59 | for (char c : unwanted) |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
60 | { |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
61 | for (int pos = 0; (pos = copy.find (String (c))) != -1;) |
14
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
12
diff
changeset
|
62 | copy.remove_at (pos--); |
1
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
63 | } |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
64 | |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
65 | return copy; |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
66 | } |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
67 | |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
68 | // ------------------------------------------------------------------------------------------------- |
5 | 69 | // |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
66
diff
changeset
|
70 | String String::to_uppercase() const |
1
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
71 | { |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
72 | String newstr (m_string); |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
73 | |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
74 | for (char& c : newstr) |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
75 | { |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
76 | if (c >= 'a' and c <= 'z') |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
77 | c -= 'a' - 'A'; |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
78 | } |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
79 | |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
80 | return newstr; |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
81 | } |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
82 | |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
83 | // ------------------------------------------------------------------------------------------------- |
5 | 84 | // |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
66
diff
changeset
|
85 | String String::to_lowercase() const |
1
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
86 | { |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
87 | String newstr (m_string); |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
88 | |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
89 | for (char& c : newstr) |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
90 | { |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
91 | if (c >= 'A' and c <= 'Z') |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
92 | c += 'a' - 'A'; |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
93 | } |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
94 | |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
95 | return newstr; |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
96 | } |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
97 | |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
98 | // ------------------------------------------------------------------------------------------------- |
5 | 99 | // |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
66
diff
changeset
|
100 | StringList String::split (char del) const |
1
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
101 | { |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
102 | String delimstr; |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
103 | delimstr += del; |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
104 | return split (delimstr); |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
105 | } |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
106 | |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
107 | // ------------------------------------------------------------------------------------------------- |
5 | 108 | // |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
66
diff
changeset
|
109 | StringList String::split (const String& del) const |
1
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
110 | { |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
111 | StringList res; |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
112 | int a = 0; |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
113 | int b; |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
114 | |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
115 | // Find all separators and store the text left to them. |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
116 | while ((b = find (del, a)) != -1) |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
117 | { |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
118 | String sub = mid (a, b); |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
119 | |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
120 | if (sub.length() > 0) |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
121 | res << sub; |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
122 | |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
123 | a = b + del.length(); |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
124 | } |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
125 | |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
126 | // Add the string at the right of the last separator |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
127 | if (a < (int) length()) |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
128 | res.append (mid (a, length())); |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
129 | |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
130 | return res; |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
131 | } |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
132 | |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
133 | // ------------------------------------------------------------------------------------------------- |
5 | 134 | // |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
66
diff
changeset
|
135 | void String::replace (const char* a, const char* b) |
1
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
136 | { |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
137 | long pos; |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
138 | |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
139 | while ((pos = find (a)) != -1) |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
140 | m_string = m_string.replace (pos, strlen (a), b); |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
141 | } |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
142 | |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
143 | // ------------------------------------------------------------------------------------------------- |
5 | 144 | // |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
66
diff
changeset
|
145 | int String::count (char needle) const |
1
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
146 | { |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
147 | int needles = 0; |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
148 | |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
149 | for (const char & c : m_string) |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
150 | if (c == needle) |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
151 | needles++; |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
152 | |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
153 | return needles; |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
154 | } |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
155 | |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
156 | // ------------------------------------------------------------------------------------------------- |
5 | 157 | // |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
66
diff
changeset
|
158 | String String::mid (long a, long b) const |
1
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
159 | { |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
160 | if (b == -1 or b > length()) |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
161 | b = length(); |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
162 | |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
163 | if (b == a) |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
164 | return ""; |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
165 | |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
166 | if (b < a) |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
167 | swap (a, b); |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
168 | |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
169 | if (a == 0 and b == length()) |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
170 | return *this; |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
171 | |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
172 | char* newstr = new char[b - a + 1]; |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
173 | strncpy (newstr, chars() + a, b - a); |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
174 | newstr[b - a] = '\0'; |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
175 | String other (newstr); |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
176 | delete[] newstr; |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
177 | return other; |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
178 | } |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
179 | |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
180 | // ------------------------------------------------------------------------------------------------- |
5 | 181 | // |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
66
diff
changeset
|
182 | int String::word_position (int n) const |
1
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
183 | { |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
184 | int count = 0; |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
185 | |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
186 | for (int i = 0; i < length(); ++i) |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
187 | { |
5 | 188 | if (not isspace (m_string[i]) or ++count < n) |
1
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
189 | continue; |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
190 | |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
191 | return i; |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
192 | } |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
193 | |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
194 | return -1; |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
195 | } |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
196 | |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
197 | // ------------------------------------------------------------------------------------------------- |
5 | 198 | // |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
66
diff
changeset
|
199 | int String::find (const char* c, int a) const |
1
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
200 | { |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
201 | int pos = m_string.find (c, a); |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
202 | |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
203 | if (pos == int (std::string::npos)) |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
204 | return -1; |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
205 | |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
206 | return pos; |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
207 | } |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
208 | |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
209 | // ------------------------------------------------------------------------------------------------- |
5 | 210 | // |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
66
diff
changeset
|
211 | int String::find_last (const char* c, int a) const |
1
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
212 | { |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
213 | if (a == -1 or a >= length()) |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
214 | a = length() - 1; |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
215 | |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
216 | for (; a > 0; a--) |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
217 | if (m_string[a] == c[0] and strncmp (chars() + a, c, strlen (c)) == 0) |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
218 | return a; |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
219 | |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
220 | return -1; |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
221 | } |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
222 | |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
223 | // ------------------------------------------------------------------------------------------------- |
5 | 224 | // |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
66
diff
changeset
|
225 | long String::to_int (bool* ok, int base) const |
1
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
226 | { |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
227 | errno = 0; |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
228 | char* endptr; |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
229 | long i = strtol (chars(), &endptr, base); |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
230 | |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
231 | if (ok) |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
232 | *ok = (errno == 0 and *endptr == '\0'); |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
233 | |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
234 | return i; |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
235 | } |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
236 | |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
237 | // ------------------------------------------------------------------------------------------------- |
5 | 238 | // |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
66
diff
changeset
|
239 | float String::to_float (bool* ok) const |
1
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
240 | { |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
241 | errno = 0; |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
242 | char* endptr; |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
243 | float i = strtof (chars(), &endptr); |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
244 | |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
245 | if (ok != nullptr) |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
246 | *ok = (errno == 0 and *endptr == '\0'); |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
247 | |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
248 | return i; |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
249 | } |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
250 | |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
251 | // ------------------------------------------------------------------------------------------------- |
5 | 252 | // |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
66
diff
changeset
|
253 | double String::to_double (bool* ok) const |
1
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
254 | { |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
255 | errno = 0; |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
256 | char* endptr; |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
257 | double i = strtod (chars(), &endptr); |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
258 | |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
259 | if (ok != nullptr) |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
260 | *ok = (errno == 0 and *endptr == '\0'); |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
261 | |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
262 | return i; |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
263 | } |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
264 | |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
265 | // ------------------------------------------------------------------------------------------------- |
5 | 266 | // |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
66
diff
changeset
|
267 | String String::operator+ (const String& data) const |
1
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
268 | { |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
269 | String newString = *this; |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
270 | newString.append (data); |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
271 | return newString; |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
272 | } |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
273 | |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
274 | // ------------------------------------------------------------------------------------------------- |
5 | 275 | // |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
66
diff
changeset
|
276 | String String::operator+ (const char* data) const |
1
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
277 | { |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
278 | String newstr = *this; |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
279 | newstr.append (data); |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
280 | return newstr; |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
281 | } |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
282 | |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
283 | // ------------------------------------------------------------------------------------------------- |
5 | 284 | // |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
66
diff
changeset
|
285 | bool String::is_numeric() const |
1
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
286 | { |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
66
diff
changeset
|
287 | char* endptr; |
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
66
diff
changeset
|
288 | strtol (chars(), &endptr, 10); |
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
66
diff
changeset
|
289 | return not (endptr && *endptr); |
1
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
290 | } |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
291 | |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
292 | // ------------------------------------------------------------------------------------------------- |
5 | 293 | // |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
66
diff
changeset
|
294 | bool String::ends_with (const String& other) |
1
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
295 | { |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
296 | if (length() < other.length()) |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
297 | return false; |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
298 | |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
299 | const int ofs = length() - other.length(); |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
300 | return strncmp (chars() + ofs, other.chars(), other.length()) == 0; |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
301 | } |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
302 | |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
303 | // ------------------------------------------------------------------------------------------------- |
5 | 304 | // |
79
62cfb7b97fc0
Added rudimentary support for CVar watch (only as a debug command for now)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
73
diff
changeset
|
305 | bool String::starts_with (const String& other) const |
1
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
306 | { |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
307 | if (length() < other.length()) |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
308 | return false; |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
309 | |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
310 | return strncmp (chars(), other.chars(), other.length()) == 0; |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
311 | } |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
312 | |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
313 | // ------------------------------------------------------------------------------------------------- |
5 | 314 | // |
83
08bfc3d9d2ae
Removed format.cpp and format.h, use built-in formatting instead
Teemu Piippo <crimsondusk64@gmail.com>
parents:
73
diff
changeset
|
315 | void __cdecl String::sprintf (const char* fmtstr, ...) |
08bfc3d9d2ae
Removed format.cpp and format.h, use built-in formatting instead
Teemu Piippo <crimsondusk64@gmail.com>
parents:
73
diff
changeset
|
316 | { |
08bfc3d9d2ae
Removed format.cpp and format.h, use built-in formatting instead
Teemu Piippo <crimsondusk64@gmail.com>
parents:
73
diff
changeset
|
317 | va_list args; |
08bfc3d9d2ae
Removed format.cpp and format.h, use built-in formatting instead
Teemu Piippo <crimsondusk64@gmail.com>
parents:
73
diff
changeset
|
318 | va_start (args, fmtstr); |
08bfc3d9d2ae
Removed format.cpp and format.h, use built-in formatting instead
Teemu Piippo <crimsondusk64@gmail.com>
parents:
73
diff
changeset
|
319 | this->vsprintf (fmtstr, args); |
08bfc3d9d2ae
Removed format.cpp and format.h, use built-in formatting instead
Teemu Piippo <crimsondusk64@gmail.com>
parents:
73
diff
changeset
|
320 | va_end (args); |
08bfc3d9d2ae
Removed format.cpp and format.h, use built-in formatting instead
Teemu Piippo <crimsondusk64@gmail.com>
parents:
73
diff
changeset
|
321 | } |
08bfc3d9d2ae
Removed format.cpp and format.h, use built-in formatting instead
Teemu Piippo <crimsondusk64@gmail.com>
parents:
73
diff
changeset
|
322 | |
08bfc3d9d2ae
Removed format.cpp and format.h, use built-in formatting instead
Teemu Piippo <crimsondusk64@gmail.com>
parents:
73
diff
changeset
|
323 | // ------------------------------------------------------------------------------------------------- |
08bfc3d9d2ae
Removed format.cpp and format.h, use built-in formatting instead
Teemu Piippo <crimsondusk64@gmail.com>
parents:
73
diff
changeset
|
324 | // |
08bfc3d9d2ae
Removed format.cpp and format.h, use built-in formatting instead
Teemu Piippo <crimsondusk64@gmail.com>
parents:
73
diff
changeset
|
325 | void String::vsprintf (const char* fmtstr, va_list args) |
1
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
326 | { |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
66
diff
changeset
|
327 | char* buf = nullptr; |
1
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
328 | int bufsize = 256; |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
329 | |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
330 | do |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
66
diff
changeset
|
331 | { |
83
08bfc3d9d2ae
Removed format.cpp and format.h, use built-in formatting instead
Teemu Piippo <crimsondusk64@gmail.com>
parents:
73
diff
changeset
|
332 | bufsize *= 2; |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
66
diff
changeset
|
333 | delete[] buf; |
1
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
334 | buf = new char[bufsize]; |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
66
diff
changeset
|
335 | } |
83
08bfc3d9d2ae
Removed format.cpp and format.h, use built-in formatting instead
Teemu Piippo <crimsondusk64@gmail.com>
parents:
73
diff
changeset
|
336 | while (vsnprintf (buf, bufsize, fmtstr, args) >= bufsize); |
1
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
337 | |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
338 | m_string = buf; |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
339 | delete[] buf; |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
340 | } |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
341 | |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
342 | // ------------------------------------------------------------------------------------------------- |
5 | 343 | // |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
66
diff
changeset
|
344 | String StringList::join (const String& delim) |
1
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
345 | { |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
346 | String result; |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
347 | |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
348 | for (const String& it : container()) |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
349 | { |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
350 | if (result.is_empty() == false) |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
351 | result += delim; |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
352 | |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
353 | result += it; |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
354 | } |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
355 | |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
356 | return result; |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
357 | } |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
358 | |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
359 | // ------------------------------------------------------------------------------------------------- |
5 | 360 | // |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
66
diff
changeset
|
361 | bool String::mask_against (const String& pattern) const |
1
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
362 | { |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
363 | // Elevate to uppercase for case-insensitive matching |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
364 | String pattern_upper = pattern.to_uppercase(); |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
365 | String this_upper = to_uppercase(); |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
366 | const char* maskstring = pattern_upper.chars(); |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
367 | const char* mptr = &maskstring[0]; |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
368 | |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
369 | for (const char* sptr = this_upper.chars(); *sptr != '\0'; sptr++) |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
370 | { |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
371 | if (*mptr == '?') |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
372 | { |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
373 | if (*(sptr + 1) == '\0') |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
374 | { |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
375 | // ? demands that there's a character here and there wasn't. |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
376 | // Therefore, mask matching fails |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
377 | return false; |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
378 | } |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
379 | } |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
380 | else if (*mptr == '*') |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
381 | { |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
382 | char end = *(++mptr); |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
383 | |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
384 | // If '*' is the final character of the message, all of the remaining |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
385 | // string matches against the '*'. We don't need to bother checking |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
386 | // the string any further. |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
387 | if (end == '\0') |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
388 | return true; |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
389 | |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
390 | // Skip to the end character |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
391 | while (*sptr != end and *sptr != '\0') |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
392 | sptr++; |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
393 | |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
394 | // String ended while the mask still had stuff |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
395 | if (*sptr == '\0') |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
396 | return false; |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
397 | } |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
398 | else if (*sptr != *mptr) |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
399 | return false; |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
400 | |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
401 | mptr++; |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
402 | } |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
403 | |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
404 | return true; |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
405 | } |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
406 | |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
407 | // ------------------------------------------------------------------------------------------------- |
5 | 408 | // |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
66
diff
changeset
|
409 | String String::from_number (short int a) |
66
bd28a5730fd0
- fixed: had problems with integral overloading under 32-bit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
410 | { |
bd28a5730fd0
- fixed: had problems with integral overloading under 32-bit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
411 | char buf[32]; |
bd28a5730fd0
- fixed: had problems with integral overloading under 32-bit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
412 | ::sprintf (buf, "%d", a); |
bd28a5730fd0
- fixed: had problems with integral overloading under 32-bit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
413 | return String (buf); |
bd28a5730fd0
- fixed: had problems with integral overloading under 32-bit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
414 | } |
bd28a5730fd0
- fixed: had problems with integral overloading under 32-bit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
415 | |
bd28a5730fd0
- fixed: had problems with integral overloading under 32-bit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
416 | // ------------------------------------------------------------------------------------------------- |
bd28a5730fd0
- fixed: had problems with integral overloading under 32-bit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
417 | // |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
66
diff
changeset
|
418 | String String::from_number (int a) |
1
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
419 | { |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
420 | char buf[32]; |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
421 | ::sprintf (buf, "%d", a); |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
422 | return String (buf); |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
423 | } |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
424 | |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
425 | // ------------------------------------------------------------------------------------------------- |
5 | 426 | // |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
66
diff
changeset
|
427 | String String::from_number (long int a) |
1
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
428 | { |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
429 | char buf[32]; |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
430 | ::sprintf (buf, "%ld", a); |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
431 | return String (buf); |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
432 | } |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
433 | |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
434 | // ------------------------------------------------------------------------------------------------- |
5 | 435 | // |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
66
diff
changeset
|
436 | String String::from_number (unsigned short int a) |
66
bd28a5730fd0
- fixed: had problems with integral overloading under 32-bit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
437 | { |
bd28a5730fd0
- fixed: had problems with integral overloading under 32-bit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
438 | char buf[32]; |
bd28a5730fd0
- fixed: had problems with integral overloading under 32-bit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
439 | ::sprintf (buf, "%u", a); |
bd28a5730fd0
- fixed: had problems with integral overloading under 32-bit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
440 | return String (buf); |
bd28a5730fd0
- fixed: had problems with integral overloading under 32-bit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
441 | } |
bd28a5730fd0
- fixed: had problems with integral overloading under 32-bit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
442 | |
bd28a5730fd0
- fixed: had problems with integral overloading under 32-bit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
443 | // ------------------------------------------------------------------------------------------------- |
bd28a5730fd0
- fixed: had problems with integral overloading under 32-bit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
444 | // |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
66
diff
changeset
|
445 | String String::from_number (unsigned int a) |
66
bd28a5730fd0
- fixed: had problems with integral overloading under 32-bit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
446 | { |
bd28a5730fd0
- fixed: had problems with integral overloading under 32-bit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
447 | char buf[32]; |
bd28a5730fd0
- fixed: had problems with integral overloading under 32-bit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
448 | ::sprintf (buf, "%u", a); |
bd28a5730fd0
- fixed: had problems with integral overloading under 32-bit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
449 | return String (buf); |
bd28a5730fd0
- fixed: had problems with integral overloading under 32-bit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
450 | } |
bd28a5730fd0
- fixed: had problems with integral overloading under 32-bit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
451 | |
bd28a5730fd0
- fixed: had problems with integral overloading under 32-bit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
452 | // ------------------------------------------------------------------------------------------------- |
bd28a5730fd0
- fixed: had problems with integral overloading under 32-bit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
453 | // |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
66
diff
changeset
|
454 | String String::from_number (unsigned long int a) |
1
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
455 | { |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
456 | char buf[32]; |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
457 | ::sprintf (buf, "%lu", a); |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
458 | return String (buf); |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
459 | } |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
460 | |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
461 | // ------------------------------------------------------------------------------------------------- |
5 | 462 | // |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
66
diff
changeset
|
463 | String String::from_number (double a) |
1
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
464 | { |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
465 | char buf[64]; |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
466 | ::sprintf (buf, "%f", a); |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
467 | return String (buf); |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
468 | } |
10
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
5
diff
changeset
|
469 | |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
5
diff
changeset
|
470 | // ------------------------------------------------------------------------------------------------- |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
5
diff
changeset
|
471 | // |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
66
diff
changeset
|
472 | String String::md5() const |
10
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
5
diff
changeset
|
473 | { |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
5
diff
changeset
|
474 | char checksum[33]; |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
5
diff
changeset
|
475 | CalculateMD5 (reinterpret_cast<const unsigned char*> (chars()), length(), checksum); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
5
diff
changeset
|
476 | checksum[sizeof checksum - 1] = '\0'; |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
5
diff
changeset
|
477 | return String (checksum); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
5
diff
changeset
|
478 | } |
12
8d0d1b368de0
- rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
10
diff
changeset
|
479 | |
8d0d1b368de0
- rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
10
diff
changeset
|
480 | // ------------------------------------------------------------------------------------------------- |
8d0d1b368de0
- rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
10
diff
changeset
|
481 | // |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
66
diff
changeset
|
482 | void String::normalize (int (*filter)(int)) |
12
8d0d1b368de0
- rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
10
diff
changeset
|
483 | { |
8d0d1b368de0
- rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
10
diff
changeset
|
484 | int a = 0; |
8d0d1b368de0
- rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
10
diff
changeset
|
485 | int b = length() - 1; |
8d0d1b368de0
- rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
10
diff
changeset
|
486 | |
8d0d1b368de0
- rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
10
diff
changeset
|
487 | while ((*filter) (m_string[a]) and a != b) |
8d0d1b368de0
- rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
10
diff
changeset
|
488 | ++a; |
8d0d1b368de0
- rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
10
diff
changeset
|
489 | |
8d0d1b368de0
- rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
10
diff
changeset
|
490 | while ((*filter) (m_string[b]) and a != b) |
8d0d1b368de0
- rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
10
diff
changeset
|
491 | --b; |
8d0d1b368de0
- rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
10
diff
changeset
|
492 | |
8d0d1b368de0
- rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
10
diff
changeset
|
493 | if (a == b) |
8d0d1b368de0
- rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
10
diff
changeset
|
494 | m_string = ""; |
8d0d1b368de0
- rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
10
diff
changeset
|
495 | else if (a != 0 or b != length() - 1) |
8d0d1b368de0
- rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
10
diff
changeset
|
496 | m_string = m_string.substr (a, b - a + 1); |
8d0d1b368de0
- rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
10
diff
changeset
|
497 | } |
103
b78c0ca832a9
CVar watching stuff works now, fixed compilation
Teemu Piippo <crimsondusk64@gmail.com>
parents:
84
diff
changeset
|
498 | |
b78c0ca832a9
CVar watching stuff works now, fixed compilation
Teemu Piippo <crimsondusk64@gmail.com>
parents:
84
diff
changeset
|
499 | // ------------------------------------------------------------------------------------------------- |
b78c0ca832a9
CVar watching stuff works now, fixed compilation
Teemu Piippo <crimsondusk64@gmail.com>
parents:
84
diff
changeset
|
500 | // |
b78c0ca832a9
CVar watching stuff works now, fixed compilation
Teemu Piippo <crimsondusk64@gmail.com>
parents:
84
diff
changeset
|
501 | String String::normalized (int (*filter)(int)) const |
b78c0ca832a9
CVar watching stuff works now, fixed compilation
Teemu Piippo <crimsondusk64@gmail.com>
parents:
84
diff
changeset
|
502 | { |
b78c0ca832a9
CVar watching stuff works now, fixed compilation
Teemu Piippo <crimsondusk64@gmail.com>
parents:
84
diff
changeset
|
503 | String result = *this; |
b78c0ca832a9
CVar watching stuff works now, fixed compilation
Teemu Piippo <crimsondusk64@gmail.com>
parents:
84
diff
changeset
|
504 | result.normalize(filter); |
b78c0ca832a9
CVar watching stuff works now, fixed compilation
Teemu Piippo <crimsondusk64@gmail.com>
parents:
84
diff
changeset
|
505 | return result; |
b78c0ca832a9
CVar watching stuff works now, fixed compilation
Teemu Piippo <crimsondusk64@gmail.com>
parents:
84
diff
changeset
|
506 | } |