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

Fix how we count unicode characters #3096

Merged
merged 1 commit into from
May 4, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions src/position.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,15 @@ namespace Sass {
// https://stackoverflow.com/a/9356203/1550314
// https://en.wikipedia.org/wiki/UTF-8#Description
unsigned char chr = *begin;
// skip over 10xxxxxx
// is 1st bit not set
if ((chr & 128) == 0) {
// Ignore all `10xxxxxx` chars
// '0xxxxxxx' are ASCII chars
// '11xxxxxx' are utf8 starts
// 64 => initial utf8 byte
// 128 => regular ASCII char
if ((chr & 192) != 128) {
// regular ASCII char
column += 1;
}
// is 2nd bit not set
else if ((chr & 64) == 0) {
// first utf8 byte
column += 1;
}
}
++ begin;
}
Expand Down