sources/mystring.cpp

Sat, 09 Jan 2016 17:48:45 +0200

author
Teemu Piippo <crimsondusk64@gmail.com>
date
Sat, 09 Jan 2016 17:48:45 +0200
branch
protocol5
changeset 108
5900be70c619
parent 106
7b156b764d11
parent 107
ca10837a2a9e
child 131
4996c8684b93
permissions
-rw-r--r--

Merged with default

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
88
08ccaf26cffd Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents: 83
diff changeset
36 BEGIN_ZFC_NAMESPACE
08ccaf26cffd Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents: 83
diff changeset
37
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
38 // -------------------------------------------------------------------------------------------------
5
146825d63b9a - code cleanup
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1
diff changeset
39 //
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
40 int String::compare (const String& other) const
1
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 return m_string.compare (other.std_string());
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
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
45 // -------------------------------------------------------------------------------------------------
5
146825d63b9a - code cleanup
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1
diff changeset
46 //
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
47 void String::trim (int n)
1
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 //
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
57 String String::strip (const List<char>& unwanted)
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
58 {
88
08ccaf26cffd Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents: 83
diff changeset
59 String result (m_string);
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
60
88
08ccaf26cffd Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents: 83
diff changeset
61 for (int i = 0; i < unwanted.size(); ++i)
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
62 {
88
08ccaf26cffd Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents: 83
diff changeset
63 String c = unwanted[i];
08ccaf26cffd Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents: 83
diff changeset
64
08ccaf26cffd Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents: 83
diff changeset
65 for (int pos = 0; (pos = result.find (c)) != -1;)
08ccaf26cffd Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents: 83
diff changeset
66 result.remove_at (pos--);
1
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
88
08ccaf26cffd Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents: 83
diff changeset
69 return result;
1
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
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
72 // -------------------------------------------------------------------------------------------------
5
146825d63b9a - code cleanup
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1
diff changeset
73 //
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
74 String String::to_uppercase() const
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
75 {
88
08ccaf26cffd Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents: 83
diff changeset
76 String result (m_string);
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
77
88
08ccaf26cffd Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents: 83
diff changeset
78 for (int i = 0; i < result.length(); ++i)
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
79 {
88
08ccaf26cffd Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents: 83
diff changeset
80 if (islower (result[i]))
08ccaf26cffd Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents: 83
diff changeset
81 result[i] -= 'a' - 'A';
1
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
88
08ccaf26cffd Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents: 83
diff changeset
84 return result;
1
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 //
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
89 String String::to_lowercase() const
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
90 {
88
08ccaf26cffd Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents: 83
diff changeset
91 String result (m_string);
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
92
88
08ccaf26cffd Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents: 83
diff changeset
93 for (int i = 0; i < result.length(); ++i)
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
94 {
88
08ccaf26cffd Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents: 83
diff changeset
95 if (isupper (result[i]))
08ccaf26cffd Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents: 83
diff changeset
96 result[i] += 'a' - 'A';
1
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
88
08ccaf26cffd Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents: 83
diff changeset
99 return result;
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
100 }
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 // -------------------------------------------------------------------------------------------------
5
146825d63b9a - code cleanup
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1
diff changeset
103 //
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
104 StringList String::split (char del) const
1
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 String delimstr;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
107 delimstr += del;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
108 return split (delimstr);
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
109 }
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 // -------------------------------------------------------------------------------------------------
5
146825d63b9a - code cleanup
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1
diff changeset
112 //
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
113 StringList String::split (const String& del) const
1
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 StringList res;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
116 int a = 0;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
117 int b;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
118
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
119 // 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
120 while ((b = find (del, a)) != -1)
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 String sub = mid (a, b);
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
123
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
124 if (sub.length() > 0)
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
125 res << sub;
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 a = b + del.length();
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
128 }
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 // 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
131 if (a < (int) length())
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
132 res.append (mid (a, length()));
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
133
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
134 return res;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
135 }
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 // -------------------------------------------------------------------------------------------------
5
146825d63b9a - code cleanup
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1
diff changeset
138 //
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
139 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
140 {
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
141 long pos;
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 while ((pos = find (a)) != -1)
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
144 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
145 }
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 // -------------------------------------------------------------------------------------------------
5
146825d63b9a - code cleanup
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1
diff changeset
148 //
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
149 int String::count (char needle) const
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
150 {
88
08ccaf26cffd Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents: 83
diff changeset
151 int result = 0;
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
152
88
08ccaf26cffd Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents: 83
diff changeset
153 for (int i = 0; i < length(); ++i)
08ccaf26cffd Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents: 83
diff changeset
154 {
08ccaf26cffd Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents: 83
diff changeset
155 if (m_string[i] == needle)
08ccaf26cffd Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents: 83
diff changeset
156 result++;
08ccaf26cffd Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents: 83
diff changeset
157 }
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
158
88
08ccaf26cffd Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents: 83
diff changeset
159 return result;
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
160 }
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 // -------------------------------------------------------------------------------------------------
5
146825d63b9a - code cleanup
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1
diff changeset
163 //
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
164 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
165 {
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
166 if (b == -1 or b > length())
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
167 b = length();
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
168
105
b4466472aecd Added some basic IRC-like commands that can be used to do what keystrokes can do without actually using keystrokes
Teemu Piippo <crimsondusk64@gmail.com>
parents: 88
diff changeset
169 if (b <= a)
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
170 return "";
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 if (a == 0 and b == length())
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
173 return *this;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
174
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
175 char* newstr = new char[b - a + 1];
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
176 strncpy (newstr, chars() + a, b - a);
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
177 newstr[b - a] = '\0';
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
178 String other (newstr);
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
179 delete[] newstr;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
180 return other;
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
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
183 // -------------------------------------------------------------------------------------------------
5
146825d63b9a - code cleanup
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1
diff changeset
184 //
105
b4466472aecd Added some basic IRC-like commands that can be used to do what keystrokes can do without actually using keystrokes
Teemu Piippo <crimsondusk64@gmail.com>
parents: 88
diff changeset
185 String String::right(int length) const
b4466472aecd Added some basic IRC-like commands that can be used to do what keystrokes can do without actually using keystrokes
Teemu Piippo <crimsondusk64@gmail.com>
parents: 88
diff changeset
186 {
b4466472aecd Added some basic IRC-like commands that can be used to do what keystrokes can do without actually using keystrokes
Teemu Piippo <crimsondusk64@gmail.com>
parents: 88
diff changeset
187 if (length >= this->length())
b4466472aecd Added some basic IRC-like commands that can be used to do what keystrokes can do without actually using keystrokes
Teemu Piippo <crimsondusk64@gmail.com>
parents: 88
diff changeset
188 return *this;
b4466472aecd Added some basic IRC-like commands that can be used to do what keystrokes can do without actually using keystrokes
Teemu Piippo <crimsondusk64@gmail.com>
parents: 88
diff changeset
189 else
b4466472aecd Added some basic IRC-like commands that can be used to do what keystrokes can do without actually using keystrokes
Teemu Piippo <crimsondusk64@gmail.com>
parents: 88
diff changeset
190 return String(chars() + this->length() - length);
b4466472aecd Added some basic IRC-like commands that can be used to do what keystrokes can do without actually using keystrokes
Teemu Piippo <crimsondusk64@gmail.com>
parents: 88
diff changeset
191 }
b4466472aecd Added some basic IRC-like commands that can be used to do what keystrokes can do without actually using keystrokes
Teemu Piippo <crimsondusk64@gmail.com>
parents: 88
diff changeset
192
b4466472aecd Added some basic IRC-like commands that can be used to do what keystrokes can do without actually using keystrokes
Teemu Piippo <crimsondusk64@gmail.com>
parents: 88
diff changeset
193 // -------------------------------------------------------------------------------------------------
b4466472aecd Added some basic IRC-like commands that can be used to do what keystrokes can do without actually using keystrokes
Teemu Piippo <crimsondusk64@gmail.com>
parents: 88
diff changeset
194 //
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
195 int String::word_position (int n) const
1
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 int count = 0;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
198
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
199 for (int i = 0; i < length(); ++i)
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
200 {
5
146825d63b9a - code cleanup
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1
diff changeset
201 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
202 continue;
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 return i;
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
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
207 return -1;
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
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
210 // -------------------------------------------------------------------------------------------------
5
146825d63b9a - code cleanup
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1
diff changeset
211 //
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
212 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
213 {
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
214 int pos = m_string.find (c, a);
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 if (pos == int (std::string::npos))
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
217 return -1;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
218
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
219 return pos;
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
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
222 // -------------------------------------------------------------------------------------------------
5
146825d63b9a - code cleanup
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1
diff changeset
223 //
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
224 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
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 //
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
238 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
239 {
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
240 errno = 0;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
241 char* endptr;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
242 long i = strtol (chars(), &endptr, base);
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
243
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
244 if (ok)
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
245 *ok = (errno == 0 and *endptr == '\0');
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
246
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
247 return i;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
248 }
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 // -------------------------------------------------------------------------------------------------
5
146825d63b9a - code cleanup
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1
diff changeset
251 //
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
252 float String::to_float (bool* ok) const
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
253 {
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
254 errno = 0;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
255 char* endptr;
88
08ccaf26cffd Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents: 83
diff changeset
256 float i = (float) strtod (chars(), &endptr);
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
257
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
258 if (ok != nullptr)
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
259 *ok = (errno == 0 and *endptr == '\0');
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
260
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
261 return i;
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
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
264 // -------------------------------------------------------------------------------------------------
5
146825d63b9a - code cleanup
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1
diff changeset
265 //
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
266 double String::to_double (bool* ok) const
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
267 {
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
268 errno = 0;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
269 char* endptr;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
270 double i = strtod (chars(), &endptr);
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
271
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
272 if (ok != nullptr)
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
273 *ok = (errno == 0 and *endptr == '\0');
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 return i;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
276 }
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 // -------------------------------------------------------------------------------------------------
5
146825d63b9a - code cleanup
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1
diff changeset
279 //
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
280 String String::operator+ (const String& data) const
1
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 String newString = *this;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
283 newString.append (data);
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
284 return newString;
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
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
287 // -------------------------------------------------------------------------------------------------
5
146825d63b9a - code cleanup
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1
diff changeset
288 //
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
289 String String::operator+ (const char* data) const
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 String newstr = *this;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
292 newstr.append (data);
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
293 return newstr;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
294 }
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 // -------------------------------------------------------------------------------------------------
5
146825d63b9a - code cleanup
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1
diff changeset
297 //
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
298 bool String::is_numeric() const
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
299 {
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
300 char* endptr;
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
301 strtol (chars(), &endptr, 10);
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
302 return not (endptr && *endptr);
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
303 }
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
304
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
305 // -------------------------------------------------------------------------------------------------
5
146825d63b9a - code cleanup
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1
diff changeset
306 //
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
307 bool String::ends_with (const String& other)
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
308 {
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
309 if (length() < other.length())
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
310 return false;
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 const int ofs = length() - other.length();
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
313 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
314 }
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
315
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
316 // -------------------------------------------------------------------------------------------------
5
146825d63b9a - code cleanup
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1
diff changeset
317 //
107
ca10837a2a9e Backport string changes from protocol5
Teemu Piippo <crimsondusk64@gmail.com>
parents: 105
diff changeset
318 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
319 {
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
320 if (length() < other.length())
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
321 return false;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
322
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
323 return strncmp (chars(), other.chars(), other.length()) == 0;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
324 }
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
325
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
326 // -------------------------------------------------------------------------------------------------
5
146825d63b9a - code cleanup
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1
diff changeset
327 //
83
08bfc3d9d2ae Removed format.cpp and format.h, use built-in formatting instead
Teemu Piippo <crimsondusk64@gmail.com>
parents: 73
diff changeset
328 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
329 {
08bfc3d9d2ae Removed format.cpp and format.h, use built-in formatting instead
Teemu Piippo <crimsondusk64@gmail.com>
parents: 73
diff changeset
330 va_list args;
08bfc3d9d2ae Removed format.cpp and format.h, use built-in formatting instead
Teemu Piippo <crimsondusk64@gmail.com>
parents: 73
diff changeset
331 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
332 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
333 va_end (args);
08bfc3d9d2ae Removed format.cpp and format.h, use built-in formatting instead
Teemu Piippo <crimsondusk64@gmail.com>
parents: 73
diff changeset
334 }
08bfc3d9d2ae Removed format.cpp and format.h, use built-in formatting instead
Teemu Piippo <crimsondusk64@gmail.com>
parents: 73
diff changeset
335
08bfc3d9d2ae Removed format.cpp and format.h, use built-in formatting instead
Teemu Piippo <crimsondusk64@gmail.com>
parents: 73
diff changeset
336 // -------------------------------------------------------------------------------------------------
08bfc3d9d2ae Removed format.cpp and format.h, use built-in formatting instead
Teemu Piippo <crimsondusk64@gmail.com>
parents: 73
diff changeset
337 //
08bfc3d9d2ae Removed format.cpp and format.h, use built-in formatting instead
Teemu Piippo <crimsondusk64@gmail.com>
parents: 73
diff changeset
338 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
339 {
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
340 char* buf = nullptr;
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
341 int bufsize = 256;
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 do
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
344 {
83
08bfc3d9d2ae Removed format.cpp and format.h, use built-in formatting instead
Teemu Piippo <crimsondusk64@gmail.com>
parents: 73
diff changeset
345 bufsize *= 2;
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
346 delete[] buf;
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
347 buf = new char[bufsize];
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
348 }
83
08bfc3d9d2ae Removed format.cpp and format.h, use built-in formatting instead
Teemu Piippo <crimsondusk64@gmail.com>
parents: 73
diff changeset
349 while (vsnprintf (buf, bufsize, fmtstr, args) >= bufsize);
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
350
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
351 m_string = buf;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
352 delete[] buf;
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 //
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
357 String StringList::join (const String& delim)
1
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 String result;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
360
88
08ccaf26cffd Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents: 83
diff changeset
361 for (int i = 0; i < size(); ++i)
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 if (result.is_empty() == false)
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
364 result += delim;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
365
88
08ccaf26cffd Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents: 83
diff changeset
366 result += container()[i];
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
367 }
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 return result;
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
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
372 // -------------------------------------------------------------------------------------------------
5
146825d63b9a - code cleanup
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1
diff changeset
373 //
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
374 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
375 {
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
376 // Elevate to uppercase for case-insensitive matching
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
377 String pattern_upper = pattern.to_uppercase();
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
378 String this_upper = to_uppercase();
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
379 const char* maskstring = pattern_upper.chars();
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
380 const char* mptr = &maskstring[0];
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 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
383 {
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
384 if (*mptr == '?')
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 if (*(sptr + 1) == '\0')
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 // ? 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
389 // Therefore, mask matching fails
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
390 return false;
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 }
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
393 else if (*mptr == '*')
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
394 {
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
395 char end = *(++mptr);
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 // 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
398 // 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
399 // the string any further.
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
400 if (end == '\0')
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
401 return true;
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 // Skip to the end character
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
404 while (*sptr != end and *sptr != '\0')
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
405 sptr++;
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 // String ended while the mask still had stuff
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
408 if (*sptr == '\0')
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
409 return false;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
410 }
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
411 else if (*sptr != *mptr)
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
412 return false;
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 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
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
417 return true;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
418 }
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 // -------------------------------------------------------------------------------------------------
5
146825d63b9a - code cleanup
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1
diff changeset
421 //
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
422 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
423 {
bd28a5730fd0 - fixed: had problems with integral overloading under 32-bit
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
424 char buf[32];
bd28a5730fd0 - fixed: had problems with integral overloading under 32-bit
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
425 ::sprintf (buf, "%d", a);
bd28a5730fd0 - fixed: had problems with integral overloading under 32-bit
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
426 return String (buf);
bd28a5730fd0 - fixed: had problems with integral overloading under 32-bit
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
427 }
bd28a5730fd0 - fixed: had problems with integral overloading under 32-bit
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
428
bd28a5730fd0 - fixed: had problems with integral overloading under 32-bit
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
429 // -------------------------------------------------------------------------------------------------
bd28a5730fd0 - fixed: had problems with integral overloading under 32-bit
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
430 //
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
431 String String::from_number (int a)
1
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 char buf[32];
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
434 ::sprintf (buf, "%d", a);
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
435 return String (buf);
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 // -------------------------------------------------------------------------------------------------
5
146825d63b9a - code cleanup
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1
diff changeset
439 //
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
440 String String::from_number (long int a)
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
441 {
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
442 char buf[32];
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
443 ::sprintf (buf, "%ld", a);
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
444 return String (buf);
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
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
447 // -------------------------------------------------------------------------------------------------
5
146825d63b9a - code cleanup
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1
diff changeset
448 //
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
449 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
450 {
bd28a5730fd0 - fixed: had problems with integral overloading under 32-bit
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
451 char buf[32];
bd28a5730fd0 - fixed: had problems with integral overloading under 32-bit
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
452 ::sprintf (buf, "%u", a);
bd28a5730fd0 - fixed: had problems with integral overloading under 32-bit
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
453 return String (buf);
bd28a5730fd0 - fixed: had problems with integral overloading under 32-bit
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
454 }
bd28a5730fd0 - fixed: had problems with integral overloading under 32-bit
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
455
bd28a5730fd0 - fixed: had problems with integral overloading under 32-bit
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
456 // -------------------------------------------------------------------------------------------------
bd28a5730fd0 - fixed: had problems with integral overloading under 32-bit
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
457 //
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
458 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
459 {
bd28a5730fd0 - fixed: had problems with integral overloading under 32-bit
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
460 char buf[32];
bd28a5730fd0 - fixed: had problems with integral overloading under 32-bit
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
461 ::sprintf (buf, "%u", a);
bd28a5730fd0 - fixed: had problems with integral overloading under 32-bit
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
462 return String (buf);
bd28a5730fd0 - fixed: had problems with integral overloading under 32-bit
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
463 }
bd28a5730fd0 - fixed: had problems with integral overloading under 32-bit
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
464
bd28a5730fd0 - fixed: had problems with integral overloading under 32-bit
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
465 // -------------------------------------------------------------------------------------------------
bd28a5730fd0 - fixed: had problems with integral overloading under 32-bit
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
466 //
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
467 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
468 {
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
469 char buf[32];
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
470 ::sprintf (buf, "%lu", a);
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
471 return String (buf);
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
472 }
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
473
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
474 // -------------------------------------------------------------------------------------------------
5
146825d63b9a - code cleanup
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1
diff changeset
475 //
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
476 String String::from_number (double a)
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
477 {
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
478 char buf[64];
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
479 ::sprintf (buf, "%f", a);
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
480 return String (buf);
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
481 }
10
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents: 5
diff changeset
482
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents: 5
diff changeset
483 // -------------------------------------------------------------------------------------------------
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents: 5
diff changeset
484 //
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
485 String String::md5() const
10
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents: 5
diff changeset
486 {
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents: 5
diff changeset
487 char checksum[33];
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents: 5
diff changeset
488 CalculateMD5 (reinterpret_cast<const unsigned char*> (chars()), length(), checksum);
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents: 5
diff changeset
489 checksum[sizeof checksum - 1] = '\0';
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents: 5
diff changeset
490 return String (checksum);
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents: 5
diff changeset
491 }
12
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 // -------------------------------------------------------------------------------------------------
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 10
diff changeset
494 //
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
495 void String::normalize (int (*filter)(int))
12
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 10
diff changeset
496 {
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 10
diff changeset
497 int a = 0;
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 10
diff changeset
498 int b = length() - 1;
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 10
diff changeset
499
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 10
diff changeset
500 while ((*filter) (m_string[a]) and a != b)
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 10
diff changeset
501 ++a;
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 10
diff changeset
502
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 10
diff changeset
503 while ((*filter) (m_string[b]) and a != b)
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 10
diff changeset
504 --b;
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 10
diff changeset
505
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 10
diff changeset
506 if (a == b)
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 10
diff changeset
507 m_string = "";
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 10
diff changeset
508 else if (a != 0 or b != length() - 1)
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 10
diff changeset
509 m_string = m_string.substr (a, b - a + 1);
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 10
diff changeset
510 }
88
08ccaf26cffd Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents: 83
diff changeset
511
107
ca10837a2a9e Backport string changes from protocol5
Teemu Piippo <crimsondusk64@gmail.com>
parents: 105
diff changeset
512 // -------------------------------------------------------------------------------------------------
ca10837a2a9e Backport string changes from protocol5
Teemu Piippo <crimsondusk64@gmail.com>
parents: 105
diff changeset
513 //
ca10837a2a9e Backport string changes from protocol5
Teemu Piippo <crimsondusk64@gmail.com>
parents: 105
diff changeset
514 String String::normalized (int (*filter)(int)) const
ca10837a2a9e Backport string changes from protocol5
Teemu Piippo <crimsondusk64@gmail.com>
parents: 105
diff changeset
515 {
ca10837a2a9e Backport string changes from protocol5
Teemu Piippo <crimsondusk64@gmail.com>
parents: 105
diff changeset
516 String result = *this;
ca10837a2a9e Backport string changes from protocol5
Teemu Piippo <crimsondusk64@gmail.com>
parents: 105
diff changeset
517 result.normalize(filter);
ca10837a2a9e Backport string changes from protocol5
Teemu Piippo <crimsondusk64@gmail.com>
parents: 105
diff changeset
518 return result;
ca10837a2a9e Backport string changes from protocol5
Teemu Piippo <crimsondusk64@gmail.com>
parents: 105
diff changeset
519 }
ca10837a2a9e Backport string changes from protocol5
Teemu Piippo <crimsondusk64@gmail.com>
parents: 105
diff changeset
520
105
b4466472aecd Added some basic IRC-like commands that can be used to do what keystrokes can do without actually using keystrokes
Teemu Piippo <crimsondusk64@gmail.com>
parents: 88
diff changeset
521 END_ZFC_NAMESPACE

mercurial