diff --git a/internal/span/utf16.go b/internal/span/utf16.go index 55e6924889..561b3fa50a 100644 --- a/internal/span/utf16.go +++ b/internal/span/utf16.go @@ -29,6 +29,8 @@ func ToUTF16Column(p Point, content []byte) (int, error) { if colZero == 0 { // 0-based column 0, so it must be chr 1 return 1, nil + } else if colZero < 0 { + return -1, fmt.Errorf("ToUTF16Column: column is invalid (%v)", colZero) } // work out the offset at the start of the line using the column lineOffset := offset - colZero @@ -41,6 +43,7 @@ func ToUTF16Column(p Point, content []byte) (int, error) { // Now, truncate down to the supplied column. start = start[:colZero] + // and count the number of utf16 characters // in theory we could do this by hand more efficiently... return len(utf16.Encode([]rune(string(start)))) + 1, nil