1 #include "parser.h"
2
Instance()3 Parser* Parser::Instance()
4 {
5 static Parser t;
6 return &t; // _instance isn't needed in this case
7 }
8
Parser()9 Parser::Parser()
10 {
11 }
12
returnUntill(string stop,string & line)13 string Parser::returnUntill(string stop, string &line)
14 {
15 string result;
16 size_t pos = line.find_first_of( stop, 0 );
17 if ( pos != string::npos )
18 result = line.substr( 0, pos );
19
20 return result;
21 }
22
returnUntillStrip(string stop,string & line)23 string Parser::returnUntillStrip(string stop, string &line)
24 {
25 string result;
26 size_t pos = line.find_first_of( stop, 0 );
27 if ( pos != string::npos )
28 result = line.substr( 0, pos );
29
30 // strip result from line
31 line = line.substr( pos+1, line.size() );
32 return result;
33 }
34
beginMatchesStrip(string stop,string & line)35 bool Parser::beginMatchesStrip(string stop, string &line)
36 {
37 if ( line.substr( 0, stop.size() ) == stop )
38 {
39 line = line.substr( stop.size(), line.size() );
40 return true;
41 }
42 else return false;
43 }
44
beginMatches(string stop,string & line)45 bool Parser::beginMatches(string stop, string &line)
46 {
47 if ( line.substr( 0, stop.size() ) == stop )
48 return true;
49 return false;
50 }
51
endMatches(string stop,string & line)52 bool Parser::endMatches(string stop, string &line)
53 {
54 if ( line.substr( line.size()-stop.size(), stop.size() ) == stop )
55 return true;
56
57 return false;
58 }
59
contains(string stop,string & line)60 bool Parser::contains(string stop, string &line)
61 {
62 size_t pos = line.find_first_of( stop, 0 );
63 if ( pos != 0 )
64 return true;
65
66 return false;
67 }
68