aboutsummaryrefslogtreecommitdiffstats
path: root/src/helperfuncs.cpp
diff options
context:
space:
mode:
authorGravatar Sadie Powell2021-04-06 20:06:18 +0100
committerGravatar Sadie Powell2021-04-07 10:36:11 +0100
commit942fd2bcfd384a12c900999fe663202c87319a68 (patch)
treec2bad1906af27afbc3c7d96c3e5ca3c27c83f090 /src/helperfuncs.cpp
parentMerge branch 'insp3' into master. (diff)
Switch simple iterator loops to use range-based for loops.
Diffstat (limited to 'src/helperfuncs.cpp')
-rw-r--r--src/helperfuncs.cpp27
1 files changed, 11 insertions, 16 deletions
diff --git a/src/helperfuncs.cpp b/src/helperfuncs.cpp
index 607f44a28..fd60d7fb1 100644
--- a/src/helperfuncs.cpp
+++ b/src/helperfuncs.cpp
@@ -180,9 +180,9 @@ bool InspIRCd::DefaultIsChannel(const std::string& chname)
if (chname[0] != '#')
return false;
- for (std::string::const_iterator i = chname.begin()+1; i != chname.end(); ++i)
+ for (const auto& chr : insp::iterator_range(chname.begin() + 1, chname.end()))
{
- switch (*i)
+ switch (chr)
{
case ' ':
case ',':
@@ -227,17 +227,13 @@ bool InspIRCd::DefaultIsIdent(const std::string& n)
if (n.empty())
return false;
- for (std::string::const_iterator i = n.begin(); i != n.end(); ++i)
+ for (const auto& chr : n)
{
- if ((*i >= 'A') && (*i <= '}'))
- {
+ if (chr >= 'A' && chr <= '}')
continue;
- }
- if (((*i >= '0') && (*i <= '9')) || (*i == '-') || (*i == '.'))
- {
+ if ((chr >= '0' && chr <= '9') || chr == '-' || chr == '.')
continue;
- }
return false;
}
@@ -345,12 +341,12 @@ bool InspIRCd::Duration(const std::string& str, unsigned long& duration)
unsigned long subtotal = 0;
/* Iterate each item in the string, looking for number or multiplier */
- for (std::string::const_iterator i = str.begin(); i != str.end(); ++i)
+ for (const auto& chr : str)
{
/* Found a number, queue it onto the current number */
- if ((*i >= '0') && (*i <= '9'))
+ if (chr >= '0' && chr <= '9')
{
- subtotal = (subtotal * 10) + (*i - '0');
+ subtotal = (subtotal * 10) + (chr - '0');
}
else
{
@@ -358,7 +354,7 @@ bool InspIRCd::Duration(const std::string& str, unsigned long& duration)
* it multiplies the built up number by, multiply the total
* and reset the built up number.
*/
- unsigned int multiplier = duration_multi[static_cast<unsigned char>(*i)];
+ unsigned int multiplier = duration_multi[static_cast<unsigned char>(chr)];
if (multiplier == 0)
return false;
@@ -382,13 +378,12 @@ unsigned long InspIRCd::Duration(const std::string& str)
bool InspIRCd::IsValidDuration(const std::string& duration)
{
- for (std::string::const_iterator i = duration.begin(); i != duration.end(); ++i)
+ for (const auto& c : duration)
{
- unsigned char c = *i;
if (((c >= '0') && (c <= '9')))
continue;
- if (!duration_multi[c])
+ if (!duration_multi[static_cast<unsigned char>(c)])
return false;
}
return true;