sources/mystring.cpp

Fri, 24 Jul 2015 04:24:38 +0300

author
Teemu Piippo <tsapii@utu.fi>
date
Fri, 24 Jul 2015 04:24:38 +0300
changeset 100
d301ead29d7c
parent 88
08ccaf26cffd
child 105
b4466472aecd
permissions
-rw-r--r--

Apply Leonard's patch for fixing the colors:

The colors were broken again.
* isprint for some reason returned true when the given byte is higher than 255.
The char cast of the byte was then printed which resulted in odd characters
popping up. Black appeared as ^@ which is NULL in caret notation.
* After that, the colors were all messed up because the RLINE enum didn't take
in account the color swapping.
So instead of messing up the enum order/number I went for a new "range-like"
method.
* After fixing all of that, I noticed the Interface::render_colorline had a
broken loop since the VS2010 commits.
This made the lines not print entierely and messed up the colors etc.

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
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
169 if (b == a)
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 (b < a)
88
08ccaf26cffd Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents: 83
diff changeset
173 std::swap (a, b);
1
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 if (a == 0 and b == length())
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
176 return *this;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
177
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
178 char* newstr = new char[b - a + 1];
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
179 strncpy (newstr, chars() + a, b - a);
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
180 newstr[b - a] = '\0';
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
181 String other (newstr);
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
182 delete[] newstr;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
183 return other;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
184 }
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
185
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
186 // -------------------------------------------------------------------------------------------------
5
146825d63b9a - code cleanup
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1
diff changeset
187 //
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
188 int String::word_position (int n) const
1
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 int count = 0;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
191
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
192 for (int i = 0; i < length(); ++i)
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
193 {
5
146825d63b9a - code cleanup
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1
diff changeset
194 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
195 continue;
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 return i;
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
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
200 return -1;
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
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
203 // -------------------------------------------------------------------------------------------------
5
146825d63b9a - code cleanup
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1
diff changeset
204 //
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
205 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
206 {
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
207 int pos = m_string.find (c, a);
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 if (pos == int (std::string::npos))
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
210 return -1;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
211
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
212 return pos;
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
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
215 // -------------------------------------------------------------------------------------------------
5
146825d63b9a - code cleanup
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1
diff changeset
216 //
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
217 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
218 {
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
219 if (a == -1 or a >= length())
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
220 a = length() - 1;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
221
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
222 for (; a > 0; a--)
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
223 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
224 return a;
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 return -1;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
227 }
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 // -------------------------------------------------------------------------------------------------
5
146825d63b9a - code cleanup
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1
diff changeset
230 //
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
231 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
232 {
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
233 errno = 0;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
234 char* endptr;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
235 long i = strtol (chars(), &endptr, base);
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
236
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
237 if (ok)
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
238 *ok = (errno == 0 and *endptr == '\0');
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 return i;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
241 }
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
242
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
243 // -------------------------------------------------------------------------------------------------
5
146825d63b9a - code cleanup
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1
diff changeset
244 //
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
245 float String::to_float (bool* ok) const
1
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 errno = 0;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
248 char* endptr;
88
08ccaf26cffd Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents: 83
diff changeset
249 float i = (float) strtod (chars(), &endptr);
1
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 if (ok != nullptr)
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
252 *ok = (errno == 0 and *endptr == '\0');
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 return i;
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
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
257 // -------------------------------------------------------------------------------------------------
5
146825d63b9a - code cleanup
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1
diff changeset
258 //
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
259 double String::to_double (bool* ok) const
1
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 errno = 0;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
262 char* endptr;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
263 double i = strtod (chars(), &endptr);
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 if (ok != nullptr)
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
266 *ok = (errno == 0 and *endptr == '\0');
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 return i;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
269 }
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 // -------------------------------------------------------------------------------------------------
5
146825d63b9a - code cleanup
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1
diff changeset
272 //
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
273 String String::operator+ (const String& data) const
1
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 String newString = *this;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
276 newString.append (data);
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
277 return newString;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
278 }
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 // -------------------------------------------------------------------------------------------------
5
146825d63b9a - code cleanup
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1
diff changeset
281 //
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
282 String String::operator+ (const char* data) const
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
283 {
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
284 String newstr = *this;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
285 newstr.append (data);
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
286 return newstr;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
287 }
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
288
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
289 // -------------------------------------------------------------------------------------------------
5
146825d63b9a - code cleanup
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1
diff changeset
290 //
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
291 bool String::is_numeric() const
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
292 {
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
293 char* endptr;
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
294 strtol (chars(), &endptr, 10);
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
295 return not (endptr && *endptr);
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
296 }
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
297
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
298 // -------------------------------------------------------------------------------------------------
5
146825d63b9a - code cleanup
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1
diff changeset
299 //
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
300 bool String::ends_with (const String& other)
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
301 {
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
302 if (length() < other.length())
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
303 return false;
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 const int ofs = length() - other.length();
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
306 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
307 }
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 // -------------------------------------------------------------------------------------------------
5
146825d63b9a - code cleanup
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1
diff changeset
310 //
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
311 bool String::starts_with (const String& other)
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
312 {
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
313 if (length() < other.length())
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
314 return false;
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 return strncmp (chars(), other.chars(), other.length()) == 0;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
317 }
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
318
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
319 // -------------------------------------------------------------------------------------------------
5
146825d63b9a - code cleanup
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1
diff changeset
320 //
83
08bfc3d9d2ae Removed format.cpp and format.h, use built-in formatting instead
Teemu Piippo <crimsondusk64@gmail.com>
parents: 73
diff changeset
321 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
322 {
08bfc3d9d2ae Removed format.cpp and format.h, use built-in formatting instead
Teemu Piippo <crimsondusk64@gmail.com>
parents: 73
diff changeset
323 va_list args;
08bfc3d9d2ae Removed format.cpp and format.h, use built-in formatting instead
Teemu Piippo <crimsondusk64@gmail.com>
parents: 73
diff changeset
324 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
325 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
326 va_end (args);
08bfc3d9d2ae Removed format.cpp and format.h, use built-in formatting instead
Teemu Piippo <crimsondusk64@gmail.com>
parents: 73
diff changeset
327 }
08bfc3d9d2ae Removed format.cpp and format.h, use built-in formatting instead
Teemu Piippo <crimsondusk64@gmail.com>
parents: 73
diff changeset
328
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 //
08bfc3d9d2ae Removed format.cpp and format.h, use built-in formatting instead
Teemu Piippo <crimsondusk64@gmail.com>
parents: 73
diff changeset
331 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
332 {
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
333 char* buf = nullptr;
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
334 int bufsize = 256;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
335
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
336 do
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
337 {
83
08bfc3d9d2ae Removed format.cpp and format.h, use built-in formatting instead
Teemu Piippo <crimsondusk64@gmail.com>
parents: 73
diff changeset
338 bufsize *= 2;
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
339 delete[] buf;
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
340 buf = new char[bufsize];
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
341 }
83
08bfc3d9d2ae Removed format.cpp and format.h, use built-in formatting instead
Teemu Piippo <crimsondusk64@gmail.com>
parents: 73
diff changeset
342 while (vsnprintf (buf, bufsize, fmtstr, args) >= bufsize);
1
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 m_string = buf;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
345 delete[] buf;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
346 }
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
347
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
348 // -------------------------------------------------------------------------------------------------
5
146825d63b9a - code cleanup
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1
diff changeset
349 //
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
350 String StringList::join (const String& delim)
1
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 String result;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
353
88
08ccaf26cffd Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents: 83
diff changeset
354 for (int i = 0; i < size(); ++i)
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
355 {
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
356 if (result.is_empty() == false)
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
357 result += delim;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
358
88
08ccaf26cffd Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents: 83
diff changeset
359 result += container()[i];
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
360 }
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
361
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
362 return result;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
363 }
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 // -------------------------------------------------------------------------------------------------
5
146825d63b9a - code cleanup
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1
diff changeset
366 //
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
367 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
368 {
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
369 // Elevate to uppercase for case-insensitive matching
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
370 String pattern_upper = pattern.to_uppercase();
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
371 String this_upper = to_uppercase();
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
372 const char* maskstring = pattern_upper.chars();
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
373 const char* mptr = &maskstring[0];
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
374
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
375 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
376 {
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
377 if (*mptr == '?')
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 if (*(sptr + 1) == '\0')
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 // ? 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
382 // Therefore, mask matching fails
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
383 return false;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
384 }
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 else if (*mptr == '*')
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 char end = *(++mptr);
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
389
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
390 // 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
391 // 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
392 // the string any further.
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
393 if (end == '\0')
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
394 return true;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
395
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
396 // Skip to the end character
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
397 while (*sptr != end and *sptr != '\0')
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
398 sptr++;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
399
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
400 // String ended while the mask still had stuff
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
401 if (*sptr == '\0')
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
402 return false;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
403 }
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
404 else if (*sptr != *mptr)
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
405 return false;
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 mptr++;
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
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
410 return true;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
411 }
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 // -------------------------------------------------------------------------------------------------
5
146825d63b9a - code cleanup
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1
diff changeset
414 //
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
415 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
416 {
bd28a5730fd0 - fixed: had problems with integral overloading under 32-bit
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
417 char buf[32];
bd28a5730fd0 - fixed: had problems with integral overloading under 32-bit
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
418 ::sprintf (buf, "%d", a);
bd28a5730fd0 - fixed: had problems with integral overloading under 32-bit
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
419 return String (buf);
bd28a5730fd0 - fixed: had problems with integral overloading under 32-bit
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
420 }
bd28a5730fd0 - fixed: had problems with integral overloading under 32-bit
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
421
bd28a5730fd0 - fixed: had problems with integral overloading under 32-bit
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
422 // -------------------------------------------------------------------------------------------------
bd28a5730fd0 - fixed: had problems with integral overloading under 32-bit
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
423 //
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
424 String String::from_number (int a)
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
425 {
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
426 char buf[32];
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
427 ::sprintf (buf, "%d", a);
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
428 return String (buf);
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
429 }
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
430
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
431 // -------------------------------------------------------------------------------------------------
5
146825d63b9a - code cleanup
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1
diff changeset
432 //
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
433 String String::from_number (long int a)
1
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 char buf[32];
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
436 ::sprintf (buf, "%ld", a);
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
437 return String (buf);
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
438 }
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 // -------------------------------------------------------------------------------------------------
5
146825d63b9a - code cleanup
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1
diff changeset
441 //
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
442 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
443 {
bd28a5730fd0 - fixed: had problems with integral overloading under 32-bit
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
444 char buf[32];
bd28a5730fd0 - fixed: had problems with integral overloading under 32-bit
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
445 ::sprintf (buf, "%u", a);
bd28a5730fd0 - fixed: had problems with integral overloading under 32-bit
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
446 return String (buf);
bd28a5730fd0 - fixed: had problems with integral overloading under 32-bit
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
447 }
bd28a5730fd0 - fixed: had problems with integral overloading under 32-bit
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
448
bd28a5730fd0 - fixed: had problems with integral overloading under 32-bit
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
449 // -------------------------------------------------------------------------------------------------
bd28a5730fd0 - fixed: had problems with integral overloading under 32-bit
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
450 //
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
451 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
452 {
bd28a5730fd0 - fixed: had problems with integral overloading under 32-bit
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
453 char buf[32];
bd28a5730fd0 - fixed: had problems with integral overloading under 32-bit
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
454 ::sprintf (buf, "%u", a);
bd28a5730fd0 - fixed: had problems with integral overloading under 32-bit
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
455 return String (buf);
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
bd28a5730fd0 - fixed: had problems with integral overloading under 32-bit
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
458 // -------------------------------------------------------------------------------------------------
bd28a5730fd0 - fixed: had problems with integral overloading under 32-bit
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
459 //
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
460 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
461 {
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
462 char buf[32];
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
463 ::sprintf (buf, "%lu", a);
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
464 return String (buf);
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
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
467 // -------------------------------------------------------------------------------------------------
5
146825d63b9a - code cleanup
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1
diff changeset
468 //
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
469 String String::from_number (double a)
1
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 char buf[64];
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
472 ::sprintf (buf, "%f", a);
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
473 return String (buf);
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
474 }
10
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents: 5
diff changeset
475
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents: 5
diff changeset
476 // -------------------------------------------------------------------------------------------------
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents: 5
diff changeset
477 //
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
478 String String::md5() const
10
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents: 5
diff changeset
479 {
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents: 5
diff changeset
480 char checksum[33];
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents: 5
diff changeset
481 CalculateMD5 (reinterpret_cast<const unsigned char*> (chars()), length(), checksum);
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents: 5
diff changeset
482 checksum[sizeof checksum - 1] = '\0';
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents: 5
diff changeset
483 return String (checksum);
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents: 5
diff changeset
484 }
12
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 10
diff changeset
485
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 10
diff changeset
486 // -------------------------------------------------------------------------------------------------
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 10
diff changeset
487 //
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
488 void String::normalize (int (*filter)(int))
12
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 10
diff changeset
489 {
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 10
diff changeset
490 int a = 0;
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 10
diff changeset
491 int b = length() - 1;
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 while ((*filter) (m_string[a]) and a != b)
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 10
diff changeset
494 ++a;
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 10
diff changeset
495
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 10
diff changeset
496 while ((*filter) (m_string[b]) and a != b)
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 10
diff changeset
497 --b;
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 10
diff changeset
498
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 10
diff changeset
499 if (a == b)
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 10
diff changeset
500 m_string = "";
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 10
diff changeset
501 else if (a != 0 or b != length() - 1)
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 10
diff changeset
502 m_string = m_string.substr (a, b - a + 1);
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 10
diff changeset
503 }
88
08ccaf26cffd Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents: 83
diff changeset
504
08ccaf26cffd Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents: 83
diff changeset
505 END_ZFC_NAMESPACE

mercurial