Signatures
This commit is contained in:
parent
0372bf78f1
commit
0af4742a14
|
@ -64,12 +64,11 @@ function normalize(text) {
|
||||||
* @returns {String} literal data as text
|
* @returns {String} literal data as text
|
||||||
*/
|
*/
|
||||||
Literal.prototype.getText = function() {
|
Literal.prototype.getText = function() {
|
||||||
if (this.text !== null) {
|
let text;
|
||||||
return this.text;
|
if (this.text === null) {
|
||||||
}
|
|
||||||
let lastChar = '';
|
let lastChar = '';
|
||||||
this.text = this.data.transform((done, value) => {
|
[this.data, this.text] = this.data.tee();
|
||||||
if (!done) {
|
this.text = stream.transform(this.text, value => {
|
||||||
const text = lastChar + util.Uint8Array_to_str(value);
|
const text = lastChar + util.Uint8Array_to_str(value);
|
||||||
// decode UTF8 and normalize EOL to \n
|
// decode UTF8 and normalize EOL to \n
|
||||||
const normalized = normalize(text);
|
const normalized = normalize(text);
|
||||||
|
@ -81,11 +80,10 @@ Literal.prototype.getText = function() {
|
||||||
// else, store the last character for the next chunk in case it's \r or half an UTF8 sequence
|
// else, store the last character for the next chunk in case it's \r or half an UTF8 sequence
|
||||||
lastChar = text[text.length - 1];
|
lastChar = text[text.length - 1];
|
||||||
return normalized.slice(0, -1);
|
return normalized.slice(0, -1);
|
||||||
} else {
|
}, () => lastChar);
|
||||||
return lastChar;
|
|
||||||
}
|
}
|
||||||
});
|
[text, this.text] = this.text.tee();
|
||||||
return this.text;
|
return text;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
10
src/util.js
10
src/util.js
|
@ -226,6 +226,7 @@ export default {
|
||||||
* @returns {Uint8Array} An array of 8-bit integers
|
* @returns {Uint8Array} An array of 8-bit integers
|
||||||
*/
|
*/
|
||||||
str_to_Uint8Array: function (str) {
|
str_to_Uint8Array: function (str) {
|
||||||
|
return stream.transform(str, str => {
|
||||||
if (!util.isString(str)) {
|
if (!util.isString(str)) {
|
||||||
throw new Error('str_to_Uint8Array: Data must be in the form of a string');
|
throw new Error('str_to_Uint8Array: Data must be in the form of a string');
|
||||||
}
|
}
|
||||||
|
@ -235,6 +236,7 @@ export default {
|
||||||
result[i] = str.charCodeAt(i);
|
result[i] = str.charCodeAt(i);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -260,7 +262,7 @@ export default {
|
||||||
* @returns {String} A valid squence of utf8 bytes
|
* @returns {String} A valid squence of utf8 bytes
|
||||||
*/
|
*/
|
||||||
encode_utf8: function (str) {
|
encode_utf8: function (str) {
|
||||||
return unescape(encodeURIComponent(str));
|
return stream.transform(str, value => unescape(encodeURIComponent(value)));
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -626,7 +628,11 @@ export default {
|
||||||
* Normalize line endings to \r\n
|
* Normalize line endings to \r\n
|
||||||
*/
|
*/
|
||||||
canonicalizeEOL: function(text) {
|
canonicalizeEOL: function(text) {
|
||||||
return text.replace(/\r\n/g, "\n").replace(/\r/g, "\n").replace(/\n/g, "\r\n");
|
return stream.transform(text, (done, value) => {
|
||||||
|
if (!done) {
|
||||||
|
return value.replace(/\r\n/g, "\n").replace(/\r/g, "\n").replace(/\n/g, "\r\n");
|
||||||
|
}
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue
Block a user