Thu, 13 Jun 2013 02:58:17 +0300
Clipboard now stores LDraw code rather than object clones, this seems much less prone to problems
189
ac2d3e8dd110
Rewrote the string class with a simpler version. The old one was more than probably leaking water like a boat with an elephant on board...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1 | /* |
ac2d3e8dd110
Rewrote the string class with a simpler version. The old one was more than probably leaking water like a boat with an elephant on board...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
2 | * LDForge: LDraw parts authoring CAD |
ac2d3e8dd110
Rewrote the string class with a simpler version. The old one was more than probably leaking water like a boat with an elephant on board...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
3 | * Copyright (C) 2013 Santeri Piippo |
ac2d3e8dd110
Rewrote the string class with a simpler version. The old one was more than probably leaking water like a boat with an elephant on board...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
4 | * |
ac2d3e8dd110
Rewrote the string class with a simpler version. The old one was more than probably leaking water like a boat with an elephant on board...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
5 | * This program is free software: you can redistribute it and/or modify |
ac2d3e8dd110
Rewrote the string class with a simpler version. The old one was more than probably leaking water like a boat with an elephant on board...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
6 | * it under the terms of the GNU General Public License as published by |
ac2d3e8dd110
Rewrote the string class with a simpler version. The old one was more than probably leaking water like a boat with an elephant on board...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
7 | * the Free Software Foundation, either version 3 of the License, or |
ac2d3e8dd110
Rewrote the string class with a simpler version. The old one was more than probably leaking water like a boat with an elephant on board...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
8 | * (at your option) any later version. |
ac2d3e8dd110
Rewrote the string class with a simpler version. The old one was more than probably leaking water like a boat with an elephant on board...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
9 | * |
ac2d3e8dd110
Rewrote the string class with a simpler version. The old one was more than probably leaking water like a boat with an elephant on board...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
10 | * This program is distributed in the hope that it will be useful, |
ac2d3e8dd110
Rewrote the string class with a simpler version. The old one was more than probably leaking water like a boat with an elephant on board...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
ac2d3e8dd110
Rewrote the string class with a simpler version. The old one was more than probably leaking water like a boat with an elephant on board...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
ac2d3e8dd110
Rewrote the string class with a simpler version. The old one was more than probably leaking water like a boat with an elephant on board...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
13 | * GNU General Public License for more details. |
ac2d3e8dd110
Rewrote the string class with a simpler version. The old one was more than probably leaking water like a boat with an elephant on board...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
14 | * |
ac2d3e8dd110
Rewrote the string class with a simpler version. The old one was more than probably leaking water like a boat with an elephant on board...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
15 | * You should have received a copy of the GNU General Public License |
ac2d3e8dd110
Rewrote the string class with a simpler version. The old one was more than probably leaking water like a boat with an elephant on board...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
ac2d3e8dd110
Rewrote the string class with a simpler version. The old one was more than probably leaking water like a boat with an elephant on board...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
17 | */ |
ac2d3e8dd110
Rewrote the string class with a simpler version. The old one was more than probably leaking water like a boat with an elephant on board...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
18 | |
ac2d3e8dd110
Rewrote the string class with a simpler version. The old one was more than probably leaking water like a boat with an elephant on board...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
19 | #ifndef STR_H |
ac2d3e8dd110
Rewrote the string class with a simpler version. The old one was more than probably leaking water like a boat with an elephant on board...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
20 | #define STR_H |
ac2d3e8dd110
Rewrote the string class with a simpler version. The old one was more than probably leaking water like a boat with an elephant on board...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
21 | |
ac2d3e8dd110
Rewrote the string class with a simpler version. The old one was more than probably leaking water like a boat with an elephant on board...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
22 | #include <string> |
ac2d3e8dd110
Rewrote the string class with a simpler version. The old one was more than probably leaking water like a boat with an elephant on board...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
23 | #include <stdarg.h> |
ac2d3e8dd110
Rewrote the string class with a simpler version. The old one was more than probably leaking water like a boat with an elephant on board...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
24 | #include <QString> |
251
c4b96bc41298
Made a vector class which wraps around std::vector... finally I have an operator<< for the thing.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
237
diff
changeset
|
25 | #include "types.h" |
189
ac2d3e8dd110
Rewrote the string class with a simpler version. The old one was more than probably leaking water like a boat with an elephant on board...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
26 | |
ac2d3e8dd110
Rewrote the string class with a simpler version. The old one was more than probably leaking water like a boat with an elephant on board...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
27 | typedef class String { |
ac2d3e8dd110
Rewrote the string class with a simpler version. The old one was more than probably leaking water like a boat with an elephant on board...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
28 | public: |
ac2d3e8dd110
Rewrote the string class with a simpler version. The old one was more than probably leaking water like a boat with an elephant on board...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
29 | typedef typename std::string::iterator it; |
ac2d3e8dd110
Rewrote the string class with a simpler version. The old one was more than probably leaking water like a boat with an elephant on board...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
30 | typedef typename std::string::const_iterator c_it; |
ac2d3e8dd110
Rewrote the string class with a simpler version. The old one was more than probably leaking water like a boat with an elephant on board...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
31 | typedef vector<String> stringlist; |
ac2d3e8dd110
Rewrote the string class with a simpler version. The old one was more than probably leaking water like a boat with an elephant on board...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
32 | |
272
2074672a6554
Cleansed the string class, moved implementations from header to code file
Santeri Piippo <crimsondusk64@gmail.com>
parents:
257
diff
changeset
|
33 | String (); |
2074672a6554
Cleansed the string class, moved implementations from header to code file
Santeri Piippo <crimsondusk64@gmail.com>
parents:
257
diff
changeset
|
34 | String (const char* data); |
2074672a6554
Cleansed the string class, moved implementations from header to code file
Santeri Piippo <crimsondusk64@gmail.com>
parents:
257
diff
changeset
|
35 | String (const QString data); |
2074672a6554
Cleansed the string class, moved implementations from header to code file
Santeri Piippo <crimsondusk64@gmail.com>
parents:
257
diff
changeset
|
36 | String (std::string data); |
189
ac2d3e8dd110
Rewrote the string class with a simpler version. The old one was more than probably leaking water like a boat with an elephant on board...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
37 | |
272
2074672a6554
Cleansed the string class, moved implementations from header to code file
Santeri Piippo <crimsondusk64@gmail.com>
parents:
257
diff
changeset
|
38 | void append (const char* data); |
2074672a6554
Cleansed the string class, moved implementations from header to code file
Santeri Piippo <crimsondusk64@gmail.com>
parents:
257
diff
changeset
|
39 | void append (const char data); |
2074672a6554
Cleansed the string class, moved implementations from header to code file
Santeri Piippo <crimsondusk64@gmail.com>
parents:
257
diff
changeset
|
40 | void append (const String data); |
2074672a6554
Cleansed the string class, moved implementations from header to code file
Santeri Piippo <crimsondusk64@gmail.com>
parents:
257
diff
changeset
|
41 | it begin (); |
2074672a6554
Cleansed the string class, moved implementations from header to code file
Santeri Piippo <crimsondusk64@gmail.com>
parents:
257
diff
changeset
|
42 | c_it begin () const; |
2074672a6554
Cleansed the string class, moved implementations from header to code file
Santeri Piippo <crimsondusk64@gmail.com>
parents:
257
diff
changeset
|
43 | const char* c () const; |
2074672a6554
Cleansed the string class, moved implementations from header to code file
Santeri Piippo <crimsondusk64@gmail.com>
parents:
257
diff
changeset
|
44 | size_t capacity () const; |
2074672a6554
Cleansed the string class, moved implementations from header to code file
Santeri Piippo <crimsondusk64@gmail.com>
parents:
257
diff
changeset
|
45 | const char* chars () const; |
2074672a6554
Cleansed the string class, moved implementations from header to code file
Santeri Piippo <crimsondusk64@gmail.com>
parents:
257
diff
changeset
|
46 | int compare (const char* other) const; |
2074672a6554
Cleansed the string class, moved implementations from header to code file
Santeri Piippo <crimsondusk64@gmail.com>
parents:
257
diff
changeset
|
47 | int compare (String other) const; |
2074672a6554
Cleansed the string class, moved implementations from header to code file
Santeri Piippo <crimsondusk64@gmail.com>
parents:
257
diff
changeset
|
48 | it end (); |
2074672a6554
Cleansed the string class, moved implementations from header to code file
Santeri Piippo <crimsondusk64@gmail.com>
parents:
257
diff
changeset
|
49 | c_it end () const; |
2074672a6554
Cleansed the string class, moved implementations from header to code file
Santeri Piippo <crimsondusk64@gmail.com>
parents:
257
diff
changeset
|
50 | void clear (); |
2074672a6554
Cleansed the string class, moved implementations from header to code file
Santeri Piippo <crimsondusk64@gmail.com>
parents:
257
diff
changeset
|
51 | ushort count (const char needle) const; |
2074672a6554
Cleansed the string class, moved implementations from header to code file
Santeri Piippo <crimsondusk64@gmail.com>
parents:
257
diff
changeset
|
52 | bool empty () const; |
2074672a6554
Cleansed the string class, moved implementations from header to code file
Santeri Piippo <crimsondusk64@gmail.com>
parents:
257
diff
changeset
|
53 | void erase (size_t pos); |
2074672a6554
Cleansed the string class, moved implementations from header to code file
Santeri Piippo <crimsondusk64@gmail.com>
parents:
257
diff
changeset
|
54 | int first (const char* c, int a = 0) const; |
2074672a6554
Cleansed the string class, moved implementations from header to code file
Santeri Piippo <crimsondusk64@gmail.com>
parents:
257
diff
changeset
|
55 | void format (const char* fmtstr, ...); |
2074672a6554
Cleansed the string class, moved implementations from header to code file
Santeri Piippo <crimsondusk64@gmail.com>
parents:
257
diff
changeset
|
56 | void insert (size_t pos, char c); |
2074672a6554
Cleansed the string class, moved implementations from header to code file
Santeri Piippo <crimsondusk64@gmail.com>
parents:
257
diff
changeset
|
57 | int last (const char* c, int a = -1) const; |
2074672a6554
Cleansed the string class, moved implementations from header to code file
Santeri Piippo <crimsondusk64@gmail.com>
parents:
257
diff
changeset
|
58 | size_t len () const; |
2074672a6554
Cleansed the string class, moved implementations from header to code file
Santeri Piippo <crimsondusk64@gmail.com>
parents:
257
diff
changeset
|
59 | String lower () const; |
2074672a6554
Cleansed the string class, moved implementations from header to code file
Santeri Piippo <crimsondusk64@gmail.com>
parents:
257
diff
changeset
|
60 | size_t maxSize () const; |
2074672a6554
Cleansed the string class, moved implementations from header to code file
Santeri Piippo <crimsondusk64@gmail.com>
parents:
257
diff
changeset
|
61 | void replace (const char* a, const char* b); |
2074672a6554
Cleansed the string class, moved implementations from header to code file
Santeri Piippo <crimsondusk64@gmail.com>
parents:
257
diff
changeset
|
62 | void resize (size_t n); |
2074672a6554
Cleansed the string class, moved implementations from header to code file
Santeri Piippo <crimsondusk64@gmail.com>
parents:
257
diff
changeset
|
63 | void shrinkToFit (); |
2074672a6554
Cleansed the string class, moved implementations from header to code file
Santeri Piippo <crimsondusk64@gmail.com>
parents:
257
diff
changeset
|
64 | stringlist split (String del) const; |
2074672a6554
Cleansed the string class, moved implementations from header to code file
Santeri Piippo <crimsondusk64@gmail.com>
parents:
257
diff
changeset
|
65 | stringlist split (char del) const; |
2074672a6554
Cleansed the string class, moved implementations from header to code file
Santeri Piippo <crimsondusk64@gmail.com>
parents:
257
diff
changeset
|
66 | String strip (char unwanted); |
2074672a6554
Cleansed the string class, moved implementations from header to code file
Santeri Piippo <crimsondusk64@gmail.com>
parents:
257
diff
changeset
|
67 | String strip (std::initializer_list<char> unwanted); |
2074672a6554
Cleansed the string class, moved implementations from header to code file
Santeri Piippo <crimsondusk64@gmail.com>
parents:
257
diff
changeset
|
68 | String substr (long a, long b) const; |
2074672a6554
Cleansed the string class, moved implementations from header to code file
Santeri Piippo <crimsondusk64@gmail.com>
parents:
257
diff
changeset
|
69 | void trim (short n); |
2074672a6554
Cleansed the string class, moved implementations from header to code file
Santeri Piippo <crimsondusk64@gmail.com>
parents:
257
diff
changeset
|
70 | String upper () const; |
189
ac2d3e8dd110
Rewrote the string class with a simpler version. The old one was more than probably leaking water like a boat with an elephant on board...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
71 | |
272
2074672a6554
Cleansed the string class, moved implementations from header to code file
Santeri Piippo <crimsondusk64@gmail.com>
parents:
257
diff
changeset
|
72 | String operator+ (const String data) const; |
2074672a6554
Cleansed the string class, moved implementations from header to code file
Santeri Piippo <crimsondusk64@gmail.com>
parents:
257
diff
changeset
|
73 | String operator+ (const char* data) const; |
2074672a6554
Cleansed the string class, moved implementations from header to code file
Santeri Piippo <crimsondusk64@gmail.com>
parents:
257
diff
changeset
|
74 | String& operator+= (const String data); |
2074672a6554
Cleansed the string class, moved implementations from header to code file
Santeri Piippo <crimsondusk64@gmail.com>
parents:
257
diff
changeset
|
75 | String& operator+= (const char* data); |
2074672a6554
Cleansed the string class, moved implementations from header to code file
Santeri Piippo <crimsondusk64@gmail.com>
parents:
257
diff
changeset
|
76 | String& operator+= (const char data); |
2074672a6554
Cleansed the string class, moved implementations from header to code file
Santeri Piippo <crimsondusk64@gmail.com>
parents:
257
diff
changeset
|
77 | String operator+ () const; |
2074672a6554
Cleansed the string class, moved implementations from header to code file
Santeri Piippo <crimsondusk64@gmail.com>
parents:
257
diff
changeset
|
78 | String operator- () const; |
2074672a6554
Cleansed the string class, moved implementations from header to code file
Santeri Piippo <crimsondusk64@gmail.com>
parents:
257
diff
changeset
|
79 | String operator- (size_t n) const; |
2074672a6554
Cleansed the string class, moved implementations from header to code file
Santeri Piippo <crimsondusk64@gmail.com>
parents:
257
diff
changeset
|
80 | String& operator-= (size_t n); |
2074672a6554
Cleansed the string class, moved implementations from header to code file
Santeri Piippo <crimsondusk64@gmail.com>
parents:
257
diff
changeset
|
81 | size_t operator~ () const; |
2074672a6554
Cleansed the string class, moved implementations from header to code file
Santeri Piippo <crimsondusk64@gmail.com>
parents:
257
diff
changeset
|
82 | vector<String> operator/ (String del) const; |
2074672a6554
Cleansed the string class, moved implementations from header to code file
Santeri Piippo <crimsondusk64@gmail.com>
parents:
257
diff
changeset
|
83 | char& operator[] (size_t n); |
2074672a6554
Cleansed the string class, moved implementations from header to code file
Santeri Piippo <crimsondusk64@gmail.com>
parents:
257
diff
changeset
|
84 | const char& operator[] (size_t n) const; |
2074672a6554
Cleansed the string class, moved implementations from header to code file
Santeri Piippo <crimsondusk64@gmail.com>
parents:
257
diff
changeset
|
85 | bool operator== (const String other) const; |
2074672a6554
Cleansed the string class, moved implementations from header to code file
Santeri Piippo <crimsondusk64@gmail.com>
parents:
257
diff
changeset
|
86 | bool operator== (const char* other) const; |
2074672a6554
Cleansed the string class, moved implementations from header to code file
Santeri Piippo <crimsondusk64@gmail.com>
parents:
257
diff
changeset
|
87 | bool operator!= (const String other) const; |
2074672a6554
Cleansed the string class, moved implementations from header to code file
Santeri Piippo <crimsondusk64@gmail.com>
parents:
257
diff
changeset
|
88 | bool operator!= (const char* other) const; |
2074672a6554
Cleansed the string class, moved implementations from header to code file
Santeri Piippo <crimsondusk64@gmail.com>
parents:
257
diff
changeset
|
89 | bool operator! () const; |
2074672a6554
Cleansed the string class, moved implementations from header to code file
Santeri Piippo <crimsondusk64@gmail.com>
parents:
257
diff
changeset
|
90 | operator const char* () const; |
2074672a6554
Cleansed the string class, moved implementations from header to code file
Santeri Piippo <crimsondusk64@gmail.com>
parents:
257
diff
changeset
|
91 | operator QString (); |
2074672a6554
Cleansed the string class, moved implementations from header to code file
Santeri Piippo <crimsondusk64@gmail.com>
parents:
257
diff
changeset
|
92 | operator const QString () const; |
189
ac2d3e8dd110
Rewrote the string class with a simpler version. The old one was more than probably leaking water like a boat with an elephant on board...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
93 | |
273
0a9141118630
Restructed recent files handling, the list shouldn't screw the hell up anymore.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
272
diff
changeset
|
94 | static str join (const vector<str>& items, const str& delim); |
0a9141118630
Restructed recent files handling, the list shouldn't screw the hell up anymore.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
272
diff
changeset
|
95 | |
189
ac2d3e8dd110
Rewrote the string class with a simpler version. The old one was more than probably leaking water like a boat with an elephant on board...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
96 | private: |
ac2d3e8dd110
Rewrote the string class with a simpler version. The old one was more than probably leaking water like a boat with an elephant on board...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
97 | std::string m_string; |
ac2d3e8dd110
Rewrote the string class with a simpler version. The old one was more than probably leaking water like a boat with an elephant on board...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
98 | } str; |
ac2d3e8dd110
Rewrote the string class with a simpler version. The old one was more than probably leaking water like a boat with an elephant on board...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
99 | |
272
2074672a6554
Cleansed the string class, moved implementations from header to code file
Santeri Piippo <crimsondusk64@gmail.com>
parents:
257
diff
changeset
|
100 | // Accessories |
2074672a6554
Cleansed the string class, moved implementations from header to code file
Santeri Piippo <crimsondusk64@gmail.com>
parents:
257
diff
changeset
|
101 | char* dynafmt (const char* fmtstr, va_list va, ulong size); |
2074672a6554
Cleansed the string class, moved implementations from header to code file
Santeri Piippo <crimsondusk64@gmail.com>
parents:
257
diff
changeset
|
102 | str fmt (const char* fmtstr, ...); |
189
ac2d3e8dd110
Rewrote the string class with a simpler version. The old one was more than probably leaking water like a boat with an elephant on board...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
103 | |
ac2d3e8dd110
Rewrote the string class with a simpler version. The old one was more than probably leaking water like a boat with an elephant on board...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
104 | #endif // STR_H |