Skip to content

add basic String#localeCompare #1008

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

Merged
merged 15 commits into from
Jan 10, 2020
Merged

add basic String#localeCompare #1008

merged 15 commits into from
Jan 10, 2020

Conversation

MaxGraey
Copy link
Member

No description provided.

@MaxGraey MaxGraey requested a review from dcodeIO January 5, 2020 13:53
// <SP>, <TAB>, <LF>, <VT>, <FF>, <CR> and <NBSP>
return c == 0x20 || <u32>(c - 0x09) <= 0x0D - 0x09 || c == 0xA0;
// @ts-ignore: cast
return ((c | 0x80) == 0xA0) | (u32(c - 0x09) <= 0x0D - 0x09);
Copy link
Member

Choose a reason for hiding this comment

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

Can you explain what changed here?

Copy link
Member Author

@MaxGraey MaxGraey Jan 10, 2020

Choose a reason for hiding this comment

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

Sure. If we slightly rearrange original condition as:

(c == 0x20 || c == 0xA0) || <u32>(c - 0x09) <= 0x0D - 0x09

and convert 0x20 and 0xA0 to binary:

0b00100000 // 0x20
0b10100000 // 0xA0
// also
0b10000000 // 0x80

we could see (c | 0b10000000) == 0b10100000 always true for 0b00100000 or 0b10100000 and false overwise

Copy link
Member Author

Choose a reason for hiding this comment

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

Added comment

@dcodeIO dcodeIO merged commit 454e9e6 into AssemblyScript:master Jan 10, 2020
@MaxGraey MaxGraey deleted the string-localeCompare branch January 10, 2020 14:22
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.

2 participants