@@ -9,10 +9,21 @@ using namespace std;
9
9
#define _VERSION_ " 1.00"
10
10
#define _DEFAULT_BUFFER_SIZE_ 1024
11
11
string identifiers[] = {
12
- " output"
12
+ " output" ,
13
+ " wrap"
13
14
};
14
15
15
16
17
+ struct UnknowIdentifier : public exception {
18
+ const char * what () const throw () {
19
+ return " Unknow identifier." ;
20
+ }
21
+ };
22
+ struct FileCannotOpen : public exception {
23
+ const char * what () const throw () {
24
+ return " File cannot open." ;
25
+ }
26
+ };
16
27
vector<string> split (string str, char delim) {
17
28
stringstream ss (str);
18
29
string item;
@@ -37,22 +48,31 @@ int main (int argc, char* argv[]) {
37
48
char buffer[bufferSize];
38
49
ifstream file (fileName);
39
50
if (!file.is_open ()) {
40
- cout << " [Error] File cannot open. " << endl ;
51
+ throw FileCannotOpen () ;
41
52
}
42
53
while (file.good ()) {
43
54
file.getline (buffer, sizeof (buffer));
44
55
vector<string> vec (split (string (buffer), ' ' ));
45
56
for (vector<string>::iterator it = vec.begin (); it != vec.end (); it++) {
57
+ bool unknow = true ;
46
58
for (int i = 0 ; i < (sizeof (identifiers) / sizeof (string)); i++) {
47
- if (identifiers[i] != *it) {
48
- if (*(it - 1 ) == identifiers[0 ]) {
49
- cout << *it << endl;
50
- }
51
- else {
52
- cout << " [Error] Unknow identifiers: " << *it << endl;
53
- }
59
+ if (identifiers[i] == *it) {
60
+ unknow = false ;
54
61
}
55
62
}
63
+ if (!unknow) {
64
+ if (*it == identifiers[0 ]) {
65
+ cout << *(it + 1 );
66
+ break ;
67
+ }
68
+ if (*it == identifiers[1 ]) {
69
+ cout << endl;
70
+ }
71
+ // TODO =====================================================================================================
72
+ }
73
+ else {
74
+ throw UnknowIdentifier ();
75
+ }
56
76
}
57
77
}
58
78
}
0 commit comments