src/stringClass.h

Thu, 24 Jul 2014 16:54:45 +0300

author
Teemu Piippo <crimsondusk64@gmail.com>
date
Thu, 24 Jul 2014 16:54:45 +0300
changeset 141
68d60e2cfa76
parent 135
8b9132fea327
permissions
-rw-r--r--

- now works properly (still debugging --help)

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);
141
68d60e2cfa76 - now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 135
diff changeset
105 static String fromNumber (double a);
119
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
106
128
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
107 String operator+ (const String& data) const;
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
108 String operator+ (const char* data) const;
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
109 inline String operator+ (int num) const;
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
110 inline String& operator+= (const String data);
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
111 inline String& operator+= (const char* data);
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
112 inline String& operator+= (int num);
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
113 inline String& operator+= (const char data);
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
114 inline String operator- (int n) const;
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
115 inline String& operator-= (int n);
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
116 inline bool operator== (const String& other) const;
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
117 inline bool operator== (const char* other) const;
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
118 inline bool operator!= (const String& other) const;
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
119 inline bool operator!= (const char* 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 bool operator< (const String& other) const;
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
122 inline operator const char*() const;
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
123 inline operator const std::string&() const;
119
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
124
128
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
125 private:
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
126 std::string _string;
119
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
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
129 class StringList : public List<String>
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
130 {
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
131 public:
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
132 StringList() {}
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
133 StringList (std::initializer_list<String> vals) :
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
134 List<String> (vals) {}
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
135 StringList (const List<String>& a) : List<String> (a.deque()) {}
124
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
136 StringList (const std::deque<String>& a) : List<String> (a) {}
119
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
137
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
138 String join (const String& delim);
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
139 };
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
140
128
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
141 inline bool operator== (const char* a, const String& b);
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
142 inline String operator+ (const char* a, const String& b);
119
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
143
141
68d60e2cfa76 - now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 135
diff changeset
144 String basename (String const& path);
68d60e2cfa76 - now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 135
diff changeset
145 String dirname (String const& path);
68d60e2cfa76 - now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 135
diff changeset
146
119
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
147 // =============================================================================
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
148 //
128
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
149 // IMPLEMENTATIONS
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
150 //
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 inline bool String::isEmpty() const
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
153 {
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
154 return _string[0] == '\0';
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
155 }
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 inline void String::append (const char* data)
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
158 {
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
159 _string.append (data);
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
160 }
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 inline void String::append (char data)
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
163 {
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
164 _string.push_back (data);
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
165 }
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 inline void String::append (const String& data)
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
168 {
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
169 _string.append (data.c_str());
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
170 }
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 inline std::string::iterator String::begin()
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
173 {
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
174 return _string.begin();
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
175 }
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 inline std::string::const_iterator String::begin() const
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
178 {
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
179 return _string.cbegin();
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
180 }
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 inline const char* String::c_str() const
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
183 {
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
184 return _string.c_str();
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
185 }
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 inline std::string::iterator String::end()
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
188 {
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
189 return _string.end();
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
190 }
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 inline std::string::const_iterator String::end() const
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
193 {
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
194 return _string.end();
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
195 }
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 inline void String::clear()
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
198 {
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
199 _string.clear();
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
200 }
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 inline void String::removeAt (int pos)
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
203 {
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
204 _string.erase (_string.begin() + pos);
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
205 }
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 inline void String::insert (int pos, char c)
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
208 {
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
209 _string.insert (_string.begin() + pos, c);
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
210 }
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 inline int String::length() const
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
213 {
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
214 return _string.length();
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
215 }
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 inline void String::remove (int pos, int len)
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
218 {
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
219 _string.replace (pos, len, "");
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
220 }
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 inline void String::removeFromStart (int len)
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
223 {
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
224 remove (0, len);
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
225 }
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 inline void String::removeFromEnd (int len)
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
228 {
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
229 remove (length() - len, len);
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
230 }
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 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
233 {
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
234 _string.replace (pos, n, a.c_str());
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
235 }
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 inline void String::shrinkToFit()
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
238 {
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
239 _string.shrink_to_fit();
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
240 }
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 inline const std::string& String::stdString() const
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
243 {
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
244 return _string;
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
245 }
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 inline String String::strip (char unwanted)
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
248 {
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
249 return strip ({unwanted});
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
250 }
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 inline String String::operator+ (int num) const
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
253 {
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
254 return *this + String::fromNumber (num);
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
255 }
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
256
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
257 inline String& String::operator+= (const String data)
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 append (data);
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
260 return *this;
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
261 }
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
262
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
263 inline String& String::operator+= (const char* data)
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 append (data);
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
266 return *this;
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
267 }
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 inline String& String::operator+= (int num)
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
270 {
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
271 return operator+= (String::fromNumber (num));
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
272 }
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 inline void String::prepend (String a)
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
275 {
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
276 _string = (a + _string).stdString();
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
277 }
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
278
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
279 inline String& String::operator+= (const char data)
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 append (data);
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
282 return *this;
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
283 }
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
284
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
285 inline String String::operator- (int n) const
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 String newString = _string;
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
288 newString -= n;
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
289 return newString;
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
290 }
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
291
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
292 inline String& String::operator-= (int n)
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 trim (n);
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
295 return *this;
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
296 }
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 inline bool String::operator== (const String& other) const
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
299 {
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
300 return stdString() == other.stdString();
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
301 }
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 inline bool String::operator== (const char* other) const
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
304 {
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
305 return operator== (String (other));
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
306 }
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 inline bool String::operator!= (const String& other) const
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
309 {
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
310 return stdString() != other.stdString();
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
311 }
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 inline bool String::operator!= (const char* other) const
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
314 {
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
315 return operator!= (String (other));
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
316 }
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 inline bool String::operator> (const String& other) const
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
319 {
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
320 return stdString() > other.stdString();
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
321 }
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 inline bool String::operator< (const String& other) const
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
324 {
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
325 return stdString() < other.stdString();
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
326 }
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 inline String::operator const char*() const
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
329 {
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
330 return c_str();
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
331 }
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 inline String::operator const std::string&() const
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
334 {
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
335 return stdString();
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
336 }
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
337
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
338 inline void String::modifyIndex (int& a)
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 if (a < 0)
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
341 a = length() - a;
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
342 }
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
343
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
344 inline int String::indexDifference (int a, int b)
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 modifyIndex (a);
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
347 modifyIndex (b);
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
348 return b - a;
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
349 }
186ebeea2a85 - refactor the string class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
350
119
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
351 inline bool operator== (const char* a, const String& b)
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
352 {
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
353 return b == a;
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
354 }
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 inline String operator+ (const char* a, const String& b)
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
357 {
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
358 return String (a) + b;
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
359 }
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
360
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
361 #endif // BOTC_STRING_H

mercurial