-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringReader.cpp
More file actions
45 lines (41 loc) · 919 Bytes
/
StringReader.cpp
File metadata and controls
45 lines (41 loc) · 919 Bytes
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
#include "StringReader.hpp"
#include "MyServer.hpp"
using namespace std;
StringReader::StringReader(const string &str) : str(str)
{
pos = 0;
}
StringReader::~StringReader() {}
bool StringReader::empty() const
{
return pos == str.size();
}
std::string StringReader::getLine()
{
size_t e = str.find_first_of("\r\n", pos);
if (e == string::npos)
e = str.size();
string res = str.substr(pos, e - pos);
pos = e;
if( pos < str.size() && str[pos] == '\r')
pos++;
if( pos < str.size() && str[pos] == '\n')
pos++;
return res;
}
std::string StringReader::getNBytes(size_t n)
{
if(n > str.size() - pos)
throw Exception("out of bounds exeption");
size_t t = pos;
pos +=n;
return str.substr(t, n);
}
std::string StringReader::getToEnd()
{
return getNBytes(str.size()- pos);
}
std::string StringReader::getAvail()
{
return getToEnd();
}