Skip to content

Commit b4224cd

Browse files
authored
Merge pull request #60 from jordimas/iso8859-1
Convert string to ISO-8859-1 and remove unneccessary mappings
2 parents e9bda95 + 6c81b26 commit b4224cd

File tree

2 files changed

+8
-26
lines changed

2 files changed

+8
-26
lines changed

js/appinfo.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ function translateJS(options, app, code) {
7474
if (translation!==undefined) {
7575
// remap any chars that we don't think we can display in Espruino's
7676
// built in fonts.
77-
translation = Utils.convertStringToISOLatin(translation);
77+
translation = Utils.convertStringToISO8859_1(translation);
7878
tokenString = toJSString(translation);
7979
}
8080
} else if (tok.str.startsWith("`")) {

js/utils.js

+7-25
Original file line numberDiff line numberDiff line change
@@ -70,84 +70,66 @@ let DEVICEINFO = [
7070
}*/
7171
];
7272

73-
/* When a char is not in Espruino's codepage, try and use
73+
/* When a char is not in Espruino's iso8859-1 codepage, try and use
7474
these conversions */
7575
const CODEPAGE_CONVERSIONS = {
76-
"æ":"e",
77-
"å":"a",
7876
"ą":"a",
7977
"ā":"a",
80-
"à":"a",
8178
"č":"c",
8279
"ć":"c",
83-
"ç":"c",
8480
"ě":"e",
8581
"ę":"e",
8682
"ē":"e",
87-
"è":"e",
88-
"é":"e",
8983
"ģ":"g",
90-
"í":"i",
9184
"ī":"i",
92-
"ï":"i",
9385
"ķ":"k",
9486
"ļ":"l",
9587
"ł":"l",
9688
"ń":"n",
9789
"ņ":"n",
9890
"ő":"o",
99-
"ó":"o",
100-
"ò":"o",
101-
"ø":"o",
10291
"ř":"r",
10392
"ś":"s",
10493
"š":"s",
105-
"ú":"u",
10694
"ū":"u",
107-
"ü":"u",
10895
"ż":"z",
10996
"ź":"z",
11097
"ž":"z",
11198
"Ą":"A",
11299
"Ā":"A",
113-
"À":"A",
114100
"Č":"C",
115101
"Ć":"C",
116-
"Ç":"C",
117102
"Ě":"E",
118103
"Ę":"E",
119104
"Ē":"E",
120-
"È":"E",
121-
"É":"E",
122105
"Ģ":"G",
123-
"Ï":"I",
124106
"Ķ":"K",
125107
"Ļ":"L",
126108
"Ł":"L",
127109
"Ń":"N",
128110
"Ņ":"N",
129111
"Ő":"O",
130-
"Ó":"O",
131-
"Ò":"O",
132112
"Ř":"R",
133113
"Ś":"S",
134114
"Š":"S",
135115
"Ū":"U",
136-
"Ú":"U",
137-
"Ü":"U",
138116
"Ż":"Z",
139117
"Ź":"Z",
140118
"Ž":"Z",
141119
};
142120

143121
/// Convert any character that cannot be displayed by Espruino's built in fonts
144122
/// originally https://github.com/espruino/EspruinoAppLoaderCore/pull/11/files
145-
function convertStringToISOLatin(originalStr) {
123+
function convertStringToISO8859_1(originalStr) {
146124
var chars = originalStr.split('');
147125
for (var i = 0; i < chars.length; i++) {
148126
var ch = chars[i];
149127
if (CODEPAGE_CONVERSIONS[ch])
150128
chars[i] = CODEPAGE_CONVERSIONS[ch];
129+
else if (chars[i].charCodeAt() > 255) {
130+
console.log("Skipped conversion of char: '" + chars[i] + "'");
131+
chars[i] = "?";
132+
}
151133
}
152134
var translatedStr = chars.join('');
153135
if (translatedStr != originalStr)
@@ -481,7 +463,7 @@ var Utils = {
481463
Const : Const,
482464
DEVICEINFO : DEVICEINFO,
483465
CODEPAGE_CONVERSIONS : CODEPAGE_CONVERSIONS,
484-
convertStringToISOLatin : convertStringToISOLatin,
466+
convertStringToISO8859_1 : convertStringToISO8859_1,
485467
escapeHtml : escapeHtml,
486468
globToRegex : globToRegex,
487469
htmlToArray : htmlToArray,

0 commit comments

Comments
 (0)