sources/mystring.cpp

Thu, 11 Dec 2014 05:58:55 +0200

author
Teemu Piippo <crimsondusk64@gmail.com>
date
Thu, 11 Dec 2014 05:58:55 +0200
changeset 5
146825d63b9a
parent 1
4dd5bde4e777
child 10
3874575d924d
permissions
-rw-r--r--

- code cleanup
- added network-related classes (bytestream, ipaddress, udp socket)

1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1 /*
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
2 Copyright 2014 Teemu Piippo
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"
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
34 #include "format.h"
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
146825d63b9a - code cleanup
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1
diff changeset
37 //
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
38 METHOD
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
39 String::compare (const String& other) const -> int
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
40 {
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
41 return m_string.compare (other.std_string());
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
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
44 // -------------------------------------------------------------------------------------------------
5
146825d63b9a - code cleanup
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1
diff changeset
45 //
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
46 METHOD
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
47 String::trim (int n) -> void
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
48 {
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
49 if (n > 0)
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
50 m_string = mid (0, length() - n).std_string();
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
51 else
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
52 m_string = mid (n, -1).std_string();
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
53 }
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
54
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
55 // -------------------------------------------------------------------------------------------------
5
146825d63b9a - code cleanup
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1
diff changeset
56 //
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
57 METHOD
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
58 String::strip (const List<char>& unwanted) -> String
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
59 {
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
60 String copy (m_string);
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
61
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
62 for (char c : unwanted)
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 for (int pos = 0; (pos = copy.find (String (c))) != -1;)
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
65 copy.remove (pos--);
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 return copy;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
69 }
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
70
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
71 // -------------------------------------------------------------------------------------------------
5
146825d63b9a - code cleanup
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1
diff changeset
72 //
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
73 METHOD
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
74 String::to_uppercase() const -> String
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 String newstr (m_string);
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
77
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
78 for (char& c : newstr)
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 if (c >= 'a' and c <= 'z')
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
81 c -= 'a' - 'A';
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
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
84 return newstr;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
85 }
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 // -------------------------------------------------------------------------------------------------
5
146825d63b9a - code cleanup
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1
diff changeset
88 //
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
89 METHOD
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
90 String::to_lowercase() const -> String
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
91 {
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
92 String newstr (m_string);
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 for (char& c : newstr)
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
95 {
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
96 if (c >= 'A' and c <= 'Z')
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
97 c += 'a' - 'A';
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
98 }
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
99
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
100 return newstr;
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
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
103 // -------------------------------------------------------------------------------------------------
5
146825d63b9a - code cleanup
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1
diff changeset
104 //
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
105 METHOD
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
106 String::split (char del) const -> StringList
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
107 {
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
108 String delimstr;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
109 delimstr += del;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
110 return split (delimstr);
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
111 }
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
112
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
113 // -------------------------------------------------------------------------------------------------
5
146825d63b9a - code cleanup
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1
diff changeset
114 //
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
115 METHOD
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
116 String::split (const String& del) const -> StringList
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 StringList res;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
119 int a = 0;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
120 int b;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
121
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
122 // 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
123 while ((b = find (del, a)) != -1)
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 String sub = mid (a, b);
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
126
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
127 if (sub.length() > 0)
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
128 res << sub;
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 a = b + del.length();
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 // 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
134 if (a < (int) length())
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
135 res.append (mid (a, length()));
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 return res;
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
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
140 // -------------------------------------------------------------------------------------------------
5
146825d63b9a - code cleanup
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1
diff changeset
141 //
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
142 METHOD
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
143 String::replace (const char* a, const char* b) -> void
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
144 {
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
145 long pos;
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 while ((pos = find (a)) != -1)
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
148 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
149 }
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
150
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
151 // -------------------------------------------------------------------------------------------------
5
146825d63b9a - code cleanup
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1
diff changeset
152 //
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
153 METHOD
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
154 String::count (char needle) const -> int
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 int needles = 0;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
157
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
158 for (const char & c : m_string)
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
159 if (c == needle)
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
160 needles++;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
161
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
162 return needles;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
163 }
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
164
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
165 // -------------------------------------------------------------------------------------------------
5
146825d63b9a - code cleanup
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1
diff changeset
166 //
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
167 METHOD
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
168 String::mid (long a, long b) const -> String
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
169 {
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
170 if (b == -1 or b > length())
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
171 b = length();
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
172
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
173 if (b == a)
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
174 return "";
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
175
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
176 if (b < a)
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
177 swap (a, b);
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 if (a == 0 and b == length())
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
180 return *this;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
181
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
182 char* newstr = new char[b - a + 1];
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
183 strncpy (newstr, chars() + a, b - a);
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
184 newstr[b - a] = '\0';
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
185 String other (newstr);
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
186 delete[] newstr;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
187 return other;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
188 }
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
189
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
190 // -------------------------------------------------------------------------------------------------
5
146825d63b9a - code cleanup
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1
diff changeset
191 //
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
192 METHOD
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
193 String::word_position (int n) const -> int
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
194 {
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
195 int count = 0;
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 for (int i = 0; i < length(); ++i)
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
198 {
5
146825d63b9a - code cleanup
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1
diff changeset
199 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
200 continue;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
201
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
202 return i;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
203 }
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
204
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
205 return -1;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
206 }
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 // -------------------------------------------------------------------------------------------------
5
146825d63b9a - code cleanup
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1
diff changeset
209 //
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
210 METHOD
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
211 String::find (const char* c, int a) const -> int
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 int pos = m_string.find (c, a);
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
214
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
215 if (pos == int (std::string::npos))
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
216 return -1;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
217
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
218 return pos;
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
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
221 // -------------------------------------------------------------------------------------------------
5
146825d63b9a - code cleanup
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1
diff changeset
222 //
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
223 METHOD
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
224 String::find_last (const char* c, int a) const -> int
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
225 {
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
226 if (a == -1 or a >= length())
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
227 a = length() - 1;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
228
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
229 for (; a > 0; a--)
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
230 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
231 return a;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
232
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
233 return -1;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
234 }
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 // -------------------------------------------------------------------------------------------------
5
146825d63b9a - code cleanup
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1
diff changeset
237 //
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
238 METHOD
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
239 String::to_int (bool* ok, int base) const -> long
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 long i = strtol (chars(), &endptr, base);
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)
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
146825d63b9a - code cleanup
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1
diff changeset
252 //
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
253 METHOD
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
254 String::to_float (bool* ok) const -> float
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
255 {
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
256 errno = 0;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
257 char* endptr;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
258 float i = strtof (chars(), &endptr);
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
259
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
260 if (ok != nullptr)
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
261 *ok = (errno == 0 and *endptr == '\0');
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
262
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
263 return i;
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
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
266 // -------------------------------------------------------------------------------------------------
5
146825d63b9a - code cleanup
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1
diff changeset
267 //
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
268 METHOD
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
269 String::to_double (bool* ok) const -> double
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
270 {
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
271 errno = 0;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
272 char* endptr;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
273 double i = strtod (chars(), &endptr);
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
274
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
275 if (ok != nullptr)
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
276 *ok = (errno == 0 and *endptr == '\0');
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 return i;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
279 }
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
280
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
281 // -------------------------------------------------------------------------------------------------
5
146825d63b9a - code cleanup
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1
diff changeset
282 //
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
283 METHOD
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
284 String::operator+ (const String& data) const -> String
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
285 {
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
286 String newString = *this;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
287 newString.append (data);
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
288 return newString;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
289 }
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 // -------------------------------------------------------------------------------------------------
5
146825d63b9a - code cleanup
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1
diff changeset
292 //
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
293 METHOD
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
294 String::operator+ (const char* data) const -> String
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 String newstr = *this;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
297 newstr.append (data);
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
298 return newstr;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
299 }
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
300
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
301 // -------------------------------------------------------------------------------------------------
5
146825d63b9a - code cleanup
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1
diff changeset
302 //
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
303 METHOD
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
304 String::is_numeric() const -> bool
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
305 {
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
306 bool gotDot = false;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
307
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
308 for (const char & c : m_string)
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 // Allow leading hyphen for negatives
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
311 if (&c == &m_string[0] and c == '-')
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
312 continue;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
313
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
314 // Check for decimal point
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
315 if (!gotDot and c == '.')
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
316 {
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
317 gotDot = true;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
318 continue;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
319 }
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
320
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
321 if (c >= '0' and c <= '9')
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
322 continue; // Digit
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
323
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
324 // If the above cases didn't catch this character, it was
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
325 // illegal and this is therefore not a number.
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
326 return false;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
327 }
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
328
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
329 return true;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
330 }
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
331
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
332 // -------------------------------------------------------------------------------------------------
5
146825d63b9a - code cleanup
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1
diff changeset
333 //
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
334 METHOD
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
335 String::ends_with (const String& other) -> bool
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
336 {
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
337 if (length() < other.length())
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
338 return false;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
339
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
340 const int ofs = length() - other.length();
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
341 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
342 }
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
343
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
344 // -------------------------------------------------------------------------------------------------
5
146825d63b9a - code cleanup
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1
diff changeset
345 //
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
346 METHOD
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
347 String::starts_with (const String& other) -> bool
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
348 {
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
349 if (length() < other.length())
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
350 return false;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
351
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
352 return strncmp (chars(), other.chars(), other.length()) == 0;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
353 }
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 // -------------------------------------------------------------------------------------------------
5
146825d63b9a - code cleanup
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1
diff changeset
356 //
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
357 METHOD
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
358 String::sprintf (const char* fmtstr, ...) -> void
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
359 {
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
360 char* buf;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
361 int bufsize = 256;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
362 va_list va;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
363 va_start (va, fmtstr);
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
364
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
365 do
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
366 buf = new char[bufsize];
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
367 while (vsnprintf (buf, bufsize, fmtstr, va) >= bufsize);
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 va_end (va);
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
370 m_string = buf;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
371 delete[] buf;
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
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
374 // -------------------------------------------------------------------------------------------------
5
146825d63b9a - code cleanup
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1
diff changeset
375 //
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
376 METHOD
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
377 StringList::join (const String& delim) -> String
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 String result;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
380
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
381 for (const String& it : container())
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
382 {
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
383 if (result.is_empty() == false)
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
384 result += delim;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
385
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
386 result += it;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
387 }
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
388
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
389 return result;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
390 }
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
391
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
392 // -------------------------------------------------------------------------------------------------
5
146825d63b9a - code cleanup
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1
diff changeset
393 //
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
394 METHOD
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
395 String::mask_against (const String& pattern) const -> bool
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
396 {
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
397 // Elevate to uppercase for case-insensitive matching
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
398 String pattern_upper = pattern.to_uppercase();
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
399 String this_upper = to_uppercase();
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
400 const char* maskstring = pattern_upper.chars();
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
401 const char* mptr = &maskstring[0];
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 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
404 {
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
405 if (*mptr == '?')
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 if (*(sptr + 1) == '\0')
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
408 {
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
409 // ? 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
410 // Therefore, mask matching fails
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
411 return false;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
412 }
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
413 }
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
414 else if (*mptr == '*')
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
415 {
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
416 char end = *(++mptr);
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
417
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
418 // 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
419 // 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
420 // the string any further.
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
421 if (end == '\0')
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
422 return true;
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 // Skip to the end character
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
425 while (*sptr != end and *sptr != '\0')
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
426 sptr++;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
427
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
428 // String ended while the mask still had stuff
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
429 if (*sptr == '\0')
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
430 return false;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
431 }
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
432 else if (*sptr != *mptr)
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
433 return false;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
434
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
435 mptr++;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
436 }
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
437
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
438 return true;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
439 }
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
440
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
441 // -------------------------------------------------------------------------------------------------
5
146825d63b9a - code cleanup
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1
diff changeset
442 //
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
443 METHOD
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
444 String::from_number (int a) -> String
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
445 {
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
446 char buf[32];
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
447 ::sprintf (buf, "%d", a);
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
448 return String (buf);
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
449 }
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
450
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
451 // -------------------------------------------------------------------------------------------------
5
146825d63b9a - code cleanup
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1
diff changeset
452 //
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
453 METHOD
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
454 String::from_number (long a) -> String
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, "%ld", 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
146825d63b9a - code cleanup
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1
diff changeset
462 //
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
463 METHOD
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
464 String::from_number (unsigned long a) -> String
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
465 {
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
466 char buf[32];
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
467 ::sprintf (buf, "%lu", a);
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
468 return String (buf);
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
469 }
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
470
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
471 // -------------------------------------------------------------------------------------------------
5
146825d63b9a - code cleanup
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1
diff changeset
472 //
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
473 METHOD
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
474 String::from_number (double a) -> String
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
475 {
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
476 char buf[64];
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
477 ::sprintf (buf, "%f", a);
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
478 return String (buf);
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
479 }

mercurial