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
Implement function convertLineEndingsToNative in blob.ts #2695
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It generally looks good, it doesn't seem to be any logical issue in the implementation based on the spec, I just left a few suggestions, especially about collectSequenceNotCRLF
.
js/blob.ts
Outdated
let token = collectionResult.collected; | ||
position = collectionResult.newPosition; | ||
|
||
result = result + token; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
result
is an empty string, no need to use it.
result = result + token; | |
result = token; |
js/blob.ts
Outdated
token = collectionResult.collected; | ||
position = collectionResult.newPosition; | ||
|
||
result = result + token; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
result = result + token; | |
result += token; |
js/blob.ts
Outdated
} | ||
} else if (c == "\n") { | ||
position++; | ||
result = result + nativeLineEnd; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
result = result + nativeLineEnd; | |
result += nativeLineEnd; |
js/blob.ts
Outdated
while (position < s.length) { | ||
let c = s.charAt(position); | ||
if (c == "\r") { | ||
result = result + nativeLineEnd; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
result = result + nativeLineEnd; | |
result += nativeLineEnd; |
js/blob.ts
Outdated
// TODO(qti3e) Implement convertLineEndingsToNative. | ||
// https://w3c.github.io/FileAPI/#convert-line-endings-to-native | ||
return s; | ||
let nativeLineEnd = "\n"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let nativeLineEnd = "\n"; | |
let nativeLineEnd = build.os == "win" ? "\r\n" : "\n"; |
js/blob.ts
Outdated
if (c == "\r" || c == "\n") { | ||
break; | ||
} | ||
result = result.concat(c); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no need to do this call on every iteration, you can obtain the same result using slice()
at the end.
const start = position;
while (...) { ... }
return { collected: s.slice(start, position), newPosition: position };
I would probably use something like this:
function collectSequenceNotCRLF(s, position) {
const start = position;
for (
let c = s.charAt(position);
position < s.length && !(c == '\r' || c == '\n');
c = s.charAt(++position)
);
return { newPosition: position, collected: s.slice(start, position) };
}
👌 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM - thanks!
✌ |
Implemented the function of convertLineEndingsToNative in blob.ts based on next URL.
https://w3c.github.io/FileAPI/#convert-line-endings-to-native