Sat, 12 Jul 2014 23:04:46 +0300
- changed all source files to use my correct legal name instead of my calling name
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1 | /* |
133
dbbdb870c835
- changed all source files to use my correct legal name instead of my calling name
Teemu Piippo <crimsondusk64@gmail.com>
parents:
128
diff
changeset
|
2 | Copyright 2012-2014 Teemu Piippo |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
3 | All rights reserved. |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
4 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
5 | Redistribution and use in source and binary forms, with or without |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
6 | modification, are permitted provided that the following conditions |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
7 | are met: |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
8 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
9 | 1. Redistributions of source code must retain the above copyright |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
10 | notice, this list of conditions and the following disclaimer. |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
11 | 2. Redistributions in binary form must reproduce the above copyright |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
12 | notice, this list of conditions and the following disclaimer in the |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
13 | documentation and/or other materials provided with the distribution. |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
14 | 3. The name of the author may not be used to endorse or promote products |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
15 | derived from this software without specific prior written permission. |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
16 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
17 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
18 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
19 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
20 | IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
21 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
22 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
23 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
24 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
26 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
27 | */ |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
28 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
29 | #ifndef BOTC_STRING_H |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
30 | #define BOTC_STRING_H |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
31 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
32 | #include <deque> |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
33 | #include <string> |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
34 | #include <stdarg.h> |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
35 | #include "types.h" |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
36 | #include "list.h" |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
37 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
38 | class String; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
39 | class StringList; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
40 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
41 | // ============================================================================= |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
42 | // |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
43 | class String |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
44 | { |
128
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
45 | public: |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
46 | String() {} |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
47 | |
128
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
48 | explicit String (char a) : |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
49 | _string ({ a, '\0' }) {} |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
50 | |
128
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
51 | String (const char* data) : |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
52 | _string (data) {} |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
53 | |
128
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
54 | String (const std::string& data) : |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
55 | _string (data) {} |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
56 | |
128
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
57 | inline void append (const char* data); |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
58 | inline void append (char data); |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
59 | inline void append (const String& data); |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
60 | inline std::string::iterator begin(); |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
61 | inline std::string::const_iterator begin() const; |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
62 | void dump() const; |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
63 | inline void clear(); |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
64 | int compare (const String& other) const; |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
65 | int count (char needle) const; |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
66 | inline const char* c_str() const; |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
67 | inline std::string::iterator end(); |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
68 | inline std::string::const_iterator end() const; |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
69 | bool endsWith (const String& other); |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
70 | int firstIndexOf (const char* c, int a = 0) const; |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
71 | String toLowercase() const; |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
72 | inline int indexDifference (int a, int b); |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
73 | inline void insert (int pos, char c); |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
74 | inline bool isEmpty() const; |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
75 | bool isNumeric() const; |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
76 | int lastIndexOf (const char* c, int a = -1) const; |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
77 | inline int length() const; |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
78 | bool maskAgainst (const String& pattern) const; |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
79 | String mid (long a, long b = -1) const; |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
80 | inline void modifyIndex (int& a); |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
81 | inline void prepend (String a); |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
82 | inline void removeAt (int pos); |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
83 | inline void remove (int pos, int len); |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
84 | inline void removeFromEnd (int len); |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
85 | inline void removeFromStart (int len); |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
86 | void replace (const char* a, const char* b); |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
87 | inline void replace (int pos, int n, const String& a); |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
88 | inline void shrinkToFit(); |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
89 | StringList split (const String& del) const; |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
90 | StringList split (char del) const; |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
91 | void sprintf (const char* fmtstr, ...); |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
92 | bool startsWith (const String& other); |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
93 | inline const std::string& stdString() const; |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
94 | inline String strip (char unwanted); |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
95 | String strip (const List<char>& unwanted); |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
96 | double toDouble (bool* ok = nullptr) const; |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
97 | float toFloat (bool* ok = nullptr) const; |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
98 | long toLong (bool* ok = nullptr, int base = 10) const; |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
99 | void trim (int n); |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
100 | String toUppercase() const; |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
101 | int wordPosition (int n) const; |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
102 | |
128
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
103 | static String fromNumber (int a); |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
104 | static String fromNumber (long a); |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
105 | |
128
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
106 | String operator+ (const String& data) const; |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
107 | String operator+ (const char* data) const; |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
108 | inline String operator+ (int num) const; |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
109 | inline String& operator+= (const String data); |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
110 | inline String& operator+= (const char* data); |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
111 | inline String& operator+= (int num); |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
112 | inline String& operator+= (const char data); |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
113 | inline String operator- (int n) const; |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
114 | inline String& operator-= (int n); |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
115 | inline bool operator== (const String& other) const; |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
116 | inline bool operator== (const char* other) const; |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
117 | inline bool operator!= (const String& other) const; |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
118 | inline bool operator!= (const char* other) const; |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
119 | inline bool operator> (const String& other) const; |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
120 | inline bool operator< (const String& other) const; |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
121 | inline operator const char*() const; |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
122 | inline operator const std::string&() const; |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
123 | |
128
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
124 | private: |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
125 | std::string _string; |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
126 | }; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
127 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
128 | class StringList : public List<String> |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
129 | { |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
130 | public: |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
131 | StringList() {} |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
132 | StringList (std::initializer_list<String> vals) : |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
133 | List<String> (vals) {} |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
134 | StringList (const List<String>& a) : List<String> (a.deque()) {} |
124
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
135 | StringList (const std::deque<String>& a) : List<String> (a) {} |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
136 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
137 | String join (const String& delim); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
138 | }; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
139 | |
128
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
140 | inline bool operator== (const char* a, const String& b); |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
141 | inline String operator+ (const char* a, const String& b); |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
142 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
143 | // ============================================================================= |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
144 | // |
128
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
145 | // IMPLEMENTATIONS |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
146 | // |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
147 | |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
148 | inline bool String::isEmpty() const |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
149 | { |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
150 | return _string[0] == '\0'; |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
151 | } |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
152 | |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
153 | inline void String::append (const char* data) |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
154 | { |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
155 | _string.append (data); |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
156 | } |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
157 | |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
158 | inline void String::append (char data) |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
159 | { |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
160 | _string.push_back (data); |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
161 | } |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
162 | |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
163 | inline void String::append (const String& data) |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
164 | { |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
165 | _string.append (data.c_str()); |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
166 | } |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
167 | |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
168 | inline std::string::iterator String::begin() |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
169 | { |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
170 | return _string.begin(); |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
171 | } |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
172 | |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
173 | inline std::string::const_iterator String::begin() const |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
174 | { |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
175 | return _string.cbegin(); |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
176 | } |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
177 | |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
178 | inline const char* String::c_str() const |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
179 | { |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
180 | return _string.c_str(); |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
181 | } |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
182 | |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
183 | inline std::string::iterator String::end() |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
184 | { |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
185 | return _string.end(); |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
186 | } |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
187 | |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
188 | inline std::string::const_iterator String::end() const |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
189 | { |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
190 | return _string.end(); |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
191 | } |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
192 | |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
193 | inline void String::clear() |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
194 | { |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
195 | _string.clear(); |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
196 | } |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
197 | |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
198 | inline void String::removeAt (int pos) |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
199 | { |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
200 | _string.erase (_string.begin() + pos); |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
201 | } |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
202 | |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
203 | inline void String::insert (int pos, char c) |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
204 | { |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
205 | _string.insert (_string.begin() + pos, c); |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
206 | } |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
207 | |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
208 | inline int String::length() const |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
209 | { |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
210 | return _string.length(); |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
211 | } |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
212 | |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
213 | inline void String::remove (int pos, int len) |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
214 | { |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
215 | _string.replace (pos, len, ""); |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
216 | } |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
217 | |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
218 | inline void String::removeFromStart (int len) |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
219 | { |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
220 | remove (0, len); |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
221 | } |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
222 | |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
223 | inline void String::removeFromEnd (int len) |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
224 | { |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
225 | remove (length() - len, len); |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
226 | } |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
227 | |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
228 | inline void String::replace (int pos, int n, const String& a) |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
229 | { |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
230 | _string.replace (pos, n, a.c_str()); |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
231 | } |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
232 | |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
233 | inline void String::shrinkToFit() |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
234 | { |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
235 | _string.shrink_to_fit(); |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
236 | } |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
237 | |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
238 | inline const std::string& String::stdString() const |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
239 | { |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
240 | return _string; |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
241 | } |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
242 | |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
243 | inline String String::strip (char unwanted) |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
244 | { |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
245 | return strip ({unwanted}); |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
246 | } |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
247 | |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
248 | inline String String::operator+ (int num) const |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
249 | { |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
250 | return *this + String::fromNumber (num); |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
251 | } |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
252 | |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
253 | inline String& String::operator+= (const String data) |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
254 | { |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
255 | append (data); |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
256 | return *this; |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
257 | } |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
258 | |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
259 | inline String& String::operator+= (const char* data) |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
260 | { |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
261 | append (data); |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
262 | return *this; |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
263 | } |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
264 | |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
265 | inline String& String::operator+= (int num) |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
266 | { |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
267 | return operator+= (String::fromNumber (num)); |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
268 | } |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
269 | |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
270 | inline void String::prepend (String a) |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
271 | { |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
272 | _string = (a + _string).stdString(); |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
273 | } |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
274 | |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
275 | inline String& String::operator+= (const char data) |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
276 | { |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
277 | append (data); |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
278 | return *this; |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
279 | } |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
280 | |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
281 | inline String String::operator- (int n) const |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
282 | { |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
283 | String newString = _string; |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
284 | newString -= n; |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
285 | return newString; |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
286 | } |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
287 | |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
288 | inline String& String::operator-= (int n) |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
289 | { |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
290 | trim (n); |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
291 | return *this; |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
292 | } |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
293 | |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
294 | inline bool String::operator== (const String& other) const |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
295 | { |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
296 | return stdString() == other.stdString(); |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
297 | } |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
298 | |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
299 | inline bool String::operator== (const char* other) const |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
300 | { |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
301 | return operator== (String (other)); |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
302 | } |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
303 | |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
304 | inline bool String::operator!= (const String& other) const |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
305 | { |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
306 | return stdString() != other.stdString(); |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
307 | } |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
308 | |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
309 | inline bool String::operator!= (const char* other) const |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
310 | { |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
311 | return operator!= (String (other)); |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
312 | } |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
313 | |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
314 | inline bool String::operator> (const String& other) const |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
315 | { |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
316 | return stdString() > other.stdString(); |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
317 | } |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
318 | |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
319 | inline bool String::operator< (const String& other) const |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
320 | { |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
321 | return stdString() < other.stdString(); |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
322 | } |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
323 | |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
324 | inline String::operator const char*() const |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
325 | { |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
326 | return c_str(); |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
327 | } |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
328 | |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
329 | inline String::operator const std::string&() const |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
330 | { |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
331 | return stdString(); |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
332 | } |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
333 | |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
334 | inline void String::modifyIndex (int& a) |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
335 | { |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
336 | if (a < 0) |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
337 | a = length() - a; |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
338 | } |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
339 | |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
340 | inline int String::indexDifference (int a, int b) |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
341 | { |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
342 | modifyIndex (a); |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
343 | modifyIndex (b); |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
344 | return b - a; |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
345 | } |
186ebeea2a85
- refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
346 | |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
347 | inline bool operator== (const char* a, const String& b) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
348 | { |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
349 | return b == a; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
350 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
351 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
352 | inline String operator+ (const char* a, const String& b) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
353 | { |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
354 | return String (a) + b; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
355 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
356 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
357 | #endif // BOTC_STRING_H |