Skip to content

Commit a2753ee

Browse files
committed
Improve locale parsing in Linux.
1 parent c7be968 commit a2753ee

1 file changed

Lines changed: 8 additions & 7 deletions

File tree

src/locale.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ var fs = require("fs"),
22
puts = require("util").puts,
33
formats = {},
44
kvRe = /=/,
5-
valueRe = /("[^"]+")/g,
5+
valueRe = /;/g,
6+
quotedRe = /"([^"]+?)"/g,
67
data = [];
78

89
process.stdin.resume();
@@ -14,17 +15,17 @@ function write() {
1415
data.join("\n").split(/\n/g).forEach(function(line) {
1516
var i = line.match(kvRe);
1617
if (i && (i = i.index)) {
17-
var value = line.substring(i + 1).split(valueRe);
18-
formats[line.substring(0, i)] = value.length > 3
19-
? value.map(function(d, i) { return d === "" ? i ? "]" : "[" : d === ";" ? ", " : d; }).join("")
20-
: value[1];
18+
var value = line.substring(i + 1).replace(quotedRe, "$1").split(valueRe);
19+
formats[line.substring(0, i)] = value;
2120
}
2221
});
2322

2423
puts(fs.readFileSync(process.argv[2], "utf8").replace(/\{([^\}]+)\}/g, function(d, k) {
2524
d = formats[k];
2625
return k === "grouping"
27-
? d === "\"127\"" || d === "\"0\"" ? null : d.replace(/^"/, "[").replace(/"$/, "]").replace(/;/, ", ")
28-
: d == null ? null : d;
26+
? d === "127" || d === "0" ? null : "[" + d.map(Number).join(", ") + "]"
27+
: d == null ? null : d.length > 1 ? "[" + d.map(quote).join(", ") + "]" : quote(d[0]);
2928
}));
3029
}
30+
31+
function quote(d) { return '"' + d + '"'; }

0 commit comments

Comments
 (0)