Skip to content

Commit c28b623

Browse files
committed
Fixed arabic
1 parent 11acd6a commit c28b623

File tree

2 files changed

+109
-25
lines changed

2 files changed

+109
-25
lines changed

mapcode.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,10 +1143,17 @@ function showinlan(str, lan, asHTML) {
11431143
}
11441144

11451145
// unpack for languages that do not support E and U
1146-
if (asc2lan[lan][4] == 63) {
1146+
if (lan == 1) { // greek
1147+
var rest = '';
1148+
var h = str.indexOf('-');
1149+
if (h >= 0) {
1150+
rest = str.substring(h);
1151+
str = str.substring(0, h);
1152+
}
11471153
if (str.indexOf('E') >= 0 || str.indexOf('U') >= 0) {
11481154
str = aeu_pack(aeu_unpack(str), true);
11491155
}
1156+
str += rest;
11501157
}
11511158

11521159
// substitute
@@ -1210,7 +1217,14 @@ function to_ascii(str) {
12101217
p++;
12111218
}
12121219
if (result.charAt(p) == 'A') {
1213-
result = result.substr(0, p) + aeu_pack(aeu_unpack(result.substr(p)), false);
1220+
var mc = result.substr(p);
1221+
var rest = '';
1222+
var h = mc.indexOf('-');
1223+
if (h >= 0) {
1224+
rest = mc.substring(h);
1225+
mc = mc.substring(0, h);
1226+
}
1227+
result = result.substr(0, p) + aeu_pack(aeu_unpack(mc), false) + rest;
12141228
/* v1.50 repack A-voweled to AEU-voweled */
12151229
}
12161230

unittest/unittest.html

Lines changed: 93 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ <h1>Mapcode Javascript Unit Tests</h1>
4545
var nrWarnings = 0;
4646

4747
// test the alphabet conversion routines
48-
4948
var testpairs = [
50-
// "OIoi#%?-.abcdfghjklmnpqrstvwxyz0123456789ABCDFGHJKLMNPQRSTVWXYZ","OIOI#%?-.ABCDFGHJKLMNPQRSTVWXYZ0123456789ABCDFGHJKLMNPQRSTVWXYZ",
51-
// "OEUoi OIoi#%?-.abcdfghjklmnpqrstvwxyz0123456789ABCDFGHJKLMNPQRSTVWXYZ","OEUOI OIOI#%?-.ABCDFGHJKLMNPQRSTVWXYZ0123456789ABCDFGHJKLMNPQRSTVWXYZ",
52-
// "OEUoi OIoi#%?-.abcdfghjklmnpqrstvwxyz0123456789euEUABCDFGHJKLMNPQRSTVWXYZ" , "OEUOI OIOI#%?-.ABCDFGHJKLMNPQRSTVWXYZ0123456789EUEUABCDFGHJKLMNPQRSTVWXYZ",
49+
"12.34E0-PQRSTZVW", "12.34E0-PQRSTZVW",
50+
"OIoi#%?-.abcdfghjklmnpqrstvwxyz0123456789ABCDFGHJKLMNPQRSTVWXYZ", "OIOI#%?-.ABCDFGHJKLMNPQRSTVWXYZ0123456789ABCDFGHJKLMNPQRSTVWXYZ",
51+
"OEUoi OIoi#%?-.abcdfghjklmnpqrstvwxyz0123456789ABCDFGHJKLMNPQRSTVWXYZ", "OEUOI OIOI#%?-.ABCDFGHJKLMNPQRSTVWXYZ0123456789ABCDFGHJKLMNPQRSTVWXYZ",
52+
"OEUoi OIoi#%?-.abcdfghjklmnpqrstvwxyz0123456789euEUABCDFGHJKLMNPQRSTVWXYZ", "OEUOI OIOI#%?-.ABCDFGHJKLMNPQRSTVWXYZ0123456789EUEUABCDFGHJKLMNPQRSTVWXYZ",
5353
"OEUoi OIoi#%?abcdfghjklmnpqrstvwxyz0123456789euEUABCDFGHJKLMNPQRSTVWXYZ", "OEUOI OIOI#%?ABCDFGHJKLMNPQRSTVWXYZ0123456789EUEUABCDFGHJKLMNPQRSTVWXYZ",
5454
".", ".",
5555
"-", "-",
@@ -59,7 +59,7 @@ <h1>Mapcode Javascript Unit Tests</h1>
5959
"OMN 112.3AU", "OMN 112.3AU",
6060
"OMN 112.3EU", "OMN 112.3EU",
6161
"OMN 100.3EU", "OMN 100.3EU",
62-
"OMN 1Oo.3EU", "OMN 1OO.3EU",
62+
"OMN 1Oo.3Oo", "OMN 1OO.3OO",
6363
"49.4V", "49.4V",
6464
"NLD 49.4V-xx123", "NLD 49.4V-XX123",
6565
"xx.xx", "XX.XX",
@@ -86,25 +86,74 @@ <h1>Mapcode Javascript Unit Tests</h1>
8686
"xx.xxx-pq", "XX.XXX-PQ",
8787
"xxx.xx-123", "XXX.XX-123",
8888
"xx.xxxx-pqRS", "XX.XXXX-PQRS",
89-
"xxx.xxx-PQRSTUVW", "XXX.XXX-PQRSTUVW",
90-
"xxxx.xx-pqrstuvw", "XXXX.XX-PQRSTUVW",
91-
"xxx.xxxx-PQrsTU", "XXX.XXXX-PQRSTU",
89+
"xxx.xxx-PQRSTZVW", "XXX.XXX-PQRSTZVW",
90+
"xxxx.xx-pqrstZvw", "XXXX.XX-PQRSTZVW",
91+
"xxx.xxxx-PQrsTZ", "XXX.XXXX-PQRSTZ",
9292
"xxxx.xxx-09876543", "XXXX.XXX-09876543",
93-
"xxxx.xxxx-PQRSTUVW", "XXXX.XXXX-PQRSTUVW",
94-
"xxxxx.xxxx-PQRSTUVW", "XXXXX.XXXX-PQRSTUVW",
95-
"pq.rs-PQRSTUVW", "PQ.RS-PQRSTUVW",
96-
"bc.123-PQRSTUVW", "BC.123-PQRSTUVW",
97-
"123.xy-PQRSTUVW", "123.XY-PQRSTUVW",
98-
"12.34E0-PQRSTUVW", "12.34E0-PQRSTUVW",
99-
"VVX.xxx-PQRSTUVW", "VVX.XXX-PQRSTUVW",
100-
"x123.xx-PQRSTUVW", "X123.XX-PQRSTUVW",
101-
"xxx.xxxx-PQRSTUVW", "XXX.XXXX-PQRSTUVW",
102-
"12xx.xxx-PQRSTUVW", "12XX.XXX-PQRSTUVW",
103-
"xxxx.xx12-PQRSTUVW", "XXXX.XX12-PQRSTUVW",
104-
"99zxx.xxxx-PQRSTUVW", "99ZXX.XXXX-PQRSTUVW",
93+
"xxxx.xxxx-PQRSTZVW", "XXXX.XXXX-PQRSTZVW",
94+
"xxxxx.xxxx-PQRSTZVW", "XXXXX.XXXX-PQRSTZVW",
95+
"pq.rs-PQRSTZVW", "PQ.RS-PQRSTZVW",
96+
"bc.123-PQRSTZVW", "BC.123-PQRSTZVW",
97+
"123.xy-PQRSTZVW", "123.XY-PQRSTZVW",
98+
"VVX.xxx-PQRSTZVW", "VVX.XXX-PQRSTZVW",
99+
"x123.xx-PQRSTZVW", "X123.XX-PQRSTZVW",
100+
"xxx.xxxx-PQRSTZVW", "XXX.XXXX-PQRSTZVW",
101+
"12xx.xxx-PQRSTZVW", "12XX.XXX-PQRSTZVW",
102+
"xxxx.xx12-PQRSTZVW", "XXXX.XX12-PQRSTZVW",
103+
"99zxx.xxxx-PQRSTZVW", "99ZXX.XXXX-PQRSTZVW",
104+
"", ""
105+
];
106+
107+
var greek_versions = [
108+
"26.53UK", "\u039161.328\u03A5",
109+
"FR.B016", "\u0395\u03A81.0716",
110+
"000.EU", "\u0391\u0030\u0030.23",
111+
"PQ.YZ", "\u03a1\u0398.57\u0396",
112+
"PQ.XYZ", "\u03a1\u0398.56\u03a5\u0396",
113+
"PQR.YZ", "\u03a1\u0398.89\u03a5\u0396",
114+
"PQ.RXYZ", "\u03a1\u03983.\u03a70\u03a5\u0396",
115+
"PQR.XYZ", "\u03a1\u03986.\u03a71\u03a5\u0396",
116+
"PQRX.YZ", "\u03a1\u03989.\u03a72\u03a5\u0396",
117+
"PQR.SXYZ", "\u03a1\u03984.\u03a3\u03a79\u03a5\u0396",
118+
"PQRS.XYZ", "\u03a1\u03988.\u03a3\u03a79\u03a5\u0396",
119+
"PQRS.WXYZ", "\u03a1\u03987\u03a3.8\u03a9\u03a72\u03a5",
120+
"PQRST.WXYZ", "\u03a1\u03987\u03a3\u03a4.8\u03a9\u03a72\u03a5",
121+
"P4.YZ", "\u03a14.\u03a5\u0396",
122+
"PQ.4Z", "\u03a1\u0398.4\u0396",
123+
"PQ.4YZ", "\u03a1\u0398.26\u03a5\u0396",
124+
"PQ4.YZ", "\u03a1\u03984.\u03a5\u0396",
125+
"PQ.46YZ", "\u03a1\u03981.61\u03a5\u0396",
126+
"PQ4.6YZ", "\u03a1\u03984.6\u03a5\u0396",
127+
"PQ46.YZ", "\u03a1\u039846.\u03a5\u0396",
128+
"PQ4.S6YZ", "\u03a1\u03982.\u03a366\u03a5\u0396",
129+
"PQ4S.6YZ", "\u03a1\u03984\u03a3.6\u03a5\u0396",
130+
"PQ4S.W6YZ", "\u03a1\u03984\u03a3.\u03a96\u03a5\u0396",
131+
"PQ4PQ.6YZ9", "\u03a1\u03984\u03a1\u0398.6\u03a5\u03969",
132+
"PQ.YZ-BCD", "\u03a1\u0398.57\u0396-\u0392\u039e\u0394",
133+
"PQ.XYZ-BCD", "\u03a1\u0398.56\u03a5\u0396-\u0392\u039e\u0394",
134+
"PQR.YZ-BCD", "\u03a1\u0398.89\u03a5\u0396-\u0392\u039e\u0394",
135+
"PQ.RXYZ-BCD", "\u03a1\u03983.\u03a70\u03a5\u0396-\u0392\u039e\u0394",
136+
"PQR.XYZ-BCD", "\u03a1\u03986.\u03a71\u03a5\u0396-\u0392\u039e\u0394",
137+
"PQRX.YZ-BCD", "\u03a1\u03989.\u03a72\u03a5\u0396-\u0392\u039e\u0394",
138+
"PQR.SXYZ-BCD", "\u03a1\u03984.\u03a3\u03a79\u03a5\u0396-\u0392\u039e\u0394",
139+
"PQRS.XYZ-BCD", "\u03a1\u03988.\u03a3\u03a79\u03a5\u0396-\u0392\u039e\u0394",
140+
"PQRS.WXYZ-BCD", "\u03a1\u03987\u03a3.8\u03a9\u03a72\u03a5-\u0392\u039e\u0394",
141+
"PQRST.WXYZ-BCD", "\u03a1\u03987\u03a3\u03a4.8\u03a9\u03a72\u03a5-\u0392\u039e\u0394",
142+
"P4.YZ-BCD", "\u03a14.\u03a5\u0396-\u0392\u039e\u0394",
143+
"PQ.4Z-BCD", "\u03a1\u0398.4\u0396-\u0392\u039e\u0394",
144+
"PQ.4YZ-BCD", "\u03a1\u0398.26\u03a5\u0396-\u0392\u039e\u0394",
145+
"PQ4.YZ-BCD", "\u03a1\u03984.\u03a5\u0396-\u0392\u039e\u0394",
146+
"PQ.46YZ-BCD", "\u03a1\u03981.61\u03a5\u0396-\u0392\u039e\u0394",
147+
"PQ4.6YZ-BCD", "\u03a1\u03984.6\u03a5\u0396-\u0392\u039e\u0394",
148+
"PQ46.YZ-BCD", "\u03a1\u039846.\u03a5\u0396-\u0392\u039e\u0394",
149+
"PQ4.S6YZ-BCD", "\u03a1\u03982.\u03a366\u03a5\u0396-\u0392\u039e\u0394",
150+
"PQ4S.6YZ-BCD", "\u03a1\u03984\u03a3.6\u03a5\u0396-\u0392\u039e\u0394",
151+
"PQ4S.W6YZ-BCD", "\u03a1\u03984\u03a3.\u03a96\u03a5\u0396-\u0392\u039e\u0394",
152+
"PQ4PQ.6YZ9-BCD", "\u03a1\u03984\u03a1\u0398.6\u03a5\u03969-\u0392\u039e\u0394",
105153
"", ""
106154
];
107155

156+
108157
function alphabet_tests() {
109158
out(MAXLANS + ' alphabets');
110159

@@ -118,10 +167,29 @@ <h1>Mapcode Javascript Unit Tests</h1>
118167
var dec = convertToAlphabet(enc, 0);
119168
if (dec != expect) {
120169
nrErrors++;
121-
out('convertToAlphabet(convertToAlphabet("' + str + '",' + i + '))= "' + dec + '", expected "' + expect + '"');
170+
out('*** ERROR ** convertToAlphabet(convertToAlphabet("' + str + '",' + i + '))= "' + dec + '", expected "' + expect + '"');
122171
}
123172
}
124173
}
174+
175+
for (var t = 0; t < greek_versions.length; t += 2) {
176+
// see if alphabets (re)convert as expected
177+
var str = greek_versions[t];
178+
var expect = greek_versions[t + 1];
179+
nrTests++;
180+
var enc = convertToAlphabet(str, 1); // to greek
181+
if (enc != expect) {
182+
nrErrors++;
183+
out('*** ERROR *** convertToAlphabet("' + str + '",GREEK))= "' + enc + '", expected "' + expect + '"');
184+
}
185+
var dec = convertToAlphabet(enc, 0);
186+
if (dec != str) {
187+
nrErrors++;
188+
out('*** ERROR *** convertToAlphabet(convertToAlphabet("' + str + '",' + i + '))= "' + dec + '", expected "' + str + '"');
189+
}
190+
}
191+
192+
125193
}
126194

127195
function printGeneratedMapcodes(r, name) {
@@ -197,10 +265,12 @@ <h1>Mapcode Javascript Unit Tests</h1>
197265
for (i = 0; i < r.length; i++) {
198266
str = r[i].fullmapcode;
199267

200-
dec = convertToAlphabet(convertToAlphabet(str, 14), 0);
268+
// check conversion back and forth via Arabic script
269+
nrTests++;
270+
var dec = convertToAlphabet(convertToAlphabet(str, 14), 0);
201271
if (dec != str) {
202272
nrError++;
203-
out('*** lanencode ' + str);
273+
out('*** ERROR *** convert back and forth failed: ' + str);
204274
}
205275

206276
nrTests++;

0 commit comments

Comments
 (0)