str.cpp

Tue, 07 May 2013 23:37:46 +0300

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Tue, 07 May 2013 23:37:46 +0300
changeset 176
84132e178d46
parent 161
c9fba92c4e35
permissions
-rw-r--r--

Removed the message log. I'll find a better way to convey messages at some point..

30
31ff9aabd506 Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
1 /*
31ff9aabd506 Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
2 * LDForge: LDraw parts authoring CAD
104
6e29bb0e83c5 GL picking stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 60
diff changeset
3 * Copyright (C) 2013 Santeri Piippo
30
31ff9aabd506 Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
4 *
31ff9aabd506 Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
5 * This program is free software: you can redistribute it and/or modify
31ff9aabd506 Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
6 * it under the terms of the GNU General Public License as published by
31ff9aabd506 Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
7 * the Free Software Foundation, either version 3 of the License, or
31ff9aabd506 Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
8 * (at your option) any later version.
31ff9aabd506 Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
9 *
31ff9aabd506 Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
10 * This program is distributed in the hope that it will be useful,
31ff9aabd506 Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
31ff9aabd506 Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31ff9aabd506 Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
13 * GNU General Public License for more details.
31ff9aabd506 Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
14 *
31ff9aabd506 Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
15 * You should have received a copy of the GNU General Public License
31ff9aabd506 Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
31ff9aabd506 Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
17 */
31ff9aabd506 Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
18
0
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
19 #include <stdio.h>
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
20 #include <stdlib.h>
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
21 #include <string.h>
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
22 #include <stdarg.h>
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
23 #include <assert.h>
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
24 // #include <initializer_list>
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
25 #include "str.h"
18
a6732098fed8 Convert the static getCoordinateRep to a common ftoa, use this function to get proper coordinate representation when converting objects to LDraw code
Santeri Piippo <crimsondusk64@gmail.com>
parents: 0
diff changeset
26 #include "common.h"
a6732098fed8 Convert the static getCoordinateRep to a common ftoa, use this function to get proper coordinate representation when converting objects to LDraw code
Santeri Piippo <crimsondusk64@gmail.com>
parents: 0
diff changeset
27 #include "misc.h"
0
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
28
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
29 #define ITERATE_STRING(u) \
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
30 for (unsigned int u = 0; u < strlen (text); u++)
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
31
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
32 // ============================================================================
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
33 // vdynformat: Try to write to a formatted string with size bytes first, if
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
34 // that fails, double the size and keep recursing until it works.
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
35 char* vdynformat (const char* csFormat, va_list vArgs, long lSize) {
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
36 char* buffer = new char[lSize];
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
37 int r = vsnprintf (buffer, lSize - 1, csFormat, vArgs);
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
38 if (r > (signed)(lSize - 1) || r < 0) {
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
39 delete[] buffer;
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
40 buffer = vdynformat (csFormat, vArgs, lSize * 2);
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
41 }
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
42 return buffer;
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
43 }
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
44
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
45 // ============================================================================
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
46 str::str () {
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
47 text = new char[1];
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
48 clear();
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
49 alloclen = strlen (text);
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
50 }
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
51
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
52 str::str (const char* c) {
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
53 text = new char[1];
29
55406ce7446e Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
54 text[0] = '\0';
55406ce7446e Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
55 curs = alloclen = 0;
0
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
56 append (c);
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
57 }
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
58
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
59 str::str (char c) {
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
60 text = new char[1];
29
55406ce7446e Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
61 text[0] = '\0';
55406ce7446e Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
62 curs = alloclen = 0;
55406ce7446e Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
63 append (c);
55406ce7446e Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
64 }
55406ce7446e Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
65
55406ce7446e Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
66 str::str (QString c) {
55406ce7446e Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
67 text = new char[1];
55406ce7446e Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
68 text[0] = '\0';
55406ce7446e Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
69 curs = alloclen = 0;
0
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
70 append (c);
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
71 }
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
72
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
73 str::~str () {
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
74 // delete[] text;
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
75 }
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
76
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
77 // ============================================================================
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
78 void str::clear () {
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
79 delete[] text;
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
80 text = new char[1];
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
81 text[0] = '\0';
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
82 curs = 0;
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
83 alloclen = 0;
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
84 }
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
85
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
86 // ============================================================================
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
87 void str::resize (unsigned int len) {
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
88 unsigned int oldlen = strlen (text);
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
89 char* oldtext = new char[oldlen];
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
90 strncpy (oldtext, text, oldlen);
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
91
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
92 delete[] text;
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
93 text = new char[len+1];
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
94 for (unsigned int u = 0; u < len+1; u++)
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
95 text[u] = 0;
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
96 strncpy (text, oldtext, len);
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
97 delete[] oldtext;
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
98
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
99 alloclen = len;
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
100 }
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
101
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
102 // ============================================================================
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
103 void str::dump () {
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
104 for (unsigned int u = 0; u <= alloclen; u++)
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
105 printf ("\t%u. %u (%c)\n", u, text[u], text[u]);
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
106 }
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
107
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
108 // ============================================================================
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
109 // Adds a new character at the end of the string.
25
c74bb88f537d Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 18
diff changeset
110 void str::append (const char c) {
0
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
111 // Out of space, thus resize
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
112 if (curs == alloclen)
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
113 resize (alloclen + 1);
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
114 text[curs] = c;
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
115 curs++;
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
116 }
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
117
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
118 void str::append (const char* c) {
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
119 resize (alloclen + strlen (c));
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
120
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
121 for (unsigned int u = 0; u < strlen (c); u++) {
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
122 if (c[u] != 0)
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
123 append (c[u]);
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
124 }
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
125 }
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
126
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
127 void str::append (str c) {
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
128 append (c.chars());
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
129 }
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
130
25
c74bb88f537d Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 18
diff changeset
131 void str::append (QString c) {
c74bb88f537d Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 18
diff changeset
132 append (c.toUtf8 ().constData ());
c74bb88f537d Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 18
diff changeset
133 }
c74bb88f537d Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 18
diff changeset
134
0
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
135 // ============================================================================
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
136 void str::appendformat (const char* c, ...) {
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
137 va_list v;
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
138
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
139 va_start (v, c);
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
140 char* buf = vdynformat (c, v, 256);
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
141 va_end (v);
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
142
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
143 append (buf);
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
144 delete[] buf;
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
145 }
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
146
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
147 void str::format (const char* fmt, ...) {
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
148 clear ();
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
149
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
150 va_list v;
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
151
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
152 va_start (v, fmt);
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
153 char* buf = vdynformat (fmt, v, 256);
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
154 va_end (v);
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
155
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
156 append (buf);
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
157 delete[] buf;
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
158 }
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
159
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
160 // ============================================================================
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
161 char* str::chars () {
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
162 return text;
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
163 }
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
164
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
165 // ============================================================================
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
166 int str::first (const char* c, unsigned int a) {
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
167 unsigned int r = 0;
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
168 unsigned int index = 0;
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
169 for (; a < alloclen; a++) {
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
170 if (text[a] == c[r]) {
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
171 if (r == 0)
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
172 index = a;
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
173
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
174 r++;
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
175 if (r == strlen (c))
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
176 return index;
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
177 } else {
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
178 if (r != 0) {
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
179 // If the string sequence broke at this point, we need to
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
180 // check this character again, for a new sequence just
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
181 // might start right here.
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
182 a--;
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
183 }
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
184
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
185 r = 0;
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
186 }
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
187 }
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
188
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
189 return -1;
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
190 }
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
191
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
192 // ============================================================================
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
193 int str::last (const char* c, int a) {
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
194 if (a == -1)
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
195 a = len();
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
196
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
197 int max = strlen (c)-1;
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
198
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
199 int r = max;
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
200 for (; a >= 0; a--) {
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
201 if (text[a] == c[r]) {
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
202 r--;
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
203 if (r == -1)
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
204 return a;
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
205 } else {
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
206 if (r != max)
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
207 a++;
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
208
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
209 r = max;
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
210 }
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
211 }
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
212
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
213 return -1;
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
214 }
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
215
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
216 // ============================================================================
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
217 str str::substr (unsigned int a, unsigned int b) {
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
218 if (a > len()) a = len();
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
219 if (b > len()) b = len();
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
220
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
221 if (b == a)
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
222 return "";
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
223
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
224 if (b < a) {
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
225 printf ("str::substring:: indices %u and %u given, should be the other way around, swapping..\n", a, b);
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
226
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
227 // Swap the variables
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
228 unsigned int c = a;
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
229 a = b;
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
230 b = c;
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
231 }
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
232
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
233 char* s = new char[b - a + 1];
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
234 strncpy (s, text + a, b - a);
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
235 s[b - a] = '\0';
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
236
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
237 str other = s;
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
238 delete[] s;
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
239 return other;
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
240 }
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
241
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
242 // ============================================================================
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
243 void str::remove (unsigned int idx, unsigned int dellen) {
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
244 str s1 = substr (0, idx);
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
245 str s2 = substr (idx + dellen, -1);
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
246
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
247 clear();
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
248
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
249 append (s1);
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
250 append (s2);
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
251 }
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
252
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
253 // ============================================================================
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
254 str str::trim (int dellen) {
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
255 if (dellen > 0)
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
256 return substr (0, len() - dellen);
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
257 return substr (-dellen, len());
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
258 }
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
259
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
260 // ============================================================================
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
261 void str::replace (const char* o, const char* n, unsigned int a) {
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
262 for (int idx; (idx = first (o, a)) != -1;) {
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
263 str s1 = substr (0, idx);
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
264 str s2 = substr (idx + strlen (o), len());
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
265
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
266 clear();
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
267
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
268 append (s1);
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
269 append (n);
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
270 append (s2);
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
271 }
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
272 }
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
273
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
274 // ============================================================================
113
bbaa40226ec9 Radial saving and reading from files
Santeri Piippo <crimsondusk64@gmail.com>
parents: 107
diff changeset
275 str str::strip (char c) {
bbaa40226ec9 Radial saving and reading from files
Santeri Piippo <crimsondusk64@gmail.com>
parents: 107
diff changeset
276 return strip ({c});
0
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
277 }
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
278
113
bbaa40226ec9 Radial saving and reading from files
Santeri Piippo <crimsondusk64@gmail.com>
parents: 107
diff changeset
279 str str::strip (std::initializer_list<char> unwanted) {
0
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
280 str cache = text;
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
281 uint oldlen = len();
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
282
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
283 char* buf = new char[oldlen];
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
284 char* bufptr = buf;
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
285 for (uint i = 0; i < oldlen; i++) {
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
286 bool valid = true;
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
287 for (const char* j = unwanted.begin(); j < unwanted.end() && valid; j++)
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
288 if (text[i] == *j)
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
289 valid = false;
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
290
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
291 if (valid)
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
292 *bufptr++ = text[i];
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
293 }
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
294
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
295 *bufptr = '\0';
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
296 assert (bufptr <= buf + oldlen);
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
297
113
bbaa40226ec9 Radial saving and reading from files
Santeri Piippo <crimsondusk64@gmail.com>
parents: 107
diff changeset
298 str zResult = buf;
bbaa40226ec9 Radial saving and reading from files
Santeri Piippo <crimsondusk64@gmail.com>
parents: 107
diff changeset
299 delete[] buf;
0
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
300
113
bbaa40226ec9 Radial saving and reading from files
Santeri Piippo <crimsondusk64@gmail.com>
parents: 107
diff changeset
301 return zResult;
0
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
302 }
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
303
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
304 void str::insert (char* c, unsigned int pos) {
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
305 str s1 = substr (0, pos);
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
306 str s2 = substr (pos, len());
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
307
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
308 clear();
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
309 append (s1);
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
310 append (c);
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
311 append (s2);
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
312 }
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
313
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
314 str str::reverse () {
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
315 char* buf = new char[len() + 1];
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
316
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
317 for (uint i = 0; i < len(); i++)
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
318 buf[i] = text[len() - i - 1];
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
319 buf[len()] = '\0';
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
320
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
321 str other = buf;
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
322 delete[] buf;
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
323 return other;
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
324 }
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
325
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
326 str str::repeat (int n) {
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
327 assert (n >= 0);
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
328
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
329 str other;
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
330 for (int i = 0; i < n; i++)
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
331 other += text;
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
332 return other;
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
333 }
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
334
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
335 // ============================================================================
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
336 bool str::isnumber () {
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
337 ITERATE_STRING (u) {
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
338 // Minus sign as the first character is allowed for negatives
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
339 if (!u && text[u] == '-')
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
340 continue;
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
341
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
342 if (text[u] < '0' || text[u] > '9')
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
343 return false;
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
344 }
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
345 return true;
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
346 }
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
347
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
348 // ============================================================================
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
349 bool str::isword () {
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
350 ITERATE_STRING (u) {
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
351 // lowercase letters
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
352 if (text[u] >= 'a' || text[u] <= 'z')
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
353 continue;
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
354
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
355 // uppercase letters
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
356 if (text[u] >= 'A' || text[u] <= 'Z')
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
357 continue;
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
358
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
359 return false;
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
360 }
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
361 return true;
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
362 }
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
363
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
364 int str::instanceof (const char* c, uint n) {
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
365 unsigned int r = 0;
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
366 unsigned int index = 0;
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
367 unsigned int x = 0;
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
368 for (uint a = 0; a < alloclen; a++) {
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
369 if (text[a] == c[r]) {
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
370 if (r == 0)
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
371 index = a;
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
372
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
373 r++;
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
374 if (r == strlen (c)) {
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
375 if (x++ == n)
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
376 return index;
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
377 r = 0;
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
378 }
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
379 } else {
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
380 if (r != 0)
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
381 a--;
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
382 r = 0;
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
383 }
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
384 }
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
385
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
386 return -1;
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
387 }
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
388
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
389 // ============================================================================
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
390 int str::compare (const char* c) {
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
391 return strcmp (text, c);
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
392 }
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
393
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
394 int str::compare (str c) {
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
395 return compare (c.chars());
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
396 }
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
397
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
398 int str::icompare (const char* c) {
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
399 return icompare (str ((char*)c));
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
400 }
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
401
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
402 int str::icompare (str b) {
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
403 return strcmp (tolower().chars(), b.tolower().chars());
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
404 }
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
405
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
406 // ============================================================================
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
407 str str::tolower () {
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
408 str n = text;
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
409
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
410 for (uint u = 0; u < len(); u++) {
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
411 if (n[u] >= 'A' && n[u] < 'Z')
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
412 n.text[u] += ('a' - 'A');
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
413 }
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
414
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
415 return n;
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
416 }
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
417
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
418 // ============================================================================
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
419 str str::toupper () {
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
420 str n = text;
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
421
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
422 for (uint u = 0; u < len(); u++) {
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
423 if (n[u] >= 'a' && n[u] < 'z')
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
424 n.text[u] -= ('a' - 'A');
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
425 }
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
426
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
427 return n;
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
428 }
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
429
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
430 // ============================================================================
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
431 unsigned str::count (char c) {
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
432 unsigned n = 0;
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
433 ITERATE_STRING (u)
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
434 if (text[u] == c)
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
435 n++;
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
436 return n;
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
437 }
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
438
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
439 unsigned str::count (char* c) {
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
440 unsigned int r = 0;
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
441 unsigned int tmp = 0;
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
442 ITERATE_STRING (u) {
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
443 if (text[u] == c[r]) {
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
444 r++;
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
445 if (r == strlen (c)) {
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
446 r = 0;
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
447 tmp++;
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
448 }
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
449 } else {
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
450 if (r != 0)
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
451 u--;
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
452 r = 0;
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
453 }
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
454 }
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
455
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
456 return tmp;
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
457 }
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
458
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
459 // ============================================================================
60
961663d05463 Parsing stability, finally figured that dumb crash
Santeri Piippo <crimsondusk64@gmail.com>
parents: 30
diff changeset
460 std::vector<str> str::split (str del, bool bNoBlanks) {
0
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
461 std::vector<str> res;
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
462 unsigned int a = 0;
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
463
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
464 // Find all separators and store the text left to them.
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
465 while (1) {
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
466 int b = first (del, a);
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
467
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
468 if (b == -1)
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
469 break;
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
470
60
961663d05463 Parsing stability, finally figured that dumb crash
Santeri Piippo <crimsondusk64@gmail.com>
parents: 30
diff changeset
471 if (!bNoBlanks || (b - a))
961663d05463 Parsing stability, finally figured that dumb crash
Santeri Piippo <crimsondusk64@gmail.com>
parents: 30
diff changeset
472 res.push_back (substr (a, b));
961663d05463 Parsing stability, finally figured that dumb crash
Santeri Piippo <crimsondusk64@gmail.com>
parents: 30
diff changeset
473
0
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
474 a = b + strlen (del);
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
475 }
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
476
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
477 // Add the string at the right of the last separator
60
961663d05463 Parsing stability, finally figured that dumb crash
Santeri Piippo <crimsondusk64@gmail.com>
parents: 30
diff changeset
478 if (!bNoBlanks || (len () - a))
961663d05463 Parsing stability, finally figured that dumb crash
Santeri Piippo <crimsondusk64@gmail.com>
parents: 30
diff changeset
479 res.push_back (substr (a, len ()));
0
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
480 return res;
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
481 }
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
482
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
483 std::vector<str> str::operator/ (str splitstring) {return split(splitstring);}
c51cce84a9ac Initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
484 std::vector<str> str::operator/ (char* splitstring) {return split(splitstring);}
18
a6732098fed8 Convert the static getCoordinateRep to a common ftoa, use this function to get proper coordinate representation when converting objects to LDraw code
Santeri Piippo <crimsondusk64@gmail.com>
parents: 0
diff changeset
485 std::vector<str> str::operator/ (const char* splitstring) {return split(splitstring);}
a6732098fed8 Convert the static getCoordinateRep to a common ftoa, use this function to get proper coordinate representation when converting objects to LDraw code
Santeri Piippo <crimsondusk64@gmail.com>
parents: 0
diff changeset
486
a6732098fed8 Convert the static getCoordinateRep to a common ftoa, use this function to get proper coordinate representation when converting objects to LDraw code
Santeri Piippo <crimsondusk64@gmail.com>
parents: 0
diff changeset
487 str& str::operator+= (vertex vrt) {
135
c243df39913e Cleanup and some restructuring
Santeri Piippo <crimsondusk64@gmail.com>
parents: 116
diff changeset
488 appendformat ("%s", vrt.stringRep (false).chars());
18
a6732098fed8 Convert the static getCoordinateRep to a common ftoa, use this function to get proper coordinate representation when converting objects to LDraw code
Santeri Piippo <crimsondusk64@gmail.com>
parents: 0
diff changeset
489 return *this;
116
4fde8fdf258a Some renaming
Santeri Piippo <crimsondusk64@gmail.com>
parents: 113
diff changeset
490 }
4fde8fdf258a Some renaming
Santeri Piippo <crimsondusk64@gmail.com>
parents: 113
diff changeset
491
161
c9fba92c4e35 Further tweaking
Santeri Piippo <crimsondusk64@gmail.com>
parents: 135
diff changeset
492 str fmt (const char* fmt, ...) {
116
4fde8fdf258a Some renaming
Santeri Piippo <crimsondusk64@gmail.com>
parents: 113
diff changeset
493 va_list va;
4fde8fdf258a Some renaming
Santeri Piippo <crimsondusk64@gmail.com>
parents: 113
diff changeset
494 char* buf;
4fde8fdf258a Some renaming
Santeri Piippo <crimsondusk64@gmail.com>
parents: 113
diff changeset
495
4fde8fdf258a Some renaming
Santeri Piippo <crimsondusk64@gmail.com>
parents: 113
diff changeset
496 va_start (va, fmt);
4fde8fdf258a Some renaming
Santeri Piippo <crimsondusk64@gmail.com>
parents: 113
diff changeset
497 buf = vdynformat (fmt, va, 256);
4fde8fdf258a Some renaming
Santeri Piippo <crimsondusk64@gmail.com>
parents: 113
diff changeset
498 va_end (va);
4fde8fdf258a Some renaming
Santeri Piippo <crimsondusk64@gmail.com>
parents: 113
diff changeset
499
4fde8fdf258a Some renaming
Santeri Piippo <crimsondusk64@gmail.com>
parents: 113
diff changeset
500 str val = buf;
4fde8fdf258a Some renaming
Santeri Piippo <crimsondusk64@gmail.com>
parents: 113
diff changeset
501 delete[] buf;
4fde8fdf258a Some renaming
Santeri Piippo <crimsondusk64@gmail.com>
parents: 113
diff changeset
502 return val;
18
a6732098fed8 Convert the static getCoordinateRep to a common ftoa, use this function to get proper coordinate representation when converting objects to LDraw code
Santeri Piippo <crimsondusk64@gmail.com>
parents: 0
diff changeset
503 }

mercurial