Skip to content

Commit 23cae14

Browse files
poco0317uvcat7
authored andcommitted
Resolve a mountain of warnings related to String removal and casting
a small amount of this was not actually directly involved in the String removal, but are necessary based on the changes to the Str functions. it would actually be better to remove some of the Str functions. but that would require effort
1 parent c969072 commit 23cae14

File tree

5 files changed

+58
-58
lines changed

5 files changed

+58
-58
lines changed

src/Core/StringUtils.cpp

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ void Str::append(std::string& s, const char* str)
3333
s.append(str);
3434
}
3535

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)
3737
{
3838
if(n > 0)
3939
{
@@ -44,7 +44,7 @@ void Str::append(std::string& s, const char* str, int n)
4444
// ================================================================================================
4545
// Str :: insert functions.
4646

47-
void Str::insert(std::string& s, int pos, char c)
47+
void Str::insert(std::string& s, size_t pos, char c)
4848
{
4949
if (pos >= s.length()) {
5050
s.append(1, c);
@@ -54,23 +54,23 @@ void Str::insert(std::string& s, int pos, char c)
5454
}
5555
}
5656

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)
5858
{
59-
insert(s, pos, str.c_str(), static_cast<int>(str.length()));
59+
insert(s, pos, str.c_str(), str.length());
6060
}
6161

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)
6363
{
64-
insert(s, pos, str, static_cast<int>(strlen(str)));
64+
insert(s, pos, str, strlen(str));
6565
}
6666

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)
6868
{
6969

7070
if (pos >= s.length()) {
7171
s.append(str, n);
7272
}
73-
else if (pos + n > static_cast<int>(s.length())) {
73+
else if (pos + n > s.length()) {
7474
s = s.substr(0, pos) + std::string(str, n) + s.substr(pos);
7575
}
7676
else {
@@ -81,7 +81,7 @@ void Str::insert(std::string& s, int pos, const char* str, int n)
8181
// ================================================================================================
8282
// Str :: resize functions.
8383

84-
void Str::truncate(std::string& s, int n)
84+
void Str::truncate(std::string& s, size_t n)
8585
{
8686
if(n < s.length())
8787
{
@@ -96,7 +96,7 @@ void Str::truncate(std::string& s, int n)
9696
}
9797
}
9898

99-
void Str::extend(std::string& s, int n, char c)
99+
void Str::extend(std::string& s, size_t n, char c)
100100
{
101101
const auto len = s.length();
102102
if(n > len)
@@ -105,7 +105,7 @@ void Str::extend(std::string& s, int n, char c)
105105
}
106106
}
107107

108-
void Str::resize(std::string& s, int n, char c)
108+
void Str::resize(std::string& s, size_t n, char c)
109109
{
110110
if(n > s.length())
111111
{
@@ -179,7 +179,7 @@ bool Str::read(const std::string& s, int* out)
179179
int v = static_cast<int>(std::stol(s));
180180
*out = v;
181181
return true;
182-
} catch (std::exception& e) {
182+
} catch (...) {
183183
// probably want to log the error here
184184
return false;
185185
}
@@ -192,7 +192,7 @@ bool Str::read(const std::string& s, uint32_t* out)
192192
*out = v;
193193
return true;
194194
}
195-
catch (std::exception& e) {
195+
catch (...) {
196196
// probably want to log the error here
197197
return false;
198198
}
@@ -205,7 +205,7 @@ bool Str::read(const std::string& s, float* out)
205205
*out = v;
206206
return true;
207207
}
208-
catch (std::exception& e) {
208+
catch (...) {
209209
// probably want to log the error here
210210
return false;
211211
}
@@ -218,7 +218,7 @@ bool Str::read(const std::string& s, double* out)
218218
*out = v;
219219
return true;
220220
}
221-
catch (std::exception& e) {
221+
catch (...) {
222222
// probably want to log the error here
223223
return false;
224224
}
@@ -282,7 +282,7 @@ void Str::simplify(std::string& s)
282282
s.erase(it, s.end());
283283
}
284284

285-
void Str::erase(std::string& s, int pos, int n)
285+
void Str::erase(std::string& s, size_t pos, size_t n)
286286
{
287287
auto len = s.length();
288288
if(pos < 0) { n += pos, pos = 0; }
@@ -315,7 +315,7 @@ void Str::replace(std::string& s, const char* fnd, const char* rep)
315315
{
316316
if(*fnd == 0) return;
317317

318-
int pos = find(s, fnd);
318+
auto pos = find(s, fnd);
319319
if(pos == std::string::npos) return;
320320
const auto replen = strlen(rep);
321321
const auto fndlen = strlen(fnd);
@@ -340,7 +340,7 @@ void Str::toLower(std::string& s)
340340
// ================================================================================================
341341
// Information functions
342342

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)
344344
{
345345
auto len = s.length();
346346
if(pos < 0) { n += pos, pos = 0; }
@@ -356,15 +356,15 @@ std::string Str::substr(const std::string& s, int pos, int n)
356356
return {};
357357
}
358358

359-
int Str::nextChar(const std::string& s, int pos)
359+
size_t Str::nextChar(const std::string& s, size_t pos)
360360
{
361361
auto len = s.length();
362362
if(pos >= len) return std::string::npos;
363363
do { ++pos; } while(pos < len && (s.at(pos) & 0xC0) == 0x80);
364364
return pos;
365365
}
366366

367-
int Str::prevChar(const std::string& s, int pos)
367+
size_t Str::prevChar(const std::string& s, size_t pos)
368368
{
369369
if(pos <= 0) return -1;
370370
do { --pos; } while(pos >= 0 && (s.at(pos) & 0xC0) == 0x80);
@@ -377,26 +377,26 @@ bool Str::isUnicode(const std::string& s)
377377
return false;
378378
}
379379

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)
381381
{
382382
auto len = s.length();
383383
pos = max(pos, 0);
384384
pos = s.find(c, pos);
385385
return (pos < len) ? pos : std::string::npos;
386386
}
387387

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)
389389
{
390390
pos = max(pos, 0);
391-
int len = s.length();
391+
auto len = s.length();
392392

393393
if(*str == 0 && pos <= len)
394394
return pos;
395395

396396
return s.find(str, pos);
397397
}
398398

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)
400400
{
401401
auto len = s.length();
402402
pos = min(pos, len - 1);
@@ -409,7 +409,7 @@ int Str::findLast(const std::string& s, char c, int pos)
409409
return (pos >= 0) ? pos : -1;
410410
}
411411

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)
413413
{
414414
auto len = s.length();
415415
pos = max(pos, 0);
@@ -423,7 +423,7 @@ int Str::findAnyOf(const std::string& s, const char* c, int pos)
423423
return (pos < len) ? pos : std::string::npos;
424424
}
425425

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)
427427
{
428428
auto len = s.length();
429429
pos = min(pos, len - 1);
@@ -440,7 +440,7 @@ int Str::findLastOf(const std::string& s, const char* c, int pos)
440440
// ================================================================================================
441441
// Str :: compare functions.
442442

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) {
444444
char a, b;
445445
if (lim > 0) {
446446
do {
@@ -457,7 +457,7 @@ static int fastnocasecmp(const char* pStrA, const char* pStrB, int lim = 0) {
457457
return static_cast<int>(a - b);
458458
}
459459

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)
461461
{
462462
if(caseSensitive)
463463
{
@@ -709,14 +709,14 @@ Fmt& Fmt::arg(const char* s)
709709

710710
Fmt& Fmt::arg(const char* s, size_t n)
711711
{
712-
int fmtLen = str.length();
712+
auto fmtLen = str.length();
713713

714714
// find the lowest marker position.
715-
int markerPos = fmtLen;
716-
int markerLen = 0;
715+
auto markerPos = fmtLen;
716+
auto markerLen = 0;
717717
if(fmtLen > 0)
718718
{
719-
int lowestMarker = 100;
719+
size_t lowestMarker = 100;
720720
const char* p = str.c_str();
721721
for(int i = 0; i < fmtLen; ++i)
722722
{
@@ -907,8 +907,8 @@ Vector<std::string> Str::split(const std::string& s, const char* lim, bool trim,
907907
Vector<std::string> out;
908908
auto limlen = strlen(lim);
909909
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;)
912912
{
913913
if(memcmp(s.data() + i, lim, limlen) == 0)
914914
{

src/Core/StringUtils.h

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,28 @@ struct Str
1717
static void append(std::string& s, const char* str);
1818

1919
/// Appends the first n characters from str at the end of the string.
20-
static void append(std::string& s, const char* str, int n);
20+
static void append(std::string& s, const char* str, size_t n);
2121

2222
/// Inserts character c into the string at position pos.
23-
static void insert(std::string& s, int pos, char c);
23+
static void insert(std::string& s, size_t pos, char c);
2424

2525
/// Inserts str into the string at position pos.
26-
static void insert(std::string& s, int pos, const std::string& str);
26+
static void insert(std::string& s, size_t pos, const std::string& str);
2727

2828
/// Inserts str into the string at position pos.
29-
static void insert(std::string& s, int pos, const char* str);
29+
static void insert(std::string& s, size_t pos, const char* str);
3030

3131
/// Inserts the first n characters from str into the string at position pos.
32-
static void insert(std::string& s, int pos, const char* str, int n);
32+
static void insert(std::string& s, size_t pos, const char* str, size_t n);
3333

3434
/// Makes sure the string is at most length n, removing characters at the end if necessary.
35-
static void truncate(std::string& s, int n);
35+
static void truncate(std::string& s, size_t n);
3636

3737
/// Makes sure the string is at least length n, appending c at the end if necessary.
38-
static void extend(std::string& s, int n, char c);
38+
static void extend(std::string& s, size_t n, char c);
3939

4040
/// Makes sure the string is exactly length n, truncating or extending with c if necessary.
41-
static void resize(std::string& s, int n, char c);
41+
static void resize(std::string& s, size_t n, char c);
4242

4343
/// Converts the string to an integer; returns alt on failure.
4444
static int readInt(const std::string& s, int alt = 0);
@@ -92,7 +92,7 @@ struct Str
9292
static void simplify(std::string& s);
9393

9494
/// Erases a sequence of n characters starting at position pos.
95-
static void erase(std::string& s, int pos = 0, int n = std::string::npos);
95+
static void erase(std::string& s, size_t pos = 0, size_t n = std::string::npos);
9696

9797
/// Removes the last character from the string.
9898
static void pop_back(std::string& s);
@@ -111,40 +111,40 @@ struct Str
111111

112112
/// Returns a substring of the string starting at position pos.
113113
/// The substring spans n characters (or until the end of the string, whichever comes first).
114-
static std::string substr(const std::string& s, int pos = 0, int n = std::string::npos);
114+
static std::string substr(const std::string& s, size_t pos = 0, size_t n = std::string::npos);
115115

116116
/// Interprets the string as UTF-8 and returns the position of the next character after pos,
117117
/// which may be an offset of more than one when dealing with multibyte UTF-8 characters.
118118
/// If the next character is past the end of the string, npos is returned.
119-
static int nextChar(const std::string& s, int pos = 0);
119+
static size_t nextChar(const std::string& s, size_t pos = 0);
120120

121121
/// Interprets the string as UTF-8 and returns the position of the previous character before
122122
/// pos, which may be an offset of more than one when dealing with multibyte UTF-8 characters.
123123
/// If the previous character is before the start of the string, -1 is returend.
124-
static int prevChar(const std::string& s, int pos = std::string::npos);
124+
static size_t prevChar(const std::string& s, size_t pos = std::string::npos);
125125

126126
/// Returns true if the string contains non-ascii characters.
127127
static bool isUnicode(const std::string& s);
128128

129129
/// Searches the string for character c.
130130
/// Returns the position of the first occurence on or after pos, or npos if no match is found.
131-
static int find(const std::string& s, char c, int pos = 0);
131+
static size_t find(const std::string& s, char c, size_t pos = 0);
132132

133133
/// Searches the string for substring s.
134134
/// Returns the position of the first occurence on or after pos, or npos if no match is found.
135-
static int find(const std::string& s, const char* str, int pos = 0);
135+
static size_t find(const std::string& s, const char* str, size_t pos = 0);
136136

137137
/// Searches the string for character c.
138138
/// Returns the position of the last occurence on or before pos, or -1 if no match is found.
139-
static int findLast(const std::string& s, char c, int pos = std::string::npos);
139+
static size_t findLast(const std::string& s, char c, size_t pos = std::string::npos);
140140

141141
/// Searches the string for any of the characters in c.
142142
/// Returns the position of the first occurence on or after pos, or npos if no match is found.
143-
static int findAnyOf(const std::string& s, const char* c, int pos = 0);
143+
static size_t findAnyOf(const std::string& s, const char* c, size_t pos = 0);
144144

145145
/// Searches the string for any of the characters in c.
146146
/// Returns the position of the last occurence on or before pos, or -1 if no match is found.
147-
static int findLastOf(const std::string& s, const char* c, int pos = std::string::npos);
147+
static size_t findLastOf(const std::string& s, const char* c, size_t pos = std::string::npos);
148148

149149
// Returns true if the end of the string matches suffix.
150150
static bool endsWith(const std::string& s, const char* suffix, bool caseSensitive = true);

src/Core/TextureImpl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ void Texture::LogInfo()
546546
for(auto tex : TM->textures)
547547
{
548548
const std::string* key = Map::findKey(TM->files, tex);
549-
std::string path = key ? Str::substr(*key, 0, static_cast<int>(key->length()) - 2) : "-- no path --";
549+
std::string path = key ? Str::substr(*key, 0, key->length() - 2) : "-- no path --";
550550

551551
Debug::log("\npath : %s\n", path.c_str());
552552
Debug::log("size : %i x %i\n", tex->w, tex->h);

src/Core/WidgetsText.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,14 +225,14 @@ void WgLineEdit::onTextInput(TextInput& evt)
225225
// truncate input
226226
if (input.length() > MaximumPastedTextLength)
227227
{
228-
Str::erase(input, MaximumPastedTextLength, static_cast<int>(input.length()) - MaximumPastedTextLength);
228+
Str::erase(input, MaximumPastedTextLength, input.length() - MaximumPastedTextLength);
229229
}
230230

231231
// ensure total length does not exceed max length
232232
int maxInputLen = std::min(MaximumPastedTextLength, static_cast<int>(lineedit_max_length_ - lineedit_text_.length()));
233233
if (input.length() > maxInputLen)
234234
{
235-
Str::erase(input, maxInputLen, static_cast<int>(input.length()) - maxInputLen);
235+
Str::erase(input, maxInputLen, input.length() - maxInputLen);
236236
}
237237

238238
Str::insert(lineedit_text_, lineedit_cursor_.y, input);

0 commit comments

Comments
 (0)