Skip to content

Commit

Permalink
fix double-escaping of newlines
Browse files Browse the repository at this point in the history
Fixes lvgl#66
  • Loading branch information
bryghtlabs-richard committed Sep 16, 2024
1 parent 807a022 commit 319cef6
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions lib/compiler_template.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@ function to_c(locale) {
return locale.toLowerCase().replace(/-/g, '_');
}

// escape C string to write all in one line.
function esc(str) {
// TODO: simple & dirty, should be improved.
return JSON.stringify(str).slice(1, -1);
}

const pf_enum = {
zero: 'LV_I18N_PLURAL_TYPE_ZERO',
one: 'LV_I18N_PLURAL_TYPE_ONE',
Expand Down Expand Up @@ -49,7 +43,7 @@ function lang_plural_template(l, form, data) {
const loc = to_c(l);
return `
static const lv_i18n_phrase_t ${loc}_plurals_${form}[] = {
${Object.entries(data[l].plural[form]).map(([ k, val ]) => ` {"${esc(k)}", "${esc(val)}"},`).join('\n')}
${Object.entries(data[l].plural[form]).map(([ k, val ]) => ` {"${k}", "${val}"},`).join('\n')}
{NULL, NULL} // End mark
};
`.trim();
Expand All @@ -59,7 +53,7 @@ function lang_singular_template(l, data) {
const loc = to_c(l);
return `
static const lv_i18n_phrase_t ${loc}_singulars[] = {
${Object.entries(data[l].singular).map(([ k, val ]) => ` {"${esc(k)}", "${esc(val)}"},`).join('\n')}
${Object.entries(data[l].singular).map(([ k, val ]) => ` {"${k}", "${val}"},`).join('\n')}
{NULL, NULL} // End mark
};
`.trim();
Expand Down

0 comments on commit 319cef6

Please sign in to comment.