-
Notifications
You must be signed in to change notification settings - Fork 7
/
parser.sh
185 lines (161 loc) · 4.91 KB
/
parser.sh
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#!/bin/bash
function parser_map {
case $flip in
'c') utf="अ"; continue;;
'f') utf="ा"; continue;;
'O') utf="इ"; continue;;
'l') utf="ि"; continue;;
# '') utf="ई"; continue;;
'L') utf="ी"; continue;;
'p') utf="उ"; continue;;
"'") utf="ु"; continue;;
# '') utf="ऊ"; continue;;
'"') utf="ू"; continue;;
'C') utf="ऋ"; continue;;
'P') utf="ए"; continue;;
']') utf="े"; continue;;
# 'i') utf="ऐ"; continue;;
'}') utf="ै"; continue;;
# '') utf="ओ"; continue;;
# '') utf="औ"; continue;;
's') utf="क"; continue;;
'S') utf="क्"; continue;;
'v') utf="ख"; continue;;
'V') utf="ख्"; continue;;
'u') utf="ग"; continue;;
'U') utf="ग्"; continue;;
'3') utf="घ"; continue;;
'£') utf="घ्"; continue;;
'ª') utf="ङ"; continue;;
'Í') utf="ङ्क"; continue;;
'r') utf="च"; continue;;
'R') utf="च्"; continue;;
'5') utf="छ"; continue;;
# 'r') utf="छ्"; continue;;
'h') utf="ज"; continue;;
'H') utf="ज्"; continue;;
''|'¤') utf="झ्"; continue;;
'`') utf="ञ"; continue;;
'~') utf="ञ्"; continue;;
'6') utf="ट"; continue;;
'7') utf="ठ"; continue;;
'§') utf="ट्ट"; continue;;
'Ý') utf="ट्ठ"; continue;;
'8') utf="ड"; continue;;
'9') utf="ढ"; continue;;
'0') utf="ण्"; continue;;
't') utf="त"; continue;;
'T') utf="त्"; continue;;
'Q') utf="त्त"; continue;;
'y') utf="थ"; continue;;
'Y') utf="थ्"; continue;;
'b') utf="द"; continue;;
'å') utf="द्व"; continue;;
'4') utf="द्ध"; continue;;
'2') utf="द्द"; continue;;
'w') utf="ध"; continue;;
'W') utf="ध्"; continue;;
'g') utf="न"; continue;;
'G') utf="न्"; continue;;
'k') utf="प"; continue;;
'K') utf="प्"; continue;;
# '') utf="फ"; continue;;
'Ï') utf="फ्"; continue;;
'a') utf="ब"; continue;;
'A') utf="ब्"; continue;;
'e') utf="भ"; continue;;
'E') utf="भ्"; continue;;
'd') utf="म"; continue;;
'D') utf="म्"; continue;;
'o') utf="य"; continue;;
'Ø') utf="्य"; continue;; # exception no unicode char
'/') utf="र"; continue;;
'{') utf="र्"; continue;;
'¥') utf="र्"; continue;; # exception no unicode char
'«'|'|') utf="्र"; continue;;
'?'|'¿') utf="रु"; continue;;
'[') utf="ृ"; continue;;
'n') utf="ल"; continue;;
'N') utf="ल्"; continue;;
'j') utf="व"; continue;;
'J') utf="व्"; continue;;
'z') utf="श"; continue;;
'Z') utf="श्"; continue;;
'>') utf="श्र"; continue;;
# '>') utf="ष"; continue;;
'i') utf="ष्"; continue;;
';') utf="स"; continue;;
':') utf="स्"; continue;;
'x') utf="ह"; continue;;
'X') utf="ह्"; continue;;
'q') utf="त्र"; continue;;
'I') utf="क्ष्"; continue;;
'1') utf="ज्ञ"; continue;;
'B') utf="द्य"; continue;;
'Ë') utf="ङ्ग"; continue;;
'!') utf="१"; continue;;
'@') utf="२"; continue;;
'#') utf="३"; continue;;
'$') utf="४"; continue;;
'%') utf="५"; continue;;
'^') utf="६"; continue;;
'&') utf="७"; continue;;
'*') utf="८"; continue;;
'(') utf="९"; continue;;
')') utf="०"; continue;;
'-') utf="("; continue;;
'_') utf=")"; continue;;
'M') utf=":"; continue;;
'\') utf="्"; continue;;
'÷') utf="/"; continue;;
'') utf="!"; continue;;
'≤' | 'Ù') utf=";"; continue;;
'.') utf="।"; continue;;
'<') utf="?"; continue;;
'æ'| 'Æ') utf='"'; continue;;
'±') utf="+"; continue;;
'=') utf="."; continue;;
'+') utf="ं"; continue;;
'F'|'') utf="ँ"; continue;;
'') utf="ँ"; continue;; #unknown only for single case
'®') utf="र"; continue;;
'') utf="त्त्"; continue;; #has the ZWJ at end
'
'|'Ú') utf="'"; continue;;
''|'') utf="-"; continue;;
*) utf=$flip;;
esac
}
function parser_init {
text=$@ # $@ can't be used for counting
len=${#text}
out=""
for ((i=0; i <= len; i++)); do
flip=${text:$i:1}
out=$out$utf
parser_map
done
echo -n $out | sed -f $WD/rules.pattern
}
function parser_xml {
text=$@ # $@ can't be used for counting
len=${#text}
out=""
tstate=0 # 0:closed, 1:open
for ((i=0; i <= len; i++)); do
flip=${text:$i:1}
if [[ "$flip" == "<" ]]; then tstate=1; continue
elif [[ "$flip" == ">" ]]; then tstate=0; continue
fi
if (( $tstate == 1 )); then continue; fi
out=$out$utf
parser_map
done
echo -n $out | sed -f $WD/rules.pattern
}
function read_file {
while read data; do
parser_init "$data"
echo
done < $1
exit 0
}