File tree Expand file tree Collapse file tree 3 files changed +22
-5
lines changed Expand file tree Collapse file tree 3 files changed +22
-5
lines changed Original file line number Diff line number Diff line change @@ -103,7 +103,11 @@ namespace Sass {
103
103
// prepend some text or token to the buffer
104
104
void Emitter::prepend_string (const std::string& text)
105
105
{
106
- wbuf.smap .prepend (Offset (text));
106
+ // do not adjust mappings for utf8 bom
107
+ // seems they are not counted in any UA
108
+ if (text.compare (" \xEF\xBB\xBF " ) != 0 ) {
109
+ wbuf.smap .prepend (Offset (text));
110
+ }
107
111
wbuf.buffer = text + wbuf.buffer ;
108
112
}
109
113
Original file line number Diff line number Diff line change @@ -37,7 +37,6 @@ namespace Sass {
37
37
38
38
// increase offset by given string (mostly called by lexer)
39
39
// increase line counter and count columns on the last line
40
- // ToDo: make the col count utf8 aware
41
40
Offset Offset::add (const char * begin, const char * end)
42
41
{
43
42
if (end == 0 ) return *this ;
@@ -47,9 +46,23 @@ namespace Sass {
47
46
// start new line
48
47
column = 0 ;
49
48
} else {
50
- ++ column;
49
+ // do not count any utf8 continuation bytes
50
+ // https://stackoverflow.com/a/9356203/1550314
51
+ // https://en.wikipedia.org/wiki/UTF-8#Description
52
+ unsigned char chr = *begin;
53
+ // skip over 10xxxxxx
54
+ // is 1st bit not set
55
+ if ((chr & 128 ) == 0 ) {
56
+ // regular ascii char
57
+ column += 1 ;
58
+ }
59
+ // is 2nd bit not set
60
+ else if ((chr & 64 ) == 0 ) {
61
+ // first utf8 byte
62
+ column += 1 ;
63
+ }
51
64
}
52
- ++begin;
65
+ ++ begin;
53
66
}
54
67
return *this ;
55
68
}
Original file line number Diff line number Diff line change @@ -136,7 +136,7 @@ namespace Sass {
136
136
}
137
137
}
138
138
}
139
- // will adjust the offset
139
+ // adjust the buffer offset
140
140
prepend (Offset (out.buffer ));
141
141
// now add the new mappings
142
142
VECTOR_UNSHIFT (mappings, out.smap .mappings );
You can’t perform that action at this time.
0 commit comments