asar coverage - build #304


src/asar/
File: src/asar/libstr.h
Date: 2025-03-24 20:16:46
Lines:
265/287
92.3%
Functions:
60/64
93.8%
Branches:
151/205
73.7%

Line Branch Exec Source
1 #pragma once
2
3 #include "std-includes.h"
4 //ty alcaro
5 extern const unsigned char char_props[256];
6 27538222 static inline int to_lower(unsigned char c) { return c|(char_props[c]&0x20); }
7 308174 static inline int to_upper(unsigned char c) { return c&~(char_props[c]&0x20); }
8
9 1726556 inline bool is_space(unsigned char c) { return char_props[c] & 0x80; } // C standard says \f \v are space, but this one disagrees
10 10071544 inline bool is_digit(unsigned char c) { return char_props[c] & 0x40; }
11 3342 inline bool is_alpha(unsigned char c) { return char_props[c] & 0x20; }
12 3570 inline bool is_lower(unsigned char c) { return char_props[c] & 0x04; }
13 4802 inline bool is_upper(unsigned char c) { return char_props[c] & 0x02; }
14 24626 inline bool is_alnum(unsigned char c) { return char_props[c] & 0x60; }
15 inline bool is_ualpha(unsigned char c) { return char_props[c] & 0x28; }
16 1339752 inline bool is_ualnum(unsigned char c) { return char_props[c] & 0x68; }
17 43242 inline bool is_xdigit(unsigned char c) { return char_props[c] & 0x01; }
18
19 17279730 inline char *copy(const char *source, int copy_length, char *dest)
20 {
21 17279730 memmove(dest, source, copy_length*sizeof(char));
22 17279730 return dest;
23 }
24
25 439732 inline int min_val(int a, int b)
26 {
27
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 439732 times.
439732 return a > b ? b : a;
28 }
29
30 440391 inline int bit_round(int v)
31 {
32 440391 v--;
33 440391 v |= v >> 1;
34 440391 v |= v >> 2;
35 440391 v |= v >> 4;
36 440391 v |= v >> 8;
37 440391 v |= v >> 16;
38 440391 v++;
39 440391 return v;
40 }
41
42 class string {
43 public:
44 56106920 const char *data() const
45 {
46 56106920 return cached_data;
47 }
48
49 1758386 char *temp_raw() const //things to cleanup and take a look at
50 {
51 1758386 return cached_data;
52 }
53
54 54839796 char *raw() const
55 {
56 54839796 return cached_data;
57 }
58
59 53826432 int length() const
60 {
61
2/2
✓ Branch 0 taken 50642658 times.
✓ Branch 1 taken 3183774 times.
53826432 return is_inlined() ? inlined.len : allocated.len;
62 }
63
64 28269463 void set_length(int length)
65 {
66
2/2
✓ Branch 0 taken 1761797 times.
✓ Branch 1 taken 26507666 times.
28269463 if(length > max_inline_length_){
67 1761797 inlined.len = (unsigned char)-1;
68 1761797 allocated.len = length;
69 }else{
70 26507666 inlined.len = length;
71 }
72 28269463 }
73
74 1747442 void truncate(int newlen)
75 {
76 1747442 resize(newlen);
77 1747442 }
78
79 5578354 void assign(const char * newstr)
80 {
81
2/2
✓ Branch 0 taken 200 times.
✓ Branch 1 taken 5578154 times.
5578354 if (!newstr) newstr = "";
82 5578354 assign(newstr, strlen(newstr));
83 5578354 }
84
85 5895152 void assign(const string &newstr)
86 {
87 5895152 assign(newstr, newstr.length());
88 5895152 }
89
90 15917872 void assign(const char * newstr, int end)
91 {
92 15917872 resize(end);
93 15917872 copy(newstr, length(), raw());
94 15917872 }
95
96
97 1103738 string& operator=(const char * newstr)
98 {
99 1103738 assign(newstr);
100 1103738 return *this;
101 }
102
103 3067708 string& operator=(const string &newstr)
104 {
105 3067708 assign(newstr);
106 3067708 return *this;
107 }
108
109 875074 string& operator+=(const string& other)
110 {
111 875074 int current_end = length();
112 875074 resize(length() + other.length());
113 875074 copy(other.data(), other.length(), raw() + current_end);
114 875074 return *this;
115 }
116
117 46332 string& operator+=(const char *other)
118 {
119 46332 int current_end = length();
120 46332 int otherlen=(int)strlen(other);
121 46332 resize(length() + otherlen);
122 46332 copy(other, otherlen, raw() + current_end);
123 46332 return *this;
124 }
125
126 9681709 string& operator+=(char c)
127 {
128 9681709 resize(length() + 1);
129 9681709 raw()[length() - 1] = c;
130 9681709 return *this;
131 }
132
133 string operator+(char right) const
134 {
135 string ret=*this;
136 ret+=right;
137 return ret;
138 }
139
140 44300 string operator+(const char * right) const
141 {
142 44300 string ret=*this;
143
1/2
✓ Branch 0 taken 44300 times.
✗ Branch 1 not taken.
44300 ret+=right;
144 44300 return ret;
145 }
146
147 5460 bool operator==(const char * right) const
148 {
149 5460 return !strcmp(data(), right);
150 }
151
152 104 bool operator==(const string& right) const
153 {
154 104 return !strcmp(data(), right.data());
155 }
156
157 1674 bool operator!=(const char * right) const
158 {
159 1674 return (strcmp(data(), right) != 0);
160 }
161
162 bool operator!=(const string& right) const
163 {
164 return (strcmp(data(), right.data()) != 0);
165 }
166
167 18084181 operator const char*() const
168 {
169 18084181 return data();
170 }
171
172 429710 explicit operator bool() const
173 {
174 429710 return length();
175 }
176
177 16712312 string()
178 16712312 {
179 //todo reduce I know this isn't all needed
180 16712312 allocated.bufferlen = 0;
181 16712312 allocated.str = 0;
182 16712312 allocated.len = 0;
183 16712312 inlined.len = 0;
184 16712312 cached_data = inlined.str;
185 16712312 next_resize = max_inline_length_+1;
186
187 16712312 }
188 4003466 string(const char * newstr) : string()
189 {
190
1/2
✓ Branch 0 taken 4003466 times.
✗ Branch 1 not taken.
4003466 assign(newstr);
191 4003466 }
192 2616164 string(const char * newstr, int newlen) : string()
193 {
194
1/2
✓ Branch 0 taken 2616164 times.
✗ Branch 1 not taken.
2616164 assign(newstr, newlen);
195 2616164 }
196 471150 string(const string& old) : string()
197 {
198
1/2
✓ Branch 0 taken 471150 times.
✗ Branch 1 not taken.
471150 assign(old.data());
199 471150 }
200
201 1118 string(string &&move) : string()
202 {
203
1/2
✓ Branch 0 taken 1118 times.
✗ Branch 1 not taken.
1118 *this = move;
204 1118 }
205
206 2828478 string& operator=(string&& move)
207 {
208
2/2
✓ Branch 0 taken 808 times.
✓ Branch 1 taken 2827670 times.
2828478 if(!is_inlined()) free(allocated.str);
209
2/2
✓ Branch 0 taken 1034 times.
✓ Branch 1 taken 2827444 times.
2828478 if(!move.is_inlined()){
210 1034 allocated.str = move.allocated.str;
211 1034 allocated.bufferlen = move.allocated.bufferlen;
212 1034 set_length(move.allocated.len);
213
214 1034 move.inlined.len = 0;
215 1034 move.inlined.str[0] = 0;
216 1034 cached_data = allocated.str;
217 1034 next_resize = move.next_resize;
218
219 }else{
220 2827444 inlined.len = 0;
221 2827444 cached_data = inlined.str;
222 2827444 next_resize = max_inline_length_+1;
223 2827444 assign(move);
224 }
225 2828478 return *this;
226 }
227
228 16681175 ~string()
229 {
230
2/2
✓ Branch 0 taken 438164 times.
✓ Branch 1 taken 16243011 times.
16681175 if(!is_inlined()){
231 438164 free(allocated.str);
232 }
233 16681175 }
234
235 string& replace(const char * instr, const char * outstr, bool all=true);
236 string& qreplace(const char * instr, const char * outstr, bool all=true);
237
238 #ifdef SERIALIZER
239 void serialize(serializer & s)
240 {
241 s(str, allocated.bufferlen);
242 set_length(strlen(str));
243 }
244 #endif
245 #define SERIALIZER_BANNED
246
247 private:
248 static const int scale_factor = 3; //scale sso
249 static const int max_inline_length_ = ((sizeof(char *) + sizeof(int) * 2) * scale_factor) - 2;
250 char *cached_data;
251 int next_resize;
252 struct si{
253 char str[max_inline_length_ + 1];
254 unsigned char len;
255 };
256
257 struct sa{
258 char *str;
259 int len;
260 int bufferlen ;
261 };
262 union{
263 si inlined;
264 sa allocated;
265 };
266
267
268 28268429 void resize(int new_length)
269 {
270 28268429 const char *old_data = data();
271
8/8
✓ Branch 0 taken 27828038 times.
✓ Branch 1 taken 440391 times.
✓ Branch 2 taken 1321092 times.
✓ Branch 3 taken 26506946 times.
✓ Branch 4 taken 720 times.
✓ Branch 5 taken 1320372 times.
✓ Branch 6 taken 441111 times.
✓ Branch 7 taken 27827318 times.
28268429 if(new_length >= next_resize || (!is_inlined() && new_length <= max_inline_length_)) {
272
7/8
✓ Branch 0 taken 440391 times.
✓ Branch 1 taken 720 times.
✓ Branch 2 taken 659 times.
✓ Branch 3 taken 439732 times.
✓ Branch 4 taken 659 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 440391 times.
✓ Branch 7 taken 720 times.
441111 if(new_length > max_inline_length_ && (is_inlined() || allocated.bufferlen <= new_length)){ //SSO or big to big
273 440391 int new_size = bit_round(new_length + 1);
274
2/2
✓ Branch 0 taken 439732 times.
✓ Branch 1 taken 659 times.
440391 if(old_data == inlined.str){
275 439732 allocated.str = copy(old_data, min_val(length(), new_length), (char *)malloc(new_size));
276 }else{
277 659 allocated.str = (char *)realloc(allocated.str, new_size);
278 659 old_data = inlined.str; //this will prevent freeing a dead realloc ptr
279 }
280 440391 allocated.bufferlen = new_size;
281 440391 cached_data = allocated.str;
282 440391 next_resize = allocated.bufferlen;
283
3/6
✓ Branch 0 taken 720 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 720 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 720 times.
✗ Branch 5 not taken.
720 }else if(length() > max_inline_length_ && new_length <= max_inline_length_){ //big to SSO
284 720 copy(old_data, new_length, inlined.str);
285 720 cached_data = inlined.str;
286 720 next_resize = max_inline_length_+1;
287 }
288
5/6
✓ Branch 0 taken 720 times.
✓ Branch 1 taken 440391 times.
✓ Branch 2 taken 720 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 720 times.
✓ Branch 5 taken 440391 times.
441111 if(old_data != inlined.str && old_data != data()){
289 720 free((char *)old_data);
290 }
291 }
292 28268429 set_length(new_length);
293
294 28268429 raw()[new_length] = 0; //always ensure null terminator
295 28268429 }
296
297 104432992 bool is_inlined() const
298 {
299 104432992 return inlined.len != (unsigned char)-1;
300 }
301 };
302 #define STR (string)
303
304 char * readfile(const char * fname, const char * basepath);
305 char * readfilenative(const char * fname);
306 bool readfile(const char * fname, const char * basepath, char ** data, int * len);//if you want an uchar*, cast it
307 char ** nsplit(char * str, const char * key, int maxlen, int * len);
308 char ** qnsplit(char * str, const char * key, int maxlen, int * len);
309 char ** qpnsplit(char * str, const char * key, int maxlen, int * len);
310 1190 inline char ** split(char * str, const char * key, int * len= nullptr) { return nsplit(str, key, 0, len); }
311 1749348 inline char ** qsplit(char * str, const char * key, int * len= nullptr) { return qnsplit(str, key, 0, len); }
312 219998 inline char ** qpsplit(char * str, const char * key, int * len= nullptr) { return qpnsplit(str, key, 0, len); }
313 inline char ** split1(char * str, const char * key, int * len= nullptr) { return nsplit(str, key, 2, len); }
314 inline char ** qsplit1(char * str, const char * key, int * len= nullptr) { return qnsplit(str, key, 2, len); }
315 inline char ** qpsplit1(char * str, const char * key, int * len= nullptr) { return qpnsplit(str, key, 2, len); }
316 //void replace(string& str, const char * instr, const char * outstr, bool all);
317 //void qreplace(string& str, const char * instr, const char * outstr, bool all);
318 bool confirmquotes(const char * str);
319 bool confirmqpar(const char * str);
320 char* strqpchr(const char* str, char key);
321 char* strqpstr(const char* str, const char* key);
322
323 inline string hex(unsigned int value)
324 {
325 char buffer[64];
326 if(0);
327 else if (value<=0x000000FF) sprintf(buffer, "%.2X", value);
328 else if (value<=0x0000FFFF) sprintf(buffer, "%.4X", value);
329 else if (value<=0x00FFFFFF) sprintf(buffer, "%.6X", value);
330 else sprintf(buffer, "%.8X", value);
331 return buffer;
332 }
333
334 inline string hex(unsigned int value, int width)
335 {
336 char buffer[64];
337 sprintf(buffer, "%.*X", width, value);
338 return buffer;
339 }
340
341 inline string hex0(unsigned int value)
342 {
343 char buffer[64];
344 sprintf(buffer, "%X", value);
345 return buffer;
346 }
347
348 inline string hex2(unsigned int value)
349 {
350 char buffer[64];
351 sprintf(buffer, "%.2X", value);
352 return buffer;
353 }
354
355 inline string hex3(unsigned int value)
356 {
357 char buffer[64];
358 sprintf(buffer, "%.3X", value);
359 return buffer;
360 }
361
362 inline string hex4(unsigned int value)
363 {
364 char buffer[64];
365 sprintf(buffer, "%.4X", value);
366 return buffer;
367 }
368
369 inline string hex5(unsigned int value)
370 {
371 char buffer[64];
372 sprintf(buffer, "%.5X", value);
373 return buffer;
374 }
375
376 2 inline string hex6(unsigned int value)
377 {
378 1 char buffer[64];
379 2 sprintf(buffer, "%.6X", value);
380
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
4 return buffer;
381 }
382
383 inline string hex8(unsigned int value)
384 {
385 char buffer[64];
386 sprintf(buffer, "%.8X", value);
387 return buffer;
388 }
389
390 1754 inline string dec(int value)
391 {
392 877 char buffer[64];
393 1754 sprintf(buffer, "%i", value);
394
1/2
✓ Branch 0 taken 1754 times.
✗ Branch 1 not taken.
3508 return buffer;
395 }
396
397 211206 inline string ftostr(double value)
398 {
399 // randomdude999: With 100 digits of precision, the buffer needs to be approx. 311+100,
400 // but let's be safe here https://stackoverflow.com/questions/7235456
401 105603 char rval[512];
402 // RPG Hacker: Ridiculously high precision, I know, but we're working with doubles
403 // here and can afford it, so no need to waste any precision
404 211206 sprintf(rval, "%.100f", value);
405
1/2
✓ Branch 0 taken 211206 times.
✗ Branch 1 not taken.
211206 if (strchr(rval, '.'))//nuke useless zeroes
406 {
407 211206 char * end=strrchr(rval, '\0')-1;
408
2/2
✓ Branch 0 taken 21120252 times.
✓ Branch 1 taken 211206 times.
21331458 while (*end=='0')
409 {
410 21120252 *end='\0';
411 21120252 end--;
412 }
413
2/2
✓ Branch 0 taken 211200 times.
✓ Branch 1 taken 6 times.
211206 if (*end=='.') *end='\0';
414 }
415
1/2
✓ Branch 0 taken 211206 times.
✗ Branch 1 not taken.
422412 return rval;
416 }
417
418 // Same as above, but with variable precision
419 18 inline string ftostrvar(double value, int precision)
420 {
421 18 int clampedprecision = precision;
422
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if (clampedprecision < 0) clampedprecision = 0;
423
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if (clampedprecision > 100) clampedprecision = 100;
424
425 // see above
426 9 char rval[512];
427 18 sprintf(rval, "%.*f", clampedprecision, (double)value);
428
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 2 times.
18 if (strchr(rval, '.'))//nuke useless zeroes
429 {
430 16 char * end = strrchr(rval, '\0') - 1;
431
2/2
✓ Branch 0 taken 46 times.
✓ Branch 1 taken 16 times.
62 while (*end == '0')
432 {
433 46 *end = '\0';
434 46 end--;
435 }
436
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 10 times.
16 if (*end == '.') *end = '\0';
437 }
438
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
36 return rval;
439 }
440
441 2818716 inline bool stribegin(const char * str, const char * key)
442 {
443
2/2
✓ Branch 0 taken 4075376 times.
✓ Branch 1 taken 225364 times.
4300740 for (int i=0;key[i];i++)
444 {
445
2/2
✓ Branch 0 taken 2593352 times.
✓ Branch 1 taken 1482024 times.
4075376 if (to_lower(str[i])!=to_lower(key[i])) return false;
446 }
447 225364 return true;
448 }
449
450 13924 inline bool striend(const char * str, const char * key)
451 {
452 13924 const char * keyend=strrchr(key, '\0');
453 13924 const char * strend=strrchr(str, '\0');
454
2/2
✓ Branch 0 taken 15690 times.
✓ Branch 1 taken 2866 times.
18556 while (key!=keyend)
455 {
456 15690 keyend--;
457 15690 strend--;
458
2/2
✓ Branch 0 taken 11058 times.
✓ Branch 1 taken 4632 times.
15690 if (to_lower(*strend)!=to_lower(*keyend)) return false;
459 }
460 2866 return true;
461 }
462
463 271516 inline bool stricmpwithupper(const char *word1, const char *word2)
464 {
465
2/2
✓ Branch 0 taken 308174 times.
✓ Branch 1 taken 9650 times.
317824 while(*word2)
466 {
467
2/2
✓ Branch 0 taken 261866 times.
✓ Branch 1 taken 46308 times.
308174 if(to_upper(*word1++) != *word2++) return true;
468 }
469 9650 return *word1;
470 }
471
472 10695086 inline bool stricmpwithlower(const char *word1, const char *word2)
473 {
474
2/2
✓ Branch 0 taken 19213330 times.
✓ Branch 1 taken 1703974 times.
20917304 while(*word2)
475 {
476
2/2
✓ Branch 0 taken 8991112 times.
✓ Branch 1 taken 10222218 times.
19213330 if(to_lower(*word1++) != *word2++) return true;
477 }
478 1703974 return *word1;
479 }
480
481 //function: return the string without quotes around it, if any exists
482 //if they don't exist, return it unaltered
483 //it is not guaranteed to return str
484 //it is not guaranteed to not edit str
485 //the input must be freed even though it's garbage, the output must not
486 1368 inline const char * dequote(char * str)
487 {
488
2/2
✓ Branch 0 taken 84 times.
✓ Branch 1 taken 1284 times.
1368 if (*str!='"') return str;
489 1284 int inpos=1;
490 1284 int outpos=0;
491 while (true)
492 {
493
2/2
✓ Branch 0 taken 1428 times.
✓ Branch 1 taken 14066 times.
15494 if (str[inpos]=='"')
494 {
495
2/2
✓ Branch 0 taken 144 times.
✓ Branch 1 taken 1284 times.
1428 if (str[inpos+1]=='"') inpos++;
496
1/2
✓ Branch 0 taken 1284 times.
✗ Branch 1 not taken.
1284 else if (str[inpos+1]=='\0') break;
497 else return nullptr;
498 }
499
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14210 times.
14210 if (!str[inpos]) return nullptr;
500 14210 str[outpos++]=str[inpos++];
501 }
502 1284 str[outpos]=0;
503 1284 return str;
504 }
505
506 24832 inline char * strqchr(const char * str, char key)
507 {
508
2/2
✓ Branch 0 taken 180022 times.
✓ Branch 1 taken 19014 times.
199036 while (*str != '\0')
509 {
510
2/2
✓ Branch 0 taken 5814 times.
✓ Branch 1 taken 174208 times.
180022 if (*str == key) { return const_cast<char*>(str); }
511
4/4
✓ Branch 0 taken 173376 times.
✓ Branch 1 taken 832 times.
✓ Branch 2 taken 144 times.
✓ Branch 3 taken 173232 times.
174208 else if (*str == '"' || *str == '\'')
512 {
513 // Special case hack for ''', which is currently our official way of handling the ' character.
514 // Even though it really stinks.
515
5/6
✓ Branch 0 taken 144 times.
✓ Branch 1 taken 832 times.
✓ Branch 2 taken 8 times.
✓ Branch 3 taken 136 times.
✓ Branch 4 taken 8 times.
✗ Branch 5 not taken.
976 if (str[0] == '\'' && str[1] == '\'' && str[2] == '\'') { str += 2; }
516 else
517 {
518 968 char delimiter = *str;
519
520 do
521 {
522 13396 str++;
523
524 // If we want to support backslash escapes, we'll have to add that right here.
525
4/4
✓ Branch 0 taken 12432 times.
✓ Branch 1 taken 964 times.
✓ Branch 2 taken 12428 times.
✓ Branch 3 taken 4 times.
13396 } while (*str != delimiter && *str != '\0');
526
527 // This feels like a superfluous check, but I can't really find a clean way to avoid it.
528
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 964 times.
968 if (*str == '\0') { return nullptr; }
529 }
530 }
531
532 174204 str++;
533 }
534
535 19014 return nullptr;
536 }
537
538 // RPG Hacker: WOW, these functions are poopy!
539 13180 inline char * strqrchr(const char * str, char key)
540 {
541 13180 const char * ret= nullptr;
542
2/2
✓ Branch 0 taken 93136 times.
✓ Branch 1 taken 13180 times.
106316 while (*str)
543 {
544
4/4
✓ Branch 0 taken 92362 times.
✓ Branch 1 taken 774 times.
✓ Branch 2 taken 88 times.
✓ Branch 3 taken 92274 times.
93136 if (*str=='"' || *str=='\'')
545 {
546 862 char token = *str;
547
548 862 str++;
549
550 // Special case hack for '''
551
4/4
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 856 times.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 2 times.
862 if (str[0] == '\'' && str[1] == '\'') { str += 2; }
552 else
553 {
554
2/2
✓ Branch 0 taken 8484 times.
✓ Branch 1 taken 858 times.
9342 while (*str != token)
555 {
556
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8484 times.
8484 if (!*str) return nullptr;
557 8484 str++;
558 }
559 858 str++;
560 }
561 862 }
562 else
563 {
564
2/2
✓ Branch 0 taken 3570 times.
✓ Branch 1 taken 88704 times.
92274 if (*str==key) ret=str;
565 92274 str++;
566 }
567 }
568 13180 return const_cast<char*>(ret);
569 }
570
571 2760 inline string substr(const char * str, int len)
572 {
573 2760 return string(str, len);
574 }
575
576 string &strip_prefix(string &str, char c, bool multi=false);
577 string &strip_suffix(string &str, char c, bool multi=false);
578 string &strip_both(string &str, char c, bool multi=false);
579 string &strip_whitespace(string &str);
580
581 char * itrim(char * str, const char * left, const char * right, bool multi=false);
582 string &itrim(string &str, const char * left, const char * right, bool multi=false);
583
584 inline string &upper(string &old)
585 {
586 int length = old.length();
587 for (int i=0;i<length;i++) old.raw()[i]=(char)to_upper(old.data()[i]);
588 return old;
589 }
590
591 1430 inline string &lower(string &old)
592 {
593 1430 int length = old.length();
594
2/2
✓ Branch 0 taken 50368 times.
✓ Branch 1 taken 1430 times.
51798 for (int i=0;i<length;i++) old.raw()[i]=(char)to_lower(old.data()[i]);
595 1430 return old;
596 }
597
598 inline const char * stristr(const char * string, const char * pattern)
599 {
600 if (!*pattern) return string;
601 const char * pptr;
602 const char * sptr;
603 const char * start;
604 for (start=string;*start!=0;start++)
605 {
606 for (;(*start && (to_lower(*start)!=to_lower(*pattern)));start++);
607 if (!*start) return nullptr;
608 pptr=pattern;
609 sptr=start;
610 while (to_lower(*sptr)==to_lower(*pptr))
611 {
612 sptr++;
613 pptr++;
614 if (!*pptr) return start;
615 }
616 }
617 return nullptr;
618 }
619
620
621
622 // Returns number of connected lines - 1
623 template<typename stringarraytype>
624 873878 inline int getconnectedlines(stringarraytype& lines, int startline, string& out)
625 {
626
2/4
✓ Branch 0 taken 873878 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 873878 times.
✗ Branch 3 not taken.
873878 out = string("");
627 873878 int count = 1;
628
629
2/4
✓ Branch 0 taken 872858 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1038 times.
✗ Branch 3 not taken.
873896 for (int i = startline; lines[i]; i++)
630 {
631 // The line should already be stripped of any comments at this point
632 873896 int linestartpos = (int)strlen(lines[i]);
633
634 873896 bool found = false;
635
636
2/2
✓ Branch 0 taken 1726544 times.
✓ Branch 1 taken 10714 times.
1737258 for (int j = linestartpos; j > 0; j--)
637 {
638
9/12
✓ Branch 0 taken 1724468 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 864220 times.
✓ Branch 3 taken 862324 times.
✓ Branch 4 taken 862144 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 863182 times.
✓ Branch 7 taken 863362 times.
✓ Branch 8 taken 1038 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 1038 times.
✓ Branch 11 taken 1038 times.
1726544 if (!is_space(lines[i][j]) && lines[i][j] != '\0' && lines[i][j] != ';')
639 {
640
4/4
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 862132 times.
✓ Branch 2 taken 6 times.
✓ Branch 3 taken 1032 times.
863182 if (lines[i][j] == '\\')
641 {
642 18 count++;
643
4/7
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✓ Branch 3 taken 6 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 6 times.
✗ Branch 6 not taken.
18 out += string(lines[i], j);
644 18 found = true;
645 18 break;
646 }
647 else
648 {
649
4/7
✓ Branch 0 taken 863164 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 862132 times.
✓ Branch 3 taken 1032 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1032 times.
✗ Branch 6 not taken.
863164 out += string(lines[i], j + 1);
650 863164 return count - 1;
651 }
652 }
653 }
654
655
2/2
✓ Branch 0 taken 10714 times.
✓ Branch 1 taken 18 times.
10732 if (!found)
656 {
657
2/7
✓ Branch 0 taken 10714 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 10714 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
10714 out += string(lines[i], 1);
658 10714 return count - 1;
659 }
660 }
661
662 return count - 1;
663 }
664