summaryrefslogtreecommitdiff
path: root/src/misc.cpp
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2010-08-03 03:25:50 -0400
committerAdam <Adam@anope.org>2010-08-03 03:25:50 -0400
commit44387a2587f30a03d7a1ac5bc4d8b94ce91e31d6 (patch)
treecf13c15faeb0db17aff12fdb58bfbd966838569c /src/misc.cpp
parent59ee16c7cb14d1ac80b9ed9b89d868af45de5ee5 (diff)
Rewrote the GetToken functions to act like they did back in 1.8, fixes many problems with commands using them (hs_set, hs_setall, hs_request)
Diffstat (limited to 'src/misc.cpp')
-rw-r--r--src/misc.cpp38
1 files changed, 13 insertions, 25 deletions
diff --git a/src/misc.cpp b/src/misc.cpp
index 263d45b5f..b8689f888 100644
--- a/src/misc.cpp
+++ b/src/misc.cpp
@@ -511,23 +511,16 @@ bool isvalidchar(char c)
* @param token_number the token number
* @return token
*/
-Anope::string myStrGetToken(const Anope::string &str, char delim, int token_number)
+Anope::string myStrGetToken(const Anope::string &str, char dilim, int token_number)
{
- if (str.empty())
+ if (str.empty() || str.find(dilim) == Anope::string::npos)
return "";
Anope::string substring;
- for (size_t idx = 0, len = str.length(), start_pos = 0, counter = 0; idx <= len; ++idx)
- {
- if (str[idx] == delim || idx == len)
- {
- if (counter == token_number)
- substring = str.substr(start_pos, idx - start_pos - 1);
- else
- start_pos = idx + 1;
- ++counter;
- }
- }
+ sepstream sep(str, dilim);
+
+ for (int i = 0; i < token_number + 1 && !sep.StreamEnd() && sep.GetToken(substring); ++i);
+
return substring;
}
@@ -542,21 +535,16 @@ Anope::string myStrGetToken(const Anope::string &str, char delim, int token_numb
*/
Anope::string myStrGetTokenRemainder(const Anope::string &str, const char dilim, int token_number)
{
- if (str.empty())
+ if (str.empty() || str.find(dilim) == Anope::string::npos)
return "";
Anope::string substring;
- for (size_t idx = 0, len = str.length(), start_pos = 0, counter = 0; idx <= len; ++idx)
- {
- if (str[idx] == dilim || idx == len)
- {
- if (counter == token_number)
- substring = str.substr(start_pos);
- else
- start_pos = idx + 1;
- ++counter;
- }
- }
+ sepstream sep(str, dilim);
+
+ for (int i = 0; i < token_number + 1 && !sep.StreamEnd() && sep.GetToken(substring); ++i);
+
+ if (!sep.StreamEnd())
+ substring += dilim + sep.GetRemaining();
return substring;
}