Skip to content

Commit

Permalink
Source: don't assume source file is utf-8
Browse files Browse the repository at this point in the history
  • Loading branch information
ehaas committed Sep 28, 2023
1 parent 8c9c4f5 commit c6b6741
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/Source.zig
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ pub fn lineCol(source: Source, loc: Location) LineCol {
var width: u32 = 0;

while (i < loc.byte_offset) : (col += 1) { // TODO this is still incorrect, but better
const len = std.unicode.utf8ByteSequenceLength(source.buf[i]) catch unreachable;
const len = std.unicode.utf8ByteSequenceLength(source.buf[i]) catch {
i += 1;
continue;
};
const cp = std.unicode.utf8Decode(source.buf[i..][0..len]) catch unreachable;
width += codepointWidth(cp);
i += len;
Expand Down

0 comments on commit c6b6741

Please sign in to comment.