Skip to content

Commit c890f92

Browse files
authored
Merge pull request #3096 from mgreter/bugfix/unicode-cp-counting
Fix how we count unicode characters
2 parents ee65eb5 + df8ff3a commit c890f92

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

src/position.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,15 @@ namespace Sass {
5454
// https://stackoverflow.com/a/9356203/1550314
5555
// https://en.wikipedia.org/wiki/UTF-8#Description
5656
unsigned char chr = *begin;
57-
// skip over 10xxxxxx
58-
// is 1st bit not set
59-
if ((chr & 128) == 0) {
57+
// Ignore all `10xxxxxx` chars
58+
// '0xxxxxxx' are ASCII chars
59+
// '11xxxxxx' are utf8 starts
60+
// 64 => initial utf8 byte
61+
// 128 => regular ASCII char
62+
if ((chr & 192) != 128) {
6063
// regular ASCII char
6164
column += 1;
6265
}
63-
// is 2nd bit not set
64-
else if ((chr & 64) == 0) {
65-
// first utf8 byte
66-
column += 1;
67-
}
6866
}
6967
++ begin;
7068
}

0 commit comments

Comments
 (0)