@@ -33,7 +33,7 @@ void Str::append(std::string& s, const char* str)
33
33
s.append (str);
34
34
}
35
35
36
- void Str::append (std::string& s, const char * str, int n)
36
+ void Str::append (std::string& s, const char * str, size_t n)
37
37
{
38
38
if (n > 0 )
39
39
{
@@ -44,7 +44,7 @@ void Str::append(std::string& s, const char* str, int n)
44
44
// ================================================================================================
45
45
// Str :: insert functions.
46
46
47
- void Str::insert (std::string& s, int pos, char c)
47
+ void Str::insert (std::string& s, size_t pos, char c)
48
48
{
49
49
if (pos >= s.length ()) {
50
50
s.append (1 , c);
@@ -54,23 +54,23 @@ void Str::insert(std::string& s, int pos, char c)
54
54
}
55
55
}
56
56
57
- void Str::insert (std::string& s, int pos, const std::string& str)
57
+ void Str::insert (std::string& s, size_t pos, const std::string& str)
58
58
{
59
- insert (s, pos, str.c_str (), static_cast < int >( str.length () ));
59
+ insert (s, pos, str.c_str (), str.length ());
60
60
}
61
61
62
- void Str::insert (std::string& s, int pos, const char * str)
62
+ void Str::insert (std::string& s, size_t pos, const char * str)
63
63
{
64
- insert (s, pos, str, static_cast < int >( strlen (str) ));
64
+ insert (s, pos, str, strlen (str));
65
65
}
66
66
67
- void Str::insert (std::string& s, int pos, const char * str, int n)
67
+ void Str::insert (std::string& s, size_t pos, const char * str, size_t n)
68
68
{
69
69
70
70
if (pos >= s.length ()) {
71
71
s.append (str, n);
72
72
}
73
- else if (pos + n > static_cast < int >( s.length () )) {
73
+ else if (pos + n > s.length ()) {
74
74
s = s.substr (0 , pos) + std::string (str, n) + s.substr (pos);
75
75
}
76
76
else {
@@ -81,7 +81,7 @@ void Str::insert(std::string& s, int pos, const char* str, int n)
81
81
// ================================================================================================
82
82
// Str :: resize functions.
83
83
84
- void Str::truncate (std::string& s, int n)
84
+ void Str::truncate (std::string& s, size_t n)
85
85
{
86
86
if (n < s.length ())
87
87
{
@@ -96,7 +96,7 @@ void Str::truncate(std::string& s, int n)
96
96
}
97
97
}
98
98
99
- void Str::extend (std::string& s, int n, char c)
99
+ void Str::extend (std::string& s, size_t n, char c)
100
100
{
101
101
const auto len = s.length ();
102
102
if (n > len)
@@ -105,7 +105,7 @@ void Str::extend(std::string& s, int n, char c)
105
105
}
106
106
}
107
107
108
- void Str::resize (std::string& s, int n, char c)
108
+ void Str::resize (std::string& s, size_t n, char c)
109
109
{
110
110
if (n > s.length ())
111
111
{
@@ -179,7 +179,7 @@ bool Str::read(const std::string& s, int* out)
179
179
int v = static_cast <int >(std::stol (s));
180
180
*out = v;
181
181
return true ;
182
- } catch (std::exception& e ) {
182
+ } catch (... ) {
183
183
// probably want to log the error here
184
184
return false ;
185
185
}
@@ -192,7 +192,7 @@ bool Str::read(const std::string& s, uint32_t* out)
192
192
*out = v;
193
193
return true ;
194
194
}
195
- catch (std::exception& e ) {
195
+ catch (... ) {
196
196
// probably want to log the error here
197
197
return false ;
198
198
}
@@ -205,7 +205,7 @@ bool Str::read(const std::string& s, float* out)
205
205
*out = v;
206
206
return true ;
207
207
}
208
- catch (std::exception& e ) {
208
+ catch (... ) {
209
209
// probably want to log the error here
210
210
return false ;
211
211
}
@@ -218,7 +218,7 @@ bool Str::read(const std::string& s, double* out)
218
218
*out = v;
219
219
return true ;
220
220
}
221
- catch (std::exception& e ) {
221
+ catch (... ) {
222
222
// probably want to log the error here
223
223
return false ;
224
224
}
@@ -282,7 +282,7 @@ void Str::simplify(std::string& s)
282
282
s.erase (it, s.end ());
283
283
}
284
284
285
- void Str::erase (std::string& s, int pos, int n)
285
+ void Str::erase (std::string& s, size_t pos, size_t n)
286
286
{
287
287
auto len = s.length ();
288
288
if (pos < 0 ) { n += pos, pos = 0 ; }
@@ -315,7 +315,7 @@ void Str::replace(std::string& s, const char* fnd, const char* rep)
315
315
{
316
316
if (*fnd == 0 ) return ;
317
317
318
- int pos = find (s, fnd);
318
+ auto pos = find (s, fnd);
319
319
if (pos == std::string::npos) return ;
320
320
const auto replen = strlen (rep);
321
321
const auto fndlen = strlen (fnd);
@@ -340,7 +340,7 @@ void Str::toLower(std::string& s)
340
340
// ================================================================================================
341
341
// Information functions
342
342
343
- std::string Str::substr (const std::string& s, int pos, int n)
343
+ std::string Str::substr (const std::string& s, size_t pos, size_t n)
344
344
{
345
345
auto len = s.length ();
346
346
if (pos < 0 ) { n += pos, pos = 0 ; }
@@ -356,15 +356,15 @@ std::string Str::substr(const std::string& s, int pos, int n)
356
356
return {};
357
357
}
358
358
359
- int Str::nextChar (const std::string& s, int pos)
359
+ size_t Str::nextChar (const std::string& s, size_t pos)
360
360
{
361
361
auto len = s.length ();
362
362
if (pos >= len) return std::string::npos;
363
363
do { ++pos; } while (pos < len && (s.at (pos) & 0xC0 ) == 0x80 );
364
364
return pos;
365
365
}
366
366
367
- int Str::prevChar (const std::string& s, int pos)
367
+ size_t Str::prevChar (const std::string& s, size_t pos)
368
368
{
369
369
if (pos <= 0 ) return -1 ;
370
370
do { --pos; } while (pos >= 0 && (s.at (pos) & 0xC0 ) == 0x80 );
@@ -377,26 +377,26 @@ bool Str::isUnicode(const std::string& s)
377
377
return false ;
378
378
}
379
379
380
- int Str::find (const std::string& s, char c, int pos)
380
+ size_t Str::find (const std::string& s, char c, size_t pos)
381
381
{
382
382
auto len = s.length ();
383
383
pos = max (pos, 0 );
384
384
pos = s.find (c, pos);
385
385
return (pos < len) ? pos : std::string::npos;
386
386
}
387
387
388
- int Str::find (const std::string& s, const char * str, int pos)
388
+ size_t Str::find (const std::string& s, const char * str, size_t pos)
389
389
{
390
390
pos = max (pos, 0 );
391
- int len = s.length ();
391
+ auto len = s.length ();
392
392
393
393
if (*str == 0 && pos <= len)
394
394
return pos;
395
395
396
396
return s.find (str, pos);
397
397
}
398
398
399
- int Str::findLast (const std::string& s, char c, int pos)
399
+ size_t Str::findLast (const std::string& s, char c, size_t pos)
400
400
{
401
401
auto len = s.length ();
402
402
pos = min (pos, len - 1 );
@@ -409,7 +409,7 @@ int Str::findLast(const std::string& s, char c, int pos)
409
409
return (pos >= 0 ) ? pos : -1 ;
410
410
}
411
411
412
- int Str::findAnyOf (const std::string& s, const char * c, int pos)
412
+ size_t Str::findAnyOf (const std::string& s, const char * c, size_t pos)
413
413
{
414
414
auto len = s.length ();
415
415
pos = max (pos, 0 );
@@ -423,7 +423,7 @@ int Str::findAnyOf(const std::string& s, const char* c, int pos)
423
423
return (pos < len) ? pos : std::string::npos;
424
424
}
425
425
426
- int Str::findLastOf (const std::string& s, const char * c, int pos)
426
+ size_t Str::findLastOf (const std::string& s, const char * c, size_t pos)
427
427
{
428
428
auto len = s.length ();
429
429
pos = min (pos, len - 1 );
@@ -440,7 +440,7 @@ int Str::findLastOf(const std::string& s, const char* c, int pos)
440
440
// ================================================================================================
441
441
// Str :: compare functions.
442
442
443
- static int fastnocasecmp (const char * pStrA, const char * pStrB, int lim = 0 ) {
443
+ static int fastnocasecmp (const char * pStrA, const char * pStrB, size_t lim = 0 ) {
444
444
char a, b;
445
445
if (lim > 0 ) {
446
446
do {
@@ -457,7 +457,7 @@ static int fastnocasecmp(const char* pStrA, const char* pStrB, int lim = 0) {
457
457
return static_cast <int >(a - b);
458
458
}
459
459
460
- static bool Equals (const char * a, const char * b, int len, bool caseSensitive)
460
+ static bool Equals (const char * a, const char * b, size_t len, bool caseSensitive)
461
461
{
462
462
if (caseSensitive)
463
463
{
@@ -709,14 +709,14 @@ Fmt& Fmt::arg(const char* s)
709
709
710
710
Fmt& Fmt::arg (const char * s, size_t n)
711
711
{
712
- int fmtLen = str.length ();
712
+ auto fmtLen = str.length ();
713
713
714
714
// find the lowest marker position.
715
- int markerPos = fmtLen;
716
- int markerLen = 0 ;
715
+ auto markerPos = fmtLen;
716
+ auto markerLen = 0 ;
717
717
if (fmtLen > 0 )
718
718
{
719
- int lowestMarker = 100 ;
719
+ size_t lowestMarker = 100 ;
720
720
const char * p = str.c_str ();
721
721
for (int i = 0 ; i < fmtLen; ++i)
722
722
{
@@ -907,8 +907,8 @@ Vector<std::string> Str::split(const std::string& s, const char* lim, bool trim,
907
907
Vector<std::string> out;
908
908
auto limlen = strlen (lim);
909
909
auto slen = s.length () - limlen;
910
- auto start = 0 ;
911
- for (int i = 0 ; i <= slen;)
910
+ size_t start = 0 ;
911
+ for (size_t i = 0 ; i <= slen;)
912
912
{
913
913
if (memcmp (s.data () + i, lim, limlen) == 0 )
914
914
{
0 commit comments