-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tokenizer.h
64 lines (51 loc) · 1.25 KB
/
Tokenizer.h
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
63
64
#pragma once
#include <string>
#include <vector>
#include <map>
#include <stack>
#include <iostream>
#include <iomanip>
class TokenizerRet {
private:
std::string _type;
std::string _value;
int _valueNum;
public:
TokenizerRet();
~TokenizerRet();
TokenizerRet(std::string type, std::string value, int valueNum);
std::string type();
std::string value();
int valueNum();
void printAllInfo();
};
struct KeyWordPack {
std::string _type;
std::string _value;
int _valueNum;
KeyWordPack();
KeyWordPack(std::string type, std::string value, int valueNum);
};
struct CmpByKeyLength {
bool operator() (const std::string& key_1, const std::string& key_2) const {
if (key_1.length() > key_2.length())
return true;
else if (key_1.length() < key_2.length())
return false;
else
return key_1 > key_2;
}
};
class Tokenizer {
private:
std::map<std::string, std::string, CmpByKeyLength> value_type_map;
std::map<std::string, int, CmpByKeyLength> value_valueNum_map;
public:
Tokenizer();
~Tokenizer();
void load_map_data(std::string type,std::string value, int valueNum);
void load_map_data(std::vector<KeyWordPack> keyword_list);
void printAllInfo();
std::string find_keywords(const std::string& str, int pl);
TokenizerRet run(std::string& str);
};