Skip to content
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

Merged
merged 6 commits into from Aug 1, 2019

Conversation

7k8m
Copy link
Contributor

@7k8m 7k8m commented Jul 28, 2019

Implemented the function of convertLineEndingsToNative in blob.ts based on next URL.
https://w3c.github.io/FileAPI/#convert-line-endings-to-native

Copy link
Contributor

@qti3e qti3e left a 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;
Copy link
Contributor

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.

Suggested change
result = result + token;
result = token;

js/blob.ts Outdated
token = collectionResult.collected;
position = collectionResult.newPosition;

result = result + token;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
result = result + token;
result += token;

js/blob.ts Outdated
}
} else if (c == "\n") {
position++;
result = result + nativeLineEnd;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
result = result + nativeLineEnd;
result += nativeLineEnd;

js/blob.ts Outdated
while (position < s.length) {
let c = s.charAt(position);
if (c == "\r") {
result = result + nativeLineEnd;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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);
Copy link
Contributor

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) };
}

@7k8m
Copy link
Contributor Author

7k8m commented Aug 1, 2019

👌

Copy link
Member

@ry ry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - thanks!

@ry ry merged commit deec1b9 into denoland:master Aug 1, 2019
@7k8m
Copy link
Contributor Author

7k8m commented Aug 1, 2019

@piscisaureus piscisaureus mentioned this pull request Aug 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants