Skip to content

Commit 5c5a691

Browse files
committed
Address notes to use size_t instead of int for count parameter.
Signed-off-by: Mei Chu <meimchu@gmail.com>
1 parent d24be22 commit 5c5a691

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

src/utils/StringUtils.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -271,17 +271,17 @@ inline std::string::size_type ReverseFind(const std::string & subject, const std
271271
}
272272

273273
// In place replace the 'search' substring by the 'replace' string in 'subject'. Limited by 'count'.
274-
inline bool ReplaceInPlace(std::string & subject, const std::string & search, const std::string & replace, int count)
274+
inline bool ReplaceInPlace(std::string & subject, const std::string & search, const std::string & replace, size_t count)
275275
{
276-
if (search.empty()) return false;
276+
if (search.empty() || count == 0) { return false; }
277277

278278
bool changed = false;
279279

280280
size_t pos = 0;
281-
int iter = 0;
281+
size_t iter = 0;
282282
while ((pos = subject.find(search, pos)) != std::string::npos)
283283
{
284-
if ( count > -1 && iter >= count ) { break; }
284+
if (iter >= count) { break; }
285285
subject.replace(pos, search.length(), replace);
286286
pos += replace.length();
287287
changed = true;
@@ -294,11 +294,11 @@ inline bool ReplaceInPlace(std::string & subject, const std::string & search, co
294294
// In place replace the 'search' substring by the 'replace' string in 'subject'.
295295
inline bool ReplaceInPlace(std::string & subject, const std::string & search, const std::string & replace)
296296
{
297-
return ReplaceInPlace(subject, search, replace, -1);
297+
return ReplaceInPlace(subject, search, replace, std::string::npos);
298298
}
299299

300300
// Replace the 'search' substring by the 'replace' string in 'subject'. Limited by 'count'.
301-
inline std::string Replace(const std::string & subject, const std::string & search, const std::string & replace, int count)
301+
inline std::string Replace(const std::string & subject, const std::string & search, const std::string & replace, size_t count)
302302
{
303303
std::string str{subject};
304304
ReplaceInPlace(str, search, replace, count);
@@ -308,7 +308,7 @@ inline std::string Replace(const std::string & subject, const std::string & sear
308308
// Replace the 'search' substring by the 'replace' string in 'subject'.
309309
inline std::string Replace(const std::string & subject, const std::string & search, const std::string & replace)
310310
{
311-
return Replace(subject, search, replace, -1);
311+
return Replace(subject, search, replace, std::string::npos);
312312
}
313313

314314
// Check if the 'entry' is in the 'list' using a case insensitive comparison.
@@ -341,14 +341,14 @@ inline bool Remove(StringVec & list, const std::string & entry)
341341
}
342342

343343
// Repeat the 'str' by the 'n' value.
344-
inline std::string Multiply(const std::string & str, int n)
344+
inline std::string Multiply(const std::string & str, size_t n)
345345
{
346346
// Early exits
347347
if (n <= 0) return "";
348348
if (n == 1) return str;
349349

350350
std::ostringstream os;
351-
for(int i = 0; i < n; ++i) { os << str; }
351+
for(size_t i = 0; i < n; ++i) { os << str; }
352352
return os.str();
353353
}
354354

0 commit comments

Comments
 (0)