blob: fe892c0e12044b1a9274b3d814ec372ae66f0950 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
/*
* Copyright (C) 2002-2009 InspIRCd Development Team
* Copyright (C) 2008-2009 Anope Team <team@anope.org>
*
* Please read COPYING and README for further details.
*
* These classes have been copied from InspIRCd and modified
* for use in Anope.
*
* $Id$
*
*/
#include "services.h"
#include "hashcomp.h"
sepstream::sepstream(const std::string &source, char seperator) : tokens(source), sep(seperator)
{
last_starting_position = n = tokens.begin();
}
bool sepstream::GetToken(std::string &token)
{
std::string::iterator lsp = last_starting_position;
while (n != tokens.end())
{
if (*n == sep || n + 1 == tokens.end())
{
last_starting_position = n + 1;
token = std::string(lsp, n + 1 == tokens.end() ? n + 1 : ++n);
while (token.length() && token.find_last_of(sep) == token.length() - 1)
token.erase(token.end() - 1);
if (token.empty())
++n;
return n == tokens.end() ? false : true;
}
++n;
}
token = "";
return false;
}
const std::string sepstream::GetRemaining()
{
return std::string(n, tokens.end());
}
bool sepstream::StreamEnd()
{
return n + 1 == tokens.end();
}
|