-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathinput.cc
62 lines (49 loc) · 1.05 KB
/
input.cc
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
58
59
60
61
62
#include "input.h"
#include<cstring>
#include<boost/regex.hpp>
#include<iostream>
input::input( converter& conv)
:m_conv( conv ){
}
input::input( std::string raw, converter& conv )
:m_conv(conv){
m_tokens.clear();
split( raw );
convert();
}
input::~input(){
}
void input::convert(){
m_intoks.clear();
for( int i=0; i < m_tokens.size(); ++i){
m_intoks.push_back( m_conv.str2idx( m_tokens[i] ) );
}
}
void input::split( std::string raw ){
#ifdef DEBUG
std::cout << "input::split\t origianl string\n" << raw << std::endl;
#endif
boost::regex sp("\\s+");
boost::sregex_token_iterator sent( raw.begin(),
raw.end(),
sp, -1);
boost::sregex_token_iterator end;
while( sent != end ){
m_tokens.push_back( *sent );
#ifdef DEBUG
std::cout << "input::split\t" << sent->str() << std::endl;
#endif
++sent;
}
#ifdef DEBUG
std::cout << std::endl;
#endif
}
void input::setsrc( std::string raw ){
m_tokens.clear();
split( raw );
convert();
}
std::vector<unsigned int>& input::result(){
return m_intoks;
}