Sun, 28 Apr 2013 04:04:36 +0300
Now capable of calculating coordinates based on mouse x and y and snapping them to the grid
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 | 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 | 19 | #include <stdio.h> |
20 | #include <stdlib.h> | |
21 | #include <string.h> | |
22 | #include <stdarg.h> | |
23 | #include <assert.h> | |
24 | // #include <initializer_list> | |
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 | 28 | |
29 | #define ITERATE_STRING(u) \ | |
30 | for (unsigned int u = 0; u < strlen (text); u++) | |
31 | ||
32 | // ============================================================================ | |
33 | // vdynformat: Try to write to a formatted string with size bytes first, if | |
34 | // that fails, double the size and keep recursing until it works. | |
35 | char* vdynformat (const char* csFormat, va_list vArgs, long lSize) { | |
36 | char* buffer = new char[lSize]; | |
37 | int r = vsnprintf (buffer, lSize - 1, csFormat, vArgs); | |
38 | if (r > (signed)(lSize - 1) || r < 0) { | |
39 | delete[] buffer; | |
40 | buffer = vdynformat (csFormat, vArgs, lSize * 2); | |
41 | } | |
42 | return buffer; | |
43 | } | |
44 | ||
45 | // ============================================================================ | |
46 | str::str () { | |
47 | text = new char[1]; | |
48 | clear(); | |
49 | alloclen = strlen (text); | |
50 | } | |
51 | ||
52 | str::str (const char* c) { | |
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 | 56 | append (c); |
57 | } | |
58 | ||
59 | str::str (char c) { | |
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 | 70 | append (c); |
71 | } | |
72 | ||
73 | str::~str () { | |
74 | // delete[] text; | |
75 | } | |
76 | ||
77 | // ============================================================================ | |
78 | void str::clear () { | |
79 | delete[] text; | |
80 | text = new char[1]; | |
81 | text[0] = '\0'; | |
82 | curs = 0; | |
83 | alloclen = 0; | |
84 | } | |
85 | ||
86 | // ============================================================================ | |
87 | void str::resize (unsigned int len) { | |
88 | unsigned int oldlen = strlen (text); | |
89 | char* oldtext = new char[oldlen]; | |
90 | strncpy (oldtext, text, oldlen); | |
91 | ||
92 | delete[] text; | |
93 | text = new char[len+1]; | |
94 | for (unsigned int u = 0; u < len+1; u++) | |
95 | text[u] = 0; | |
96 | strncpy (text, oldtext, len); | |
97 | delete[] oldtext; | |
98 | ||
99 | alloclen = len; | |
100 | } | |
101 | ||
102 | // ============================================================================ | |
103 | void str::dump () { | |
104 | for (unsigned int u = 0; u <= alloclen; u++) | |
105 | printf ("\t%u. %u (%c)\n", u, text[u], text[u]); | |
106 | } | |
107 | ||
108 | // ============================================================================ | |
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 | 111 | // Out of space, thus resize |
112 | if (curs == alloclen) | |
113 | resize (alloclen + 1); | |
114 | text[curs] = c; | |
115 | curs++; | |
116 | } | |
117 | ||
118 | void str::append (const char* c) { | |
119 | resize (alloclen + strlen (c)); | |
120 | ||
121 | for (unsigned int u = 0; u < strlen (c); u++) { | |
122 | if (c[u] != 0) | |
123 | append (c[u]); | |
124 | } | |
125 | } | |
126 | ||
127 | void str::append (str c) { | |
128 | append (c.chars()); | |
129 | } | |
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 | 135 | // ============================================================================ |
136 | void str::appendformat (const char* c, ...) { | |
137 | va_list v; | |
138 | ||
139 | va_start (v, c); | |
140 | char* buf = vdynformat (c, v, 256); | |
141 | va_end (v); | |
142 | ||
143 | append (buf); | |
144 | delete[] buf; | |
145 | } | |
146 | ||
147 | void str::format (const char* fmt, ...) { | |
148 | clear (); | |
149 | ||
150 | va_list v; | |
151 | ||
152 | va_start (v, fmt); | |
153 | char* buf = vdynformat (fmt, v, 256); | |
154 | va_end (v); | |
155 | ||
156 | append (buf); | |
157 | delete[] buf; | |
158 | } | |
159 | ||
160 | str str::format (...) { | |
161 | va_list va; | |
162 | char* buf; | |
163 | ||
164 | va_start (va, this); | |
165 | buf = vdynformat (text, va, 256); | |
166 | va_end (va); | |
167 | ||
168 | str val = buf; | |
169 | delete[] buf; | |
170 | return val; | |
171 | } | |
172 | ||
173 | // ============================================================================ | |
174 | char* str::chars () { | |
175 | return text; | |
176 | } | |
177 | ||
178 | // ============================================================================ | |
179 | int str::first (const char* c, unsigned int a) { | |
180 | unsigned int r = 0; | |
181 | unsigned int index = 0; | |
182 | for (; a < alloclen; a++) { | |
183 | if (text[a] == c[r]) { | |
184 | if (r == 0) | |
185 | index = a; | |
186 | ||
187 | r++; | |
188 | if (r == strlen (c)) | |
189 | return index; | |
190 | } else { | |
191 | if (r != 0) { | |
192 | // If the string sequence broke at this point, we need to | |
193 | // check this character again, for a new sequence just | |
194 | // might start right here. | |
195 | a--; | |
196 | } | |
197 | ||
198 | r = 0; | |
199 | } | |
200 | } | |
201 | ||
202 | return -1; | |
203 | } | |
204 | ||
205 | // ============================================================================ | |
206 | int str::last (const char* c, int a) { | |
207 | if (a == -1) | |
208 | a = len(); | |
209 | ||
210 | int max = strlen (c)-1; | |
211 | ||
212 | int r = max; | |
213 | for (; a >= 0; a--) { | |
214 | if (text[a] == c[r]) { | |
215 | r--; | |
216 | if (r == -1) | |
217 | return a; | |
218 | } else { | |
219 | if (r != max) | |
220 | a++; | |
221 | ||
222 | r = max; | |
223 | } | |
224 | } | |
225 | ||
226 | return -1; | |
227 | } | |
228 | ||
229 | // ============================================================================ | |
230 | str str::substr (unsigned int a, unsigned int b) { | |
231 | if (a > len()) a = len(); | |
232 | if (b > len()) b = len(); | |
233 | ||
234 | if (b == a) | |
235 | return ""; | |
236 | ||
237 | if (b < a) { | |
238 | printf ("str::substring:: indices %u and %u given, should be the other way around, swapping..\n", a, b); | |
239 | ||
240 | // Swap the variables | |
241 | unsigned int c = a; | |
242 | a = b; | |
243 | b = c; | |
244 | } | |
245 | ||
246 | char* s = new char[b - a + 1]; | |
247 | strncpy (s, text + a, b - a); | |
248 | s[b - a] = '\0'; | |
249 | ||
250 | str other = s; | |
251 | delete[] s; | |
252 | return other; | |
253 | } | |
254 | ||
255 | // ============================================================================ | |
256 | void str::remove (unsigned int idx, unsigned int dellen) { | |
257 | str s1 = substr (0, idx); | |
258 | str s2 = substr (idx + dellen, -1); | |
259 | ||
260 | clear(); | |
261 | ||
262 | append (s1); | |
263 | append (s2); | |
264 | } | |
265 | ||
266 | // ============================================================================ | |
267 | str str::trim (int dellen) { | |
268 | if (dellen > 0) | |
269 | return substr (0, len() - dellen); | |
270 | return substr (-dellen, len()); | |
271 | } | |
272 | ||
273 | // ============================================================================ | |
274 | void str::replace (const char* o, const char* n, unsigned int a) { | |
275 | for (int idx; (idx = first (o, a)) != -1;) { | |
276 | str s1 = substr (0, idx); | |
277 | str s2 = substr (idx + strlen (o), len()); | |
278 | ||
279 | clear(); | |
280 | ||
281 | append (s1); | |
282 | append (n); | |
283 | append (s2); | |
284 | } | |
285 | } | |
286 | ||
287 | // ============================================================================ | |
113
bbaa40226ec9
Radial saving and reading from files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
107
diff
changeset
|
288 | str str::strip (char c) { |
bbaa40226ec9
Radial saving and reading from files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
107
diff
changeset
|
289 | return strip ({c}); |
0 | 290 | } |
291 | ||
113
bbaa40226ec9
Radial saving and reading from files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
107
diff
changeset
|
292 | str str::strip (std::initializer_list<char> unwanted) { |
0 | 293 | str cache = text; |
294 | uint oldlen = len(); | |
295 | ||
296 | char* buf = new char[oldlen]; | |
297 | char* bufptr = buf; | |
298 | for (uint i = 0; i < oldlen; i++) { | |
299 | bool valid = true; | |
300 | for (const char* j = unwanted.begin(); j < unwanted.end() && valid; j++) | |
301 | if (text[i] == *j) | |
302 | valid = false; | |
303 | ||
304 | if (valid) | |
305 | *bufptr++ = text[i]; | |
306 | } | |
307 | ||
308 | *bufptr = '\0'; | |
309 | assert (bufptr <= buf + oldlen); | |
310 | ||
113
bbaa40226ec9
Radial saving and reading from files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
107
diff
changeset
|
311 | str zResult = buf; |
bbaa40226ec9
Radial saving and reading from files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
107
diff
changeset
|
312 | delete[] buf; |
0 | 313 | |
113
bbaa40226ec9
Radial saving and reading from files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
107
diff
changeset
|
314 | return zResult; |
0 | 315 | } |
316 | ||
317 | void str::insert (char* c, unsigned int pos) { | |
318 | str s1 = substr (0, pos); | |
319 | str s2 = substr (pos, len()); | |
320 | ||
321 | clear(); | |
322 | append (s1); | |
323 | append (c); | |
324 | append (s2); | |
325 | } | |
326 | ||
327 | str str::reverse () { | |
328 | char* buf = new char[len() + 1]; | |
329 | ||
330 | for (uint i = 0; i < len(); i++) | |
331 | buf[i] = text[len() - i - 1]; | |
332 | buf[len()] = '\0'; | |
333 | ||
334 | str other = buf; | |
335 | delete[] buf; | |
336 | return other; | |
337 | } | |
338 | ||
339 | str str::repeat (int n) { | |
340 | assert (n >= 0); | |
341 | ||
342 | str other; | |
343 | for (int i = 0; i < n; i++) | |
344 | other += text; | |
345 | return other; | |
346 | } | |
347 | ||
348 | // ============================================================================ | |
349 | bool str::isnumber () { | |
350 | ITERATE_STRING (u) { | |
351 | // Minus sign as the first character is allowed for negatives | |
352 | if (!u && text[u] == '-') | |
353 | continue; | |
354 | ||
355 | if (text[u] < '0' || text[u] > '9') | |
356 | return false; | |
357 | } | |
358 | return true; | |
359 | } | |
360 | ||
361 | // ============================================================================ | |
362 | bool str::isword () { | |
363 | ITERATE_STRING (u) { | |
364 | // lowercase letters | |
365 | if (text[u] >= 'a' || text[u] <= 'z') | |
366 | continue; | |
367 | ||
368 | // uppercase letters | |
369 | if (text[u] >= 'A' || text[u] <= 'Z') | |
370 | continue; | |
371 | ||
372 | return false; | |
373 | } | |
374 | return true; | |
375 | } | |
376 | ||
377 | int str::instanceof (const char* c, uint n) { | |
378 | unsigned int r = 0; | |
379 | unsigned int index = 0; | |
380 | unsigned int x = 0; | |
381 | for (uint a = 0; a < alloclen; a++) { | |
382 | if (text[a] == c[r]) { | |
383 | if (r == 0) | |
384 | index = a; | |
385 | ||
386 | r++; | |
387 | if (r == strlen (c)) { | |
388 | if (x++ == n) | |
389 | return index; | |
390 | r = 0; | |
391 | } | |
392 | } else { | |
393 | if (r != 0) | |
394 | a--; | |
395 | r = 0; | |
396 | } | |
397 | } | |
398 | ||
399 | return -1; | |
400 | } | |
401 | ||
402 | // ============================================================================ | |
403 | int str::compare (const char* c) { | |
404 | return strcmp (text, c); | |
405 | } | |
406 | ||
407 | int str::compare (str c) { | |
408 | return compare (c.chars()); | |
409 | } | |
410 | ||
411 | int str::icompare (const char* c) { | |
412 | return icompare (str ((char*)c)); | |
413 | } | |
414 | ||
415 | int str::icompare (str b) { | |
416 | return strcmp (tolower().chars(), b.tolower().chars()); | |
417 | } | |
418 | ||
419 | // ============================================================================ | |
420 | str str::tolower () { | |
421 | str n = text; | |
422 | ||
423 | for (uint u = 0; u < len(); u++) { | |
424 | if (n[u] >= 'A' && n[u] < 'Z') | |
425 | n.text[u] += ('a' - 'A'); | |
426 | } | |
427 | ||
428 | return n; | |
429 | } | |
430 | ||
431 | // ============================================================================ | |
432 | str str::toupper () { | |
433 | str n = text; | |
434 | ||
435 | for (uint u = 0; u < len(); u++) { | |
436 | if (n[u] >= 'a' && n[u] < 'z') | |
437 | n.text[u] -= ('a' - 'A'); | |
438 | } | |
439 | ||
440 | return n; | |
441 | } | |
442 | ||
443 | // ============================================================================ | |
444 | unsigned str::count (char c) { | |
445 | unsigned n = 0; | |
446 | ITERATE_STRING (u) | |
447 | if (text[u] == c) | |
448 | n++; | |
449 | return n; | |
450 | } | |
451 | ||
452 | unsigned str::count (char* c) { | |
453 | unsigned int r = 0; | |
454 | unsigned int tmp = 0; | |
455 | ITERATE_STRING (u) { | |
456 | if (text[u] == c[r]) { | |
457 | r++; | |
458 | if (r == strlen (c)) { | |
459 | r = 0; | |
460 | tmp++; | |
461 | } | |
462 | } else { | |
463 | if (r != 0) | |
464 | u--; | |
465 | r = 0; | |
466 | } | |
467 | } | |
468 | ||
469 | return tmp; | |
470 | } | |
471 | ||
472 | // ============================================================================ | |
60
961663d05463
Parsing stability, finally figured that dumb crash
Santeri Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
473 | std::vector<str> str::split (str del, bool bNoBlanks) { |
0 | 474 | std::vector<str> res; |
475 | unsigned int a = 0; | |
476 | ||
477 | // Find all separators and store the text left to them. | |
478 | while (1) { | |
479 | int b = first (del, a); | |
480 | ||
481 | if (b == -1) | |
482 | break; | |
483 | ||
60
961663d05463
Parsing stability, finally figured that dumb crash
Santeri Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
484 | if (!bNoBlanks || (b - a)) |
961663d05463
Parsing stability, finally figured that dumb crash
Santeri Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
485 | res.push_back (substr (a, b)); |
961663d05463
Parsing stability, finally figured that dumb crash
Santeri Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
486 | |
0 | 487 | a = b + strlen (del); |
488 | } | |
489 | ||
490 | // 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
|
491 | if (!bNoBlanks || (len () - a)) |
961663d05463
Parsing stability, finally figured that dumb crash
Santeri Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
492 | res.push_back (substr (a, len ())); |
0 | 493 | return res; |
494 | } | |
495 | ||
496 | std::vector<str> str::operator/ (str splitstring) {return split(splitstring);} | |
497 | 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
|
498 | 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
|
499 | |
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
|
500 | str& str::operator+= (vertex vrt) { |
135
c243df39913e
Cleanup and some restructuring
Santeri Piippo <crimsondusk64@gmail.com>
parents:
116
diff
changeset
|
501 | 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
|
502 | return *this; |
116 | 503 | } |
504 | ||
505 | str format (const char* fmt, ...) { | |
506 | va_list va; | |
507 | char* buf; | |
508 | ||
509 | va_start (va, fmt); | |
510 | buf = vdynformat (fmt, va, 256); | |
511 | va_end (va); | |
512 | ||
513 | str val = buf; | |
514 | delete[] buf; | |
515 | 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
|
516 | } |