Merge pull request #2931 from jmoenig/michael/utf-8

Better Support Multi-Byte Emoji with `split` and `unicode`
snap7
Jens Mönig 2021-12-15 08:24:49 +01:00 zatwierdzone przez GitHub
commit 4210201e07
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
2 zmienionych plików z 11 dodań i 9 usunięć

Wyświetl plik

@ -932,7 +932,7 @@ List.prototype.asCSV = function () {
return string; return string;
} }
cell = ['\"']; cell = ['\"'];
string.split('').forEach(letter => { Array.from(string).forEach(letter => {
cell.push(letter); cell.push(letter);
if (letter === '\"') { if (letter === '\"') {
cell.push(letter); cell.push(letter);

Wyświetl plik

@ -4344,15 +4344,16 @@ Process.prototype.reportStringSize = function (data) {
}; };
Process.prototype.reportUnicode = function (string) { Process.prototype.reportUnicode = function (string) {
var str; var str, unicodeList;
if (this.enableHyperOps) { if (this.enableHyperOps) {
if (string instanceof List) { if (string instanceof List) {
return string.map(each => this.reportUnicode(each)); return string.map(each => this.reportUnicode(each));
} }
str = isNil(string) ? '\u0000' : string.toString(); str = isNil(string) ? '\u0000' : string.toString();
if (str.length > 1) { unicodeList = Array.from(str);
return this.reportUnicode(new List(str.split(''))); if (unicodeList.length > 1) {
return this.reportUnicode(new List(unicodeList));
} }
} else { } else {
str = isNil(string) ? '\u0000' : string.toString(); str = isNil(string) ? '\u0000' : string.toString();
@ -4420,9 +4421,10 @@ Process.prototype.reportBasicTextSplit = function (string, delimiter) {
str = str.trim(); str = str.trim();
del = /\s+/; del = /\s+/;
break; break;
case isNil(delimiter):
case '':
case 'letter': case 'letter':
del = ''; return new List(Array.from(str));
break;
case 'csv': case 'csv':
return this.parseCSV(string); return this.parseCSV(string);
case 'json': case 'json':
@ -4434,7 +4436,7 @@ Process.prototype.reportBasicTextSplit = function (string, delimiter) {
return this.parseCSVfields(string); return this.parseCSVfields(string);
*/ */
default: default:
del = isNil(delimiter) ? '' : delimiter.toString(); del = delimiter.toString();
} }
return new List(str.split(del)); return new List(str.split(del));
}; };