Line Numbers and Byte Offsets in Diagnostics
A file diagnostic can identify a source line and column or the exact position in serialized bytes. The two measurements answer different questions.
- Source
- Anbloq
- Language
- English
- Created
- Updated
- Chapters
- 4
- Reading time
- 1 min
In this article4 chapters
Trace an accented prefix
A UTF-8 line beginning with é uses two bytes before its next code point. A column count based on code points advances once. Code point and character positions explain why visual columns can also differ.
Keep source positions through parsing
Decoded records can carry their line number even after filtering. Use enumerated source indices and state whether numbering starts at zero or one in the output.[1]
Calculate both coordinates on an accented two-line record
UTF-8 text containing é, a newline and then X encodes as C3 A9 0A 58. X starts at zero-based byte offset three, displayed line two and first column. Replacing LF with CRLF moves the offset by one while the logical line remains two. See character positions in Unicode.
Byte offsets: é starts 0, newline 2, X starts 3
Logical locations: é at line 1, X at line 2
Under CRLF: X starts at byte offset 4
State the numbering convention in machine-facing output
Column can mean a code-point position, display column or byte position within a line. Tabs and combining marks can separate these meanings. Use source offsets alongside human-facing positions when tooling needs to locate the exact bytes.