Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert string to ISO-8859-1 and remove unneccessary mappings #60

Merged
merged 1 commit into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion js/appinfo.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Node.js
if ("undefined"!=typeof module) {
Espruino = require("../lib/espruinotools.js");
Utils = require("./utils.js");

Check warning on line 4 in js/appinfo.js

View workflow job for this annotation

GitHub Actions / test

'Utils' is not defined
heatshrink = require("../../webtools/heatshrink.js");
}

Expand Down Expand Up @@ -74,16 +74,16 @@
if (translation!==undefined) {
// remap any chars that we don't think we can display in Espruino's
// built in fonts.
translation = Utils.convertStringToISOLatin(translation);
translation = Utils.convertStringToISO8859_1(translation);

Check warning on line 77 in js/appinfo.js

View workflow job for this annotation

GitHub Actions / test

'Utils' is not defined
tokenString = toJSString(translation);

Check warning on line 78 in js/appinfo.js

View workflow job for this annotation

GitHub Actions / test

'toJSString' is not defined
}
} else if (tok.str.startsWith("`")) {
// it's a tempated String! scan all clauses inside it and re-run on the JS in those
var re = /\$\{[^}]*\}/g;

Check warning on line 82 in js/appinfo.js

View workflow job for this annotation

GitHub Actions / test

Unexpected var, use let or const instead
while ((match = re.exec(tokenString)) != null) {

Check warning on line 83 in js/appinfo.js

View workflow job for this annotation

GitHub Actions / test

'match' is not defined
var orig = match[0];

Check warning on line 84 in js/appinfo.js

View workflow job for this annotation

GitHub Actions / test

Unexpected var, use let or const instead

Check warning on line 84 in js/appinfo.js

View workflow job for this annotation

GitHub Actions / test

'match' is not defined
var replacement = translateJS(options, app, orig.slice(2,-1));

Check warning on line 85 in js/appinfo.js

View workflow job for this annotation

GitHub Actions / test

Unexpected var, use let or const instead
tokenString = tokenString.substr(0,match.index+2) + replacement + tokenString.substr(match.index + orig.length-1);

Check warning on line 86 in js/appinfo.js

View workflow job for this annotation

GitHub Actions / test

'match' is not defined

Check warning on line 86 in js/appinfo.js

View workflow job for this annotation

GitHub Actions / test

'match' is not defined
}
}
outjs += previousString+tokenString;
Expand Down
32 changes: 7 additions & 25 deletions js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,84 +70,66 @@ let DEVICEINFO = [
}*/
];

/* When a char is not in Espruino's codepage, try and use
/* When a char is not in Espruino's iso8859-1 codepage, try and use
these conversions */
const CODEPAGE_CONVERSIONS = {
"æ":"e",
"å":"a",
"ą":"a",
"ā":"a",
"à":"a",
"č":"c",
"ć":"c",
"ç":"c",
"ě":"e",
"ę":"e",
"ē":"e",
"è":"e",
"é":"e",
"ģ":"g",
"í":"i",
"ī":"i",
"ï":"i",
"ķ":"k",
"ļ":"l",
"ł":"l",
"ń":"n",
"ņ":"n",
"ő":"o",
"ó":"o",
"ò":"o",
"ø":"o",
"ř":"r",
"ś":"s",
"š":"s",
"ú":"u",
"ū":"u",
"ü":"u",
"ż":"z",
"ź":"z",
"ž":"z",
"Ą":"A",
"Ā":"A",
"À":"A",
"Č":"C",
"Ć":"C",
"Ç":"C",
"Ě":"E",
"Ę":"E",
"Ē":"E",
"È":"E",
"É":"E",
"Ģ":"G",
"Ï":"I",
"Ķ":"K",
"Ļ":"L",
"Ł":"L",
"Ń":"N",
"Ņ":"N",
"Ő":"O",
"Ó":"O",
"Ò":"O",
"Ř":"R",
"Ś":"S",
"Š":"S",
"Ū":"U",
"Ú":"U",
"Ü":"U",
"Ż":"Z",
"Ź":"Z",
"Ž":"Z",
};

/// Convert any character that cannot be displayed by Espruino's built in fonts
/// originally https://github.com/espruino/EspruinoAppLoaderCore/pull/11/files
function convertStringToISOLatin(originalStr) {
function convertStringToISO8859_1(originalStr) {
var chars = originalStr.split('');
for (var i = 0; i < chars.length; i++) {
var ch = chars[i];
if (CODEPAGE_CONVERSIONS[ch])
chars[i] = CODEPAGE_CONVERSIONS[ch];
else if (chars[i].charCodeAt() > 255) {
console.log("Skipped conversion of char: '" + chars[i] + "'");
chars[i] = "?";
}
}
var translatedStr = chars.join('');
if (translatedStr != originalStr)
Expand Down Expand Up @@ -481,7 +463,7 @@ var Utils = {
Const : Const,
DEVICEINFO : DEVICEINFO,
CODEPAGE_CONVERSIONS : CODEPAGE_CONVERSIONS,
convertStringToISOLatin : convertStringToISOLatin,
convertStringToISO8859_1 : convertStringToISO8859_1,
escapeHtml : escapeHtml,
globToRegex : globToRegex,
htmlToArray : htmlToArray,
Expand Down
Loading