-
Notifications
You must be signed in to change notification settings - Fork 0
/
helper.cpp
executable file
·94 lines (93 loc) · 2.47 KB
/
helper.cpp
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include "helper.h"
int helper_is_alphabet(char c){
if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))
return 1;
return 0;
}
int helper_is_number(char c){
if ((c >= '0' && c <= '9'))
return 1;
return 0;
}
int helper_is_alphabet(std::string c){
if (c.length() != 1)
return 0;
if ((c >= "a" && c <= "z") || (c >= "A" && c <= "Z"))
return 1;
return 0;
}
int helper_is_same_word(char c){
if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))
return 1;
for (int i = 0; i < basic_component_symbols_count; i++) {
if (c == basic_component_symbols[i]) {
return 1;
}
}
return 0;
}
int helper_is_same_word(std::string str){
if (str.length() != 1)
return 0;
char c = str[0];
if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))
return 1;
for (int i = 0; i < basic_component_symbols_count; i++) {
if (c == basic_component_symbols[i]) {
return 1;
}
}
return 0;
}
int helper_is_number(std::string c){
for (size_t i = 0; i < c.length(); i++) {
if (c[i] - helper_num_char_bias < 0 || c[i] - helper_num_char_bias > 9)
return 0;
}
return 1;
}
int helper_is_basic_symbol_removal(char c){
size_t i;
for (i = 0; i < basic_symbols_removable; i++)
if (c == basic_symbols[i])
return 1;
return 0;
}
int helper_is_basic_end_seperator(char c){
size_t i;
for (i = 0; i < basic_end_seperators_count; i++)
if (c == basic_end_seperators[i])
return 1;
return 0;
}
int helper_is_basic_symbol(char c){
size_t i;
for (i = 0; i < basic_symbols_count; i++)
if (c == basic_symbols[i])
return 1;
return 0;
}
int helper_get_symbol_index(char c){
size_t i;
for (i = 0; i < basic_symbols_count; i++) {
if (c == basic_symbols[i]) {
return (int)i;
}
}
std::cout << "Error: Symbol not found!\n";
return INVALID_SYMBOL;
}
GSymbol::GSymbol(char c){
if (!helper_is_basic_symbol(c)) {
std::cout << "In constructor of class GSymbol:\nError: char not valid!\n";
symbol_index = INVALID_SYMBOL;
}
symbol_index = helper_get_symbol_index(c);
}
void GSymbol::setContent(char c){
if (!helper_is_basic_symbol(c)) {
std::cout << "In constructor of class GSymbol:\nError: char not valid!\n";
symbol_index = INVALID_SYMBOL;
}
symbol_index = helper_get_symbol_index(c);
}