sources/mystring.cpp

Wed, 20 Jul 2016 17:53:13 +0300

author
Teemu Piippo <teemu@compsta2.com>
date
Wed, 20 Jul 2016 17:53:13 +0300
changeset 149
7643c21d546b
parent 148
19e98695e584
child 150
37db42ad451a
child 157
42bb29924218
permissions
-rw-r--r--

Restored the String::vsprintf buffer to 1024 characters, it only was 64 characters long for testing.

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 * \brief Removes all instances of an unwanted character from 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 * \param unwanted Character to remove.
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
53 */
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
54 void String::strip (char unwanted)
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
55 {
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
56 for (int pos = 0; (pos = find (unwanted)) != -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
57 removeAt (pos--);
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
58 }
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
59
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
60 /*!
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
61 * \brief Removes all instances of multiple characters from 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
62 * \param unwanted Characters to remove.
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
63 */
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
64 void String::strip (const List<char>& unwanted)
110
cad1163333b9 Fix compilation on MSVC 2010
Teemu Piippo <crimsondusk64@gmail.com>
parents: 109
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 for (char character : unwanted)
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 strip(character);
110
cad1163333b9 Fix compilation on MSVC 2010
Teemu Piippo <crimsondusk64@gmail.com>
parents: 109
diff changeset
68 }
cad1163333b9 Fix compilation on MSVC 2010
Teemu Piippo <crimsondusk64@gmail.com>
parents: 109
diff changeset
69
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
70 /*!
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
71 * \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
72 */
145
d0aedc9be448 Renamed String methods, and reformatted mystring.h
Teemu Piippo <teemu@compsta2.com>
parents: 137
diff changeset
73 String String::toUpperCase() const
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
74 {
88
08ccaf26cffd Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents: 83
diff changeset
75 String result (m_string);
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
76
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
77 for (char &ch : result)
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
78 {
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
79 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
80 ch -= 'a' - 'A';
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
81 }
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
82
88
08ccaf26cffd Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents: 83
diff changeset
83 return result;
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
84 }
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
85
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
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 * \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
88 */
145
d0aedc9be448 Renamed String methods, and reformatted mystring.h
Teemu Piippo <teemu@compsta2.com>
parents: 137
diff changeset
89 String String::toLowerCase() const
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
90 {
88
08ccaf26cffd Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents: 83
diff changeset
91 String result (m_string);
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
92
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
93 for (char &ch : result)
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
94 {
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
95 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
96 ch += 'a' - 'A';
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
97 }
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
98
88
08ccaf26cffd Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents: 83
diff changeset
99 return result;
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
100 }
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
101
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
102 /*!
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
103 * \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
104 * \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
105 * \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
106 */
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
107 StringList String::split (char delimeter) const
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
108 {
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
109 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
110 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
111 return split (delimeterString);
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
112 }
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
113
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
114 /*!
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
115 * \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
116 * \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
117 * \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
118 */
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
119 StringList String::split (const String& delimeter) const
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
120 {
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
121 StringList result;
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
122 int a = 0;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
123 int b;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
124
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
125 // 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
126 while ((b = find (delimeter, a)) != -1)
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
127 {
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
128 String sub = mid (a, b);
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
129
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
130 if (sub.length() > 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
131 result << sub;
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
132
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
133 a = b + delimeter.length();
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
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
136 // 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
137 if (a < (int) 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
138 result.append (mid (a, length()));
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
139
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
140 return result;
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
141 }
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
142
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
143 /*!
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
144 * \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
145 * \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
146 * \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
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
148 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
149 {
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
150 int position;
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
151
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
152 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
153 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
154 }
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
155
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
156 /*!
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 * \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
158 * \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
159 */
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 int String::count (char character) const
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
161 {
88
08ccaf26cffd Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents: 83
diff changeset
162 int result = 0;
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
163
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
164 for (char ch : *this)
88
08ccaf26cffd Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents: 83
diff changeset
165 {
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
166 if (ch == character)
88
08ccaf26cffd Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents: 83
diff changeset
167 result++;
08ccaf26cffd Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents: 83
diff changeset
168 }
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
169
88
08ccaf26cffd Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents: 83
diff changeset
170 return result;
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
171 }
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
172
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
173 /*!
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 * \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
175 * \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
176 * \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
177 */
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
178 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
179 {
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
180 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
181 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
182 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
183 rangeEnd = min(rangeEnd, length());
129
a556ce001e26 Adjusted String::mid again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 110
diff changeset
184
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
185 if (rangeEnd <= rangeBegin)
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
186 return "";
129
a556ce001e26 Adjusted String::mid again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 110
diff changeset
187 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
188 return m_string.substr(rangeBegin, rangeEnd - rangeBegin);
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
189 }
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
190
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 /*!
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
192 * \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
193 * \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
194 */
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
195 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
196 {
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
197 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
198 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
199 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
200 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
201 }
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
202
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
203 /*!
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 * \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
205 * \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
206 * \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
207 * \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
208 */
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 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
210 {
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 int position = m_string.find (subString, startingPosition);
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
212
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
213 if (position == int (std::string::npos))
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
214 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
215 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
216 return position;
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
217 }
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
218
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
219 /*!
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 * \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
221 * \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
222 * \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
223 * \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
224 */
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 int String::find (char character, int startingPosition) const
110
cad1163333b9 Fix compilation on MSVC 2010
Teemu Piippo <crimsondusk64@gmail.com>
parents: 109
diff changeset
226 {
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
227 int position = m_string.find (character, startingPosition);
110
cad1163333b9 Fix compilation on MSVC 2010
Teemu Piippo <crimsondusk64@gmail.com>
parents: 109
diff changeset
228
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
229 if (position == int (std::string::npos))
110
cad1163333b9 Fix compilation on MSVC 2010
Teemu Piippo <crimsondusk64@gmail.com>
parents: 109
diff changeset
230 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
231 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
232 return position;
110
cad1163333b9 Fix compilation on MSVC 2010
Teemu Piippo <crimsondusk64@gmail.com>
parents: 109
diff changeset
233 }
cad1163333b9 Fix compilation on MSVC 2010
Teemu Piippo <crimsondusk64@gmail.com>
parents: 109
diff changeset
234
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
235 /*!
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 * \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
237 * \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
238 * \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
239 * \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
240 */
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
241 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
242 {
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
243 modifyIndex(startingPosition);
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
244
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
245 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
246 {
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 (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
248 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
249 }
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
250
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
251 return -1;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
252 }
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
253
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
254 /*!
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 * \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
256 * \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
257 * 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
258 * \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
259 * \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
260 */
145
d0aedc9be448 Renamed String methods, and reformatted mystring.h
Teemu Piippo <teemu@compsta2.com>
parents: 137
diff changeset
261 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
262 {
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
263 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
264 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
265 long result = strtol (chars(), &endPointer, base);
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
266
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
267 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
268 *ok = (errno == 0 and *endPointer == '\0');
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
269
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
270 return result;
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
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
273 /*!
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
274 * \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
275 * \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
276 * 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
277 * \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
278 */
145
d0aedc9be448 Renamed String methods, and reformatted mystring.h
Teemu Piippo <teemu@compsta2.com>
parents: 137
diff changeset
279 float String::toFloat (bool* ok) const
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
280 {
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
281 return static_cast<float>(toDouble(ok));
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
282 }
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
283
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
284 /*!
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 * \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
286 * \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
287 * 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
288 * \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
289 */
145
d0aedc9be448 Renamed String methods, and reformatted mystring.h
Teemu Piippo <teemu@compsta2.com>
parents: 137
diff changeset
290 double String::toDouble (bool* ok) const
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
291 {
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
292 errno = 0;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
293 char* endptr;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
294 double i = strtod (chars(), &endptr);
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
295
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
296 if (ok != nullptr)
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
297 *ok = (errno == 0 and *endptr == '\0');
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
298
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
299 return i;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
300 }
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
301
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
302 /*!
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
303 * \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
304 * \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
305 * \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
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 String String::operator+ (const String& text) const
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
308 {
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
309 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
310 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
311 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
312 }
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
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
314 /*!
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
315 * \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
316 * \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
317 * \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
318 */
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 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
320 {
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
321 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
322 newString.append (text);
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
323 return newString;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
324 }
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
325
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
326 /*!
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 * \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
328 */
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 bool String::isNumeric() const
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
330 {
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
331 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
332 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
333 return (endPointer != nullptr) and (*endPointer != '\0');
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
334 }
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
335
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
336 /*!
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
337 * \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
338 * \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
339 */
145
d0aedc9be448 Renamed String methods, and reformatted mystring.h
Teemu Piippo <teemu@compsta2.com>
parents: 137
diff changeset
340 bool String::endsWith (const String& other) const
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
341 {
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
342 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
343 {
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
344 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
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 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
347 {
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 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
349 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
350 }
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
351 }
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
352
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 /*!
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 * \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
355 * \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
356 */
145
d0aedc9be448 Renamed String methods, and reformatted mystring.h
Teemu Piippo <teemu@compsta2.com>
parents: 137
diff changeset
357 bool String::startsWith (const String& other) const
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
358 {
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
359 if (length() < other.length())
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
360 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
361 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
362 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
363 }
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
364
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
365 /*!
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
366 * \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
367 * \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
368 * \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
369 */
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
370 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
371 {
08bfc3d9d2ae Removed format.cpp and format.h, use built-in formatting instead
Teemu Piippo <crimsondusk64@gmail.com>
parents: 73
diff changeset
372 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
373 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
374 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
375 va_end (args);
08bfc3d9d2ae Removed format.cpp and format.h, use built-in formatting instead
Teemu Piippo <crimsondusk64@gmail.com>
parents: 73
diff changeset
376 }
08bfc3d9d2ae Removed format.cpp and format.h, use built-in formatting instead
Teemu Piippo <crimsondusk64@gmail.com>
parents: 73
diff changeset
377
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
378 /*!
148
19e98695e584 Made String::vsprintf behave properly with long strings.
Teemu Piippo <teemu@compsta2.com>
parents: 147
diff changeset
379 * \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
380 * \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
381 * \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
382 */
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
383 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
384 {
148
19e98695e584 Made String::vsprintf behave properly with long strings.
Teemu Piippo <teemu@compsta2.com>
parents: 147
diff changeset
385 // 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
386 va_list argsCopy;
19e98695e584 Made String::vsprintf behave properly with long strings.
Teemu Piippo <teemu@compsta2.com>
parents: 147
diff changeset
387 va_copy(argsCopy, args);
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
388
148
19e98695e584 Made String::vsprintf behave properly with long strings.
Teemu Piippo <teemu@compsta2.com>
parents: 147
diff changeset
389 // 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
390 static char buffer[1024];
148
19e98695e584 Made String::vsprintf behave properly with long strings.
Teemu Piippo <teemu@compsta2.com>
parents: 147
diff changeset
391 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
392
19e98695e584 Made String::vsprintf behave properly with long strings.
Teemu Piippo <teemu@compsta2.com>
parents: 147
diff changeset
393 if (length < sizeof buffer)
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
394 {
148
19e98695e584 Made String::vsprintf behave properly with long strings.
Teemu Piippo <teemu@compsta2.com>
parents: 147
diff changeset
395 // 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
396 m_string = buffer;
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
397 }
148
19e98695e584 Made String::vsprintf behave properly with long strings.
Teemu Piippo <teemu@compsta2.com>
parents: 147
diff changeset
398 else
19e98695e584 Made String::vsprintf behave properly with long strings.
Teemu Piippo <teemu@compsta2.com>
parents: 147
diff changeset
399 {
19e98695e584 Made String::vsprintf behave properly with long strings.
Teemu Piippo <teemu@compsta2.com>
parents: 147
diff changeset
400 // 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
401 Vector<char> newBuffer(length + 1);
19e98695e584 Made String::vsprintf behave properly with long strings.
Teemu Piippo <teemu@compsta2.com>
parents: 147
diff changeset
402 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
403 m_string = newBuffer;
19e98695e584 Made String::vsprintf behave properly with long strings.
Teemu Piippo <teemu@compsta2.com>
parents: 147
diff changeset
404 }
1
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 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
409 * \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
410 * \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
411 */
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 String StringList::join (const String& delimeter)
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
413 {
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
414 String result;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
415
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
416 for (const String &item : container())
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
417 {
145
d0aedc9be448 Renamed String methods, and reformatted mystring.h
Teemu Piippo <teemu@compsta2.com>
parents: 137
diff changeset
418 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
419 result += delimeter;
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
420
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
421 result += item;
1
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
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
424 return result;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
425 }
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
426
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
427 /*!
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
428 * \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
429 * 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
430 * \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
431 * \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
432 */
145
d0aedc9be448 Renamed String methods, and reformatted mystring.h
Teemu Piippo <teemu@compsta2.com>
parents: 137
diff changeset
433 bool String::maskAgainst (const String& pattern) const
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
434 {
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
435 // 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
436 String pattern_upper = pattern.toUpperCase();
d0aedc9be448 Renamed String methods, and reformatted mystring.h
Teemu Piippo <teemu@compsta2.com>
parents: 137
diff changeset
437 String this_upper = toUpperCase();
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
438 const char* maskstring = pattern_upper.chars();
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
439 const char* mptr = &maskstring[0];
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
440
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
441 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
442 {
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
443 if (*mptr == '?')
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
444 {
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
445 if (*(sptr + 1) == '\0')
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
446 {
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
447 // ? 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
448 // Therefore, mask matching fails
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
449 return false;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
450 }
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
451 }
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
452 else if (*mptr == '*')
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
453 {
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
454 char end = *(++mptr);
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 // 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
457 // 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
458 // the string any further.
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
459 if (end == '\0')
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
460 return true;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
461
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
462 // Skip to the end character
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
463 while (*sptr != end and *sptr != '\0')
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
464 sptr++;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
465
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
466 // String ended while the mask still had stuff
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
467 if (*sptr == '\0')
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
468 return false;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
469 }
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
470 else if (*sptr != *mptr)
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
471 return false;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
472
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
473 mptr++;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
474 }
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
475
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
476 return true;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
477 }
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
478
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
479 /*!
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 * \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
481 * \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
482 * \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
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 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
485 {
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
486 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
487 ::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
488 return String (buffer);
66
bd28a5730fd0 - fixed: had problems with integral overloading under 32-bit
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
489 }
bd28a5730fd0 - fixed: had problems with integral overloading under 32-bit
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
490
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
491 /*!
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 * \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
493 * \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
494 * \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
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 String String::fromNumber (int value)
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
497 {
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
498 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
499 ::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
500 return String (buffer);
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
501 }
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
502
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
503 /*!
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 * \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
505 * \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
506 * \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
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 String String::fromNumber (long int value)
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
509 {
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
510 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
511 ::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
512 return String (buffer);
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
513 }
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
514
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
515 /*!
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 * \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
517 * \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
518 * \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
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 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
521 {
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
522 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
523 ::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
524 return String (buffer);
66
bd28a5730fd0 - fixed: had problems with integral overloading under 32-bit
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
525 }
bd28a5730fd0 - fixed: had problems with integral overloading under 32-bit
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
526
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
527 /*!
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 * \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
529 * \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
530 * \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
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 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
533 {
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
534 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
535 ::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
536 return String (buffer);
66
bd28a5730fd0 - fixed: had problems with integral overloading under 32-bit
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
537 }
bd28a5730fd0 - fixed: had problems with integral overloading under 32-bit
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
538
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
539 /*!
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 * \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
541 * \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
542 * \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
543 */
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
544 String String::fromNumber (unsigned long int value)
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
545 {
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
546 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
547 ::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
548 return String (buffer);
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
549 }
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
550
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
551 /*!
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
552 * \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
553 * \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
554 * \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
555 */
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
556 String String::fromNumber (double value)
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
557 {
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
558 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
559 ::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
560 return String (buffer);
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
561 }
10
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents: 5
diff changeset
562
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
563 /*!
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 * \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
565 */
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
566 String String::md5() const
10
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents: 5
diff changeset
567 {
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents: 5
diff changeset
568 char checksum[33];
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents: 5
diff changeset
569 CalculateMD5 (reinterpret_cast<const unsigned char*> (chars()), length(), checksum);
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents: 5
diff changeset
570 checksum[sizeof checksum - 1] = '\0';
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents: 5
diff changeset
571 return String (checksum);
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents: 5
diff changeset
572 }
12
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 10
diff changeset
573
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
574 /*!
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
575 * \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
576 * 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
577 * \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
578 */
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
579 void String::normalize (int (*filter)(int))
12
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 10
diff changeset
580 {
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 10
diff changeset
581 int a = 0;
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 10
diff changeset
582 int b = length() - 1;
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 10
diff changeset
583
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 10
diff changeset
584 while ((*filter) (m_string[a]) and a != b)
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 10
diff changeset
585 ++a;
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 10
diff changeset
586
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 10
diff changeset
587 while ((*filter) (m_string[b]) and a != b)
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 10
diff changeset
588 --b;
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 10
diff changeset
589
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 10
diff changeset
590 if (a == b)
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 10
diff changeset
591 m_string = "";
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 10
diff changeset
592 else if (a != 0 or b != length() - 1)
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 10
diff changeset
593 m_string = m_string.substr (a, b - a + 1);
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 10
diff changeset
594 }
88
08ccaf26cffd Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents: 83
diff changeset
595
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
596 /*!
12c93c4a137c Documented mystring.cpp. String::trim removed as it does the same as String::removeFromEnd.
Teemu Piippo <teemu@compsta2.com>
parents: 145
diff changeset
597 * \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
598 * 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
599 */
107
ca10837a2a9e Backport string changes from protocol5
Teemu Piippo <crimsondusk64@gmail.com>
parents: 105
diff changeset
600 String String::normalized (int (*filter)(int)) const
ca10837a2a9e Backport string changes from protocol5
Teemu Piippo <crimsondusk64@gmail.com>
parents: 105
diff changeset
601 {
ca10837a2a9e Backport string changes from protocol5
Teemu Piippo <crimsondusk64@gmail.com>
parents: 105
diff changeset
602 String result = *this;
ca10837a2a9e Backport string changes from protocol5
Teemu Piippo <crimsondusk64@gmail.com>
parents: 105
diff changeset
603 result.normalize(filter);
ca10837a2a9e Backport string changes from protocol5
Teemu Piippo <crimsondusk64@gmail.com>
parents: 105
diff changeset
604 return result;
ca10837a2a9e Backport string changes from protocol5
Teemu Piippo <crimsondusk64@gmail.com>
parents: 105
diff changeset
605 }
ca10837a2a9e Backport string changes from protocol5
Teemu Piippo <crimsondusk64@gmail.com>
parents: 105
diff changeset
606
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
607 END_ZFC_NAMESPACE

mercurial