sources/mystring.cpp

Wed, 27 Jan 2021 13:08:51 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Wed, 27 Jan 2021 13:08:51 +0200
changeset 180
2e7225dbd9b2
parent 179
7fc34735178e
child 181
e254398fcc7c
permissions
-rw-r--r--

continue cleanup

1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1 /*
109
e4966d7e615d Happy new year 2016
Teemu Piippo <crimsondusk64@gmail.com>
parents: 107
diff changeset
2 Copyright 2014 - 2016 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
147
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
38 /*!
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
39 * \brief Compares this string with another.
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
40 * \param other The string to compare with.
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
41 * \returns -1 if this string is lexicographically less than \c other,
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
42 * 0 if they are equal, or
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
43 * 1 if this string is lexicographically greater than \c other.
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
44 */
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
45 int String::compare (const String& other) const
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
46 {
145
d0aedc9be448 Renamed String methods, and reformatted mystring.h
Teemu Piippo <teemu@compsta2.com>
parents: 137
diff changeset
47 return m_string.compare (other.stdString());
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
147
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
50 /*!
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
51 * \returns an upper-case version of this string.
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
52 */
145
d0aedc9be448 Renamed String methods, and reformatted mystring.h
Teemu Piippo <teemu@compsta2.com>
parents: 137
diff changeset
53 String String::toUpperCase() const
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
54 {
88
08ccaf26cffd Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents: 83
diff changeset
55 String result (m_string);
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
56
137
485cb6d6b98c Made Range not include the 'max' parameter, replaced a lot of for()-loops with C++11-style range-for-loops
Teemu Piippo <teemu@compsta2.com>
parents: 129
diff changeset
57 for (char &ch : result)
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
58 {
137
485cb6d6b98c Made Range not include the 'max' parameter, replaced a lot of for()-loops with C++11-style range-for-loops
Teemu Piippo <teemu@compsta2.com>
parents: 129
diff changeset
59 if (islower(ch))
485cb6d6b98c Made Range not include the 'max' parameter, replaced a lot of for()-loops with C++11-style range-for-loops
Teemu Piippo <teemu@compsta2.com>
parents: 129
diff changeset
60 ch -= 'a' - 'A';
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
61 }
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
62
88
08ccaf26cffd Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents: 83
diff changeset
63 return result;
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
64 }
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
65
147
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
66 /*!
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
67 * \returns a lower-case version of this string.
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
68 */
145
d0aedc9be448 Renamed String methods, and reformatted mystring.h
Teemu Piippo <teemu@compsta2.com>
parents: 137
diff changeset
69 String String::toLowerCase() const
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
70 {
88
08ccaf26cffd Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents: 83
diff changeset
71 String result (m_string);
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
72
137
485cb6d6b98c Made Range not include the 'max' parameter, replaced a lot of for()-loops with C++11-style range-for-loops
Teemu Piippo <teemu@compsta2.com>
parents: 129
diff changeset
73 for (char &ch : result)
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
74 {
137
485cb6d6b98c Made Range not include the 'max' parameter, replaced a lot of for()-loops with C++11-style range-for-loops
Teemu Piippo <teemu@compsta2.com>
parents: 129
diff changeset
75 if (isupper(ch))
485cb6d6b98c Made Range not include the 'max' parameter, replaced a lot of for()-loops with C++11-style range-for-loops
Teemu Piippo <teemu@compsta2.com>
parents: 129
diff changeset
76 ch += 'a' - 'A';
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
77 }
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
78
88
08ccaf26cffd Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents: 83
diff changeset
79 return result;
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
80 }
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
81
147
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
82 /*!
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
83 * \brief Splits this string using the provided delimeter.
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
84 * \param delimeter Delimeter to use for splitting.
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
85 * \returns a string list containing the split strings.
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
86 */
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
87 StringList String::split (char delimeter) const
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
88 {
147
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
89 String delimeterString;
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
90 delimeterString += delimeter;
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
91 return split (delimeterString);
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
92 }
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
93
147
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
94 /*!
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
95 * \brief Splits this string using the provided delimeter.
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
96 * \param delimeter Delimeter to use for splitting.
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
97 * \returns a string list containing the split strings.
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
98 */
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
99 StringList String::split (const String& delimeter) const
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
100 {
147
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
101 StringList result;
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
102 int a = 0;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
103 int b;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
104
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
105 // Find all separators and store the text left to them.
147
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
106 while ((b = find (delimeter, a)) != -1)
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
107 {
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
108 String sub = mid (a, b);
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 if (sub.length() > 0)
179
7fc34735178e start cleaning up unused code
Teemu Piippo <teemu@hecknology.net>
parents: 158
diff changeset
111 result.push_back(sub);
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
112
147
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
113 a = b + delimeter.length();
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
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
116 // 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
117 if (a < (int) length())
179
7fc34735178e start cleaning up unused code
Teemu Piippo <teemu@hecknology.net>
parents: 158
diff changeset
118 result.push_back(mid(a, length()));
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
119
147
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
120 return result;
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
147
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
123 /*!
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
124 * \brief Replaces all instances of \c text with \c replacement.
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
125 * \param text Text to replace away.
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
126 * \param replacement Text to replace \c text with.
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
127 */
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
128 void String::replace (const char* text, const char* replacement)
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
129 {
147
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
130 int position;
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
131
147
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
132 while ((position = find (text)) != -1)
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
133 m_string = m_string.replace (position, strlen (text), replacement);
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
134 }
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
135
147
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
136 /*!
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
137 * \param character Character to count.
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
138 * \returns the amount of \c character found in the string.
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
139 */
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
140 int String::count (char character) const
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
141 {
88
08ccaf26cffd Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents: 83
diff changeset
142 int result = 0;
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
143
137
485cb6d6b98c Made Range not include the 'max' parameter, replaced a lot of for()-loops with C++11-style range-for-loops
Teemu Piippo <teemu@compsta2.com>
parents: 129
diff changeset
144 for (char ch : *this)
88
08ccaf26cffd Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents: 83
diff changeset
145 {
147
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
146 if (ch == character)
88
08ccaf26cffd Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents: 83
diff changeset
147 result++;
08ccaf26cffd Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents: 83
diff changeset
148 }
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
149
88
08ccaf26cffd Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents: 83
diff changeset
150 return result;
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
151 }
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
152
147
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
153 /*!
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
154 * \param a Starting index of the range.
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
155 * \param b Ending index of the range.
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
156 * \returns a sub-string containing all characters from \c a to \c b, not including the character at \c b.
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
157 */
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
158 String String::mid (int rangeBegin, int rangeEnd) const
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
159 {
147
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
160 modifyIndex(rangeBegin);
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
161 modifyIndex(rangeEnd);
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
162 rangeBegin = max(rangeBegin, 0);
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
163 rangeEnd = min(rangeEnd, length());
129
a556ce001e26 Adjusted String::mid again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 110
diff changeset
164
147
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
165 if (rangeEnd <= rangeBegin)
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
166 return "";
129
a556ce001e26 Adjusted String::mid again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 110
diff changeset
167 else
147
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
168 return m_string.substr(rangeBegin, rangeEnd - rangeBegin);
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
169 }
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
170
147
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
171 /*!
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
172 * \param length Amount of characters to return.
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
173 * \returns the \c length right-most characters of the string.
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
174 */
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
175 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
176 {
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
177 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
178 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
179 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
180 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
181 }
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
182
147
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
183 /*!
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
184 * \brief Finds the first instance of a sub-string.
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
185 * \param subString Sub-string to search within this string.
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
186 * \param startingPosition Position to start looking for the sub-string from.
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
187 * \returns the position the first instance of sub-string found, or -1 if not found.
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
188 */
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
189 int String::find (const char* subString, int startingPosition) const
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
190 {
147
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
191 int position = m_string.find (subString, startingPosition);
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
192
147
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
193 if (position == int (std::string::npos))
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
194 return -1;
147
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
195 else
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
196 return position;
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
197 }
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
198
147
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
199 /*!
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
200 * \brief Finds the first instance of a character.
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
201 * \param character Character to search within this string.
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
202 * \param startingPosition Position to start looking for the character from.
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
203 * \returns the position of the first instance of the provided character found, or -1 if not found.
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
204 */
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
205 int String::find (char character, int startingPosition) const
110
cad1163333b9 Fix compilation on MSVC 2010
Teemu Piippo <crimsondusk64@gmail.com>
parents: 109
diff changeset
206 {
147
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
207 int position = m_string.find (character, startingPosition);
110
cad1163333b9 Fix compilation on MSVC 2010
Teemu Piippo <crimsondusk64@gmail.com>
parents: 109
diff changeset
208
147
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
209 if (position == int (std::string::npos))
110
cad1163333b9 Fix compilation on MSVC 2010
Teemu Piippo <crimsondusk64@gmail.com>
parents: 109
diff changeset
210 return -1;
147
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
211 else
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
212 return position;
110
cad1163333b9 Fix compilation on MSVC 2010
Teemu Piippo <crimsondusk64@gmail.com>
parents: 109
diff changeset
213 }
cad1163333b9 Fix compilation on MSVC 2010
Teemu Piippo <crimsondusk64@gmail.com>
parents: 109
diff changeset
214
147
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
215 /*!
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
216 * \brief Finds the last instance of a sub-string.
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
217 * \param subString Sub-string to search within this string.
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
218 * \param startingPosition Position to start looking for the sub-string from.
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
219 * \returns the position the last instance of sub-string found, or -1 if not found.
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
220 */
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
221 int String::findLast (const char* subString, int startingPosition) const
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
222 {
147
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
223 modifyIndex(startingPosition);
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
224
147
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
225 for (; startingPosition > 0; startingPosition--)
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
226 {
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
227 if (strncmp (chars() + startingPosition, subString, strlen (subString)) == 0)
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
228 return startingPosition;
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
229 }
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
230
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
231 return -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
147
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
234 /*!
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
235 * \brief Converts this string to an integer.
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
236 * \param ok An pointer to a boolean to store whether or not the conversion was successful.
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
237 * If \c ok is \c NULL, the success state is not stored.
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
238 * \param base The base to interpret this string with.
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
239 * \returns the resulting integer.
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
240 */
145
d0aedc9be448 Renamed String methods, and reformatted mystring.h
Teemu Piippo <teemu@compsta2.com>
parents: 137
diff changeset
241 long String::toInt (bool* ok, int base) const
1
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 errno = 0;
147
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
244 char* endPointer;
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
245 long result = strtol (chars(), &endPointer, base);
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
246
147
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
247 if (ok != nullptr)
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
248 *ok = (errno == 0 and *endPointer == '\0');
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
249
147
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
250 return result;
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
251 }
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
252
147
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
253 /*!
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
254 * \brief Converts this string to a floating-point number.
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
255 * \param ok An pointer to a boolean to store whether or not the conversion was successful.
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
256 * If \c ok is \c NULL, the success state is not stored.
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
257 * \returns the resulting floating-point number.
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
258 */
145
d0aedc9be448 Renamed String methods, and reformatted mystring.h
Teemu Piippo <teemu@compsta2.com>
parents: 137
diff changeset
259 float String::toFloat (bool* ok) const
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
260 {
147
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
261 return static_cast<float>(toDouble(ok));
1
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
147
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
264 /*!
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
265 * \brief Converts this string to a double-precision floating-point number.
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
266 * \param ok An pointer to a boolean to store whether or not the conversion was successful.
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
267 * If \c ok is \c NULL, the success state is not stored.
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
268 * \returns the resulting floating-point number.
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
269 */
145
d0aedc9be448 Renamed String methods, and reformatted mystring.h
Teemu Piippo <teemu@compsta2.com>
parents: 137
diff changeset
270 double String::toDouble (bool* ok) const
1
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 errno = 0;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
273 char* endptr;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
274 double i = strtod (chars(), &endptr);
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
275
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
276 if (ok != nullptr)
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
277 *ok = (errno == 0 and *endptr == '\0');
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 return i;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
280 }
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
281
147
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
282 /*!
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
283 * \brief Catenates this string with another string.
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
284 * \param text String to catenate to the end of this string.
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
285 * \returns the resulting string.
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
286 */
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
287 String String::operator+ (const String& text) const
1
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 String newString = *this;
147
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
290 newString.append (text);
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
291 return newString;
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
292 }
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
293
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
294 /*!
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
295 * \brief Catenates this string with another string.
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
296 * \param text String to catenate to the end of this string.
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
297 * \returns the resulting string.
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
298 */
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
299 String String::operator+ (const char* text) const
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
300 {
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
301 String newString = *this;
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
302 newString.append (text);
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
303 return newString;
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
147
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
306 /*!
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
307 * \returns whether or not this string represents a number.
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
308 */
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
309 bool String::isNumeric() const
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
310 {
147
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
311 char* endPointer;
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
312 strtol (chars(), &endPointer, 10);
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
313 return (endPointer != nullptr) and (*endPointer != '\0');
1
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
147
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
316 /*!
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
317 * \param other Sub-string to find from the end of this string.
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
318 * \return whether or not this string ends with the provided sub-string.
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
319 */
145
d0aedc9be448 Renamed String methods, and reformatted mystring.h
Teemu Piippo <teemu@compsta2.com>
parents: 137
diff changeset
320 bool String::endsWith (const String& other) const
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
321 {
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
322 if (length() < other.length())
147
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
323 {
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
324 return false;
147
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
325 }
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
326 else
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
327 {
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
328 const int offset = length() - other.length();
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
329 return strncmp (chars() + offset, other.chars(), other.length()) == 0;
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
330 }
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
331 }
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
332
147
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
333 /*!
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
334 * \param other Sub-string to find from the beginning of this string.
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
335 * \returns whether or not this string begins with the provided sub-string.
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
336 */
145
d0aedc9be448 Renamed String methods, and reformatted mystring.h
Teemu Piippo <teemu@compsta2.com>
parents: 137
diff changeset
337 bool String::startsWith (const String& other) const
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
338 {
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
339 if (length() < other.length())
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
340 return false;
147
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
341 else
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
342 return strncmp (chars(), other.chars(), other.length()) == 0;
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
147
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
345 /*!
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
346 * \brief Formats this string using \c printf -like syntax.
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
347 * \param formatString Template string to use with formatting.
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
348 * \param ... Variadic arguments to use with formatting.
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
349 */
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
350 void __cdecl String::sprintf (const char* formatString, ...)
83
08bfc3d9d2ae Removed format.cpp and format.h, use built-in formatting instead
Teemu Piippo <crimsondusk64@gmail.com>
parents: 73
diff changeset
351 {
08bfc3d9d2ae Removed format.cpp and format.h, use built-in formatting instead
Teemu Piippo <crimsondusk64@gmail.com>
parents: 73
diff changeset
352 va_list args;
147
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
353 va_start (args, formatString);
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
354 this->vsprintf (formatString, args);
83
08bfc3d9d2ae Removed format.cpp and format.h, use built-in formatting instead
Teemu Piippo <crimsondusk64@gmail.com>
parents: 73
diff changeset
355 va_end (args);
08bfc3d9d2ae Removed format.cpp and format.h, use built-in formatting instead
Teemu Piippo <crimsondusk64@gmail.com>
parents: 73
diff changeset
356 }
08bfc3d9d2ae Removed format.cpp and format.h, use built-in formatting instead
Teemu Piippo <crimsondusk64@gmail.com>
parents: 73
diff changeset
357
147
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
358 /*!
148
19e98695e584 Made String::vsprintf behave properly with long strings.
Teemu Piippo <teemu@compsta2.com>
parents: 147
diff changeset
359 * \brief Formats this string using \c vsnprintf, using the provided arguments.
147
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
360 * \param formatString Template string to use with formatting.
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
361 * \param args Variadic arguments to use with formatting.
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
362 */
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
363 void String::vsprintf (const char* formatString, va_list args)
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
364 {
148
19e98695e584 Made String::vsprintf behave properly with long strings.
Teemu Piippo <teemu@compsta2.com>
parents: 147
diff changeset
365 // Copy the argument list so that we have something to provide to vsnprintf in case we have to call it again.
19e98695e584 Made String::vsprintf behave properly with long strings.
Teemu Piippo <teemu@compsta2.com>
parents: 147
diff changeset
366 va_list argsCopy;
19e98695e584 Made String::vsprintf behave properly with long strings.
Teemu Piippo <teemu@compsta2.com>
parents: 147
diff changeset
367 va_copy(argsCopy, args);
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
368
148
19e98695e584 Made String::vsprintf behave properly with long strings.
Teemu Piippo <teemu@compsta2.com>
parents: 147
diff changeset
369 // First, attempt to format using a fixed-size buffer.
149
7643c21d546b Restored the String::vsprintf buffer to 1024 characters, it only was 64 characters long for testing.
Teemu Piippo <teemu@compsta2.com>
parents: 148
diff changeset
370 static char buffer[1024];
148
19e98695e584 Made String::vsprintf behave properly with long strings.
Teemu Piippo <teemu@compsta2.com>
parents: 147
diff changeset
371 size_t length = vsnprintf(buffer, sizeof buffer, formatString, args);
19e98695e584 Made String::vsprintf behave properly with long strings.
Teemu Piippo <teemu@compsta2.com>
parents: 147
diff changeset
372
19e98695e584 Made String::vsprintf behave properly with long strings.
Teemu Piippo <teemu@compsta2.com>
parents: 147
diff changeset
373 if (length < sizeof buffer)
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
374 {
148
19e98695e584 Made String::vsprintf behave properly with long strings.
Teemu Piippo <teemu@compsta2.com>
parents: 147
diff changeset
375 // vsnprintf succeeded in fitting the formatted string into the buffer, so we're done.
19e98695e584 Made String::vsprintf behave properly with long strings.
Teemu Piippo <teemu@compsta2.com>
parents: 147
diff changeset
376 m_string = buffer;
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
377 }
148
19e98695e584 Made String::vsprintf behave properly with long strings.
Teemu Piippo <teemu@compsta2.com>
parents: 147
diff changeset
378 else
19e98695e584 Made String::vsprintf behave properly with long strings.
Teemu Piippo <teemu@compsta2.com>
parents: 147
diff changeset
379 {
19e98695e584 Made String::vsprintf behave properly with long strings.
Teemu Piippo <teemu@compsta2.com>
parents: 147
diff changeset
380 // vsnprintf needs more space, so we have to allocate a new buffer and try again.
19e98695e584 Made String::vsprintf behave properly with long strings.
Teemu Piippo <teemu@compsta2.com>
parents: 147
diff changeset
381 Vector<char> newBuffer(length + 1);
19e98695e584 Made String::vsprintf behave properly with long strings.
Teemu Piippo <teemu@compsta2.com>
parents: 147
diff changeset
382 vsnprintf(newBuffer.data(), length + 1, formatString, argsCopy);
19e98695e584 Made String::vsprintf behave properly with long strings.
Teemu Piippo <teemu@compsta2.com>
parents: 147
diff changeset
383 m_string = newBuffer;
19e98695e584 Made String::vsprintf behave properly with long strings.
Teemu Piippo <teemu@compsta2.com>
parents: 147
diff changeset
384 }
1
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
147
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
387 /*!
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
388 * \brief Joins the elements of this string list into one longer string.
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
389 * \param delimeter The delimeter to place between the element strings.
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
390 * \returns the catenated string.
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
391 */
179
7fc34735178e start cleaning up unused code
Teemu Piippo <teemu@hecknology.net>
parents: 158
diff changeset
392 String join_string_list(const StringList& strings, const String& delimeter)
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
393 {
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
394 String result;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
395
179
7fc34735178e start cleaning up unused code
Teemu Piippo <teemu@hecknology.net>
parents: 158
diff changeset
396 for (const String &item : strings)
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
397 {
145
d0aedc9be448 Renamed String methods, and reformatted mystring.h
Teemu Piippo <teemu@compsta2.com>
parents: 137
diff changeset
398 if (result.isEmpty() == false)
147
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
399 result += delimeter;
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
400
137
485cb6d6b98c Made Range not include the 'max' parameter, replaced a lot of for()-loops with C++11-style range-for-loops
Teemu Piippo <teemu@compsta2.com>
parents: 129
diff changeset
401 result += item;
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
402 }
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
403
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
404 return result;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
405 }
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
406
147
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
407 /*!
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
408 * \brief Tries to match this string against a mask pattern. In the pattern, '?' refers to one character, and '*' to
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
409 * any number of characters.
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
410 * \param pattern The masking pattern to use for matching.
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
411 * \returns whether or not this string matches the provided pattern.
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
412 */
145
d0aedc9be448 Renamed String methods, and reformatted mystring.h
Teemu Piippo <teemu@compsta2.com>
parents: 137
diff changeset
413 bool String::maskAgainst (const String& pattern) const
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
414 {
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
415 // Elevate to uppercase for case-insensitive matching
145
d0aedc9be448 Renamed String methods, and reformatted mystring.h
Teemu Piippo <teemu@compsta2.com>
parents: 137
diff changeset
416 String pattern_upper = pattern.toUpperCase();
d0aedc9be448 Renamed String methods, and reformatted mystring.h
Teemu Piippo <teemu@compsta2.com>
parents: 137
diff changeset
417 String this_upper = toUpperCase();
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
418 const char* maskstring = pattern_upper.chars();
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
419 const char* mptr = &maskstring[0];
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
420
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
421 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
422 {
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
423 if (*mptr == '?')
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
424 {
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
425 if (*(sptr + 1) == '\0')
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
426 {
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
427 // ? 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
428 // Therefore, mask matching fails
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
429 return false;
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 }
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
432 else if (*mptr == '*')
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
433 {
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
434 char end = *(++mptr);
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
435
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
436 // 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
437 // 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
438 // the string any further.
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
439 if (end == '\0')
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
440 return true;
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 // Skip to the end character
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
443 while (*sptr != end and *sptr != '\0')
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
444 sptr++;
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 // String ended while the mask still had stuff
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
447 if (*sptr == '\0')
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
448 return false;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
449 }
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
450 else if (*sptr != *mptr)
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
451 return false;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
452
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
453 mptr++;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
454 }
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
455
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
456 return true;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
457 }
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
458
147
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
459 /*!
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
460 * \brief Converts a short integer into a string.
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
461 * \param value The value to convert.
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
462 * \returns the resulting string.
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
463 */
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
464 String String::fromNumber (short int value)
66
bd28a5730fd0 - fixed: had problems with integral overloading under 32-bit
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
465 {
147
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
466 char buffer[32];
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
467 ::sprintf (buffer, "%d", value);
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
468 return String (buffer);
66
bd28a5730fd0 - fixed: had problems with integral overloading under 32-bit
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
469 }
bd28a5730fd0 - fixed: had problems with integral overloading under 32-bit
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
470
147
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
471 /*!
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
472 * \brief Converts an integer into a string.
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
473 * \param value The value to convert.
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
474 * \returns the resulting string.
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
475 */
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
476 String String::fromNumber (int value)
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
477 {
147
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
478 char buffer[32];
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
479 ::sprintf (buffer, "%d", value);
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
480 return String (buffer);
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
481 }
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
482
147
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
483 /*!
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
484 * \brief Converts a long integer into a string.
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
485 * \param value The value to convert.
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
486 * \returns the resulting string.
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
487 */
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
488 String String::fromNumber (long int value)
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
489 {
147
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
490 char buffer[32];
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
491 ::sprintf (buffer, "%ld", value);
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
492 return String (buffer);
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
493 }
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
494
147
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
495 /*!
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
496 * \brief Converts an unsigned short integer into a string.
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
497 * \param value The value to convert.
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
498 * \returns the resulting string.
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
499 */
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
500 String String::fromNumber (unsigned short int value)
66
bd28a5730fd0 - fixed: had problems with integral overloading under 32-bit
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
501 {
147
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
502 char buffer[32];
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
503 ::sprintf (buffer, "%u", value);
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
504 return String (buffer);
66
bd28a5730fd0 - fixed: had problems with integral overloading under 32-bit
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
505 }
bd28a5730fd0 - fixed: had problems with integral overloading under 32-bit
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
506
147
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
507 /*!
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
508 * \brief Converts an unsigned integer into a string.
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
509 * \param value The value to convert.
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
510 * \returns the resulting string.
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
511 */
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
512 String String::fromNumber (unsigned int value)
66
bd28a5730fd0 - fixed: had problems with integral overloading under 32-bit
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
513 {
147
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
514 char buffer[32];
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
515 ::sprintf (buffer, "%u", value);
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
516 return String (buffer);
66
bd28a5730fd0 - fixed: had problems with integral overloading under 32-bit
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
517 }
bd28a5730fd0 - fixed: had problems with integral overloading under 32-bit
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
518
147
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
519 /*!
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
520 * \brief Converts an unsigned long integer into a string.
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
521 * \param value The value to convert.
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
522 * \returns the resulting string.
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
523 */
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
524 String String::fromNumber (unsigned long int value)
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
525 {
147
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
526 char buffer[32];
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
527 ::sprintf (buffer, "%lu", value);
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
528 return String (buffer);
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
529 }
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
530
147
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
531 /*!
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
532 * \brief Converts a double-precision floating point number into a string, using the "%f" format specifier.
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
533 * \param value The value to convert.
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
534 * \returns the resulting string.
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
535 */
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
536 String String::fromNumber (double value)
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
537 {
147
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
538 char buffer[64];
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
539 ::sprintf (buffer, "%f", value);
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
540 return String (buffer);
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
541 }
10
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents: 5
diff changeset
542
147
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
543 /*!
157
42bb29924218 Bytestream now behaves more like a cursor. It does not store the data anymore, rather it leaves the user to specify a vector to use for storage.
Teemu Piippo <teemu@compsta2.com>
parents: 149
diff changeset
544 * \brief Constructs a string from a vector of bytes. The bytes do not have to be null-terminated.
42bb29924218 Bytestream now behaves more like a cursor. It does not store the data anymore, rather it leaves the user to specify a vector to use for storage.
Teemu Piippo <teemu@compsta2.com>
parents: 149
diff changeset
545 * \param bytes Bytes to use for construction
42bb29924218 Bytestream now behaves more like a cursor. It does not store the data anymore, rather it leaves the user to specify a vector to use for storage.
Teemu Piippo <teemu@compsta2.com>
parents: 149
diff changeset
546 * \returns the resulting string.
42bb29924218 Bytestream now behaves more like a cursor. It does not store the data anymore, rather it leaves the user to specify a vector to use for storage.
Teemu Piippo <teemu@compsta2.com>
parents: 149
diff changeset
547 */
158
de7574d292ad Added the ByteArray typedef for Vector<unsigned char>
Teemu Piippo <teemu@compsta2.com>
parents: 157
diff changeset
548 String String::fromBytes(const ByteArray& bytes)
157
42bb29924218 Bytestream now behaves more like a cursor. It does not store the data anymore, rather it leaves the user to specify a vector to use for storage.
Teemu Piippo <teemu@compsta2.com>
parents: 149
diff changeset
549 {
42bb29924218 Bytestream now behaves more like a cursor. It does not store the data anymore, rather it leaves the user to specify a vector to use for storage.
Teemu Piippo <teemu@compsta2.com>
parents: 149
diff changeset
550 return String(reinterpret_cast<const Vector<char>&>(bytes));
42bb29924218 Bytestream now behaves more like a cursor. It does not store the data anymore, rather it leaves the user to specify a vector to use for storage.
Teemu Piippo <teemu@compsta2.com>
parents: 149
diff changeset
551 }
42bb29924218 Bytestream now behaves more like a cursor. It does not store the data anymore, rather it leaves the user to specify a vector to use for storage.
Teemu Piippo <teemu@compsta2.com>
parents: 149
diff changeset
552
42bb29924218 Bytestream now behaves more like a cursor. It does not store the data anymore, rather it leaves the user to specify a vector to use for storage.
Teemu Piippo <teemu@compsta2.com>
parents: 149
diff changeset
553 /*!
147
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
554 * \returns the MD5-checksum of this string.
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
555 */
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
556 String String::md5() const
10
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents: 5
diff changeset
557 {
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents: 5
diff changeset
558 char checksum[33];
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents: 5
diff changeset
559 CalculateMD5 (reinterpret_cast<const unsigned char*> (chars()), length(), checksum);
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents: 5
diff changeset
560 checksum[sizeof checksum - 1] = '\0';
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents: 5
diff changeset
561 return String (checksum);
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents: 5
diff changeset
562 }
12
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 10
diff changeset
563
147
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
564 /*!
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
565 * \brief Removes leading and trailing whitespace from this string. Alternatively a custom filter can be used to strip
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
566 * something else than whitespace.
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
567 * \param filter The filtering function to use.
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
568 */
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
569 void String::normalize (int (*filter)(int))
12
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 10
diff changeset
570 {
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 10
diff changeset
571 int a = 0;
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 10
diff changeset
572 int b = length() - 1;
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 10
diff changeset
573
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 10
diff changeset
574 while ((*filter) (m_string[a]) and a != b)
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 10
diff changeset
575 ++a;
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 10
diff changeset
576
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 10
diff changeset
577 while ((*filter) (m_string[b]) and a != b)
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 10
diff changeset
578 --b;
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 10
diff changeset
579
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 10
diff changeset
580 if (a == b)
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 10
diff changeset
581 m_string = "";
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 10
diff changeset
582 else if (a != 0 or b != length() - 1)
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 10
diff changeset
583 m_string = m_string.substr (a, b - a + 1);
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 10
diff changeset
584 }
88
08ccaf26cffd Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents: 83
diff changeset
585
147
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
586 /*!
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
587 * \returns a version of this string without leading or trailing whitespace. Alternatively a custom filter can be used
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
588 * to strip something else than whitespace.
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
589 */
107
ca10837a2a9e Backport string changes from protocol5
Teemu Piippo <crimsondusk64@gmail.com>
parents: 105
diff changeset
590 String String::normalized (int (*filter)(int)) const
ca10837a2a9e Backport string changes from protocol5
Teemu Piippo <crimsondusk64@gmail.com>
parents: 105
diff changeset
591 {
ca10837a2a9e Backport string changes from protocol5
Teemu Piippo <crimsondusk64@gmail.com>
parents: 105
diff changeset
592 String result = *this;
ca10837a2a9e Backport string changes from protocol5
Teemu Piippo <crimsondusk64@gmail.com>
parents: 105
diff changeset
593 result.normalize(filter);
ca10837a2a9e Backport string changes from protocol5
Teemu Piippo <crimsondusk64@gmail.com>
parents: 105
diff changeset
594 return result;
ca10837a2a9e Backport string changes from protocol5
Teemu Piippo <crimsondusk64@gmail.com>
parents: 105
diff changeset
595 }
ca10837a2a9e Backport string changes from protocol5
Teemu Piippo <crimsondusk64@gmail.com>
parents: 105
diff changeset
596
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
597 END_ZFC_NAMESPACE

mercurial