Helper class for finding newlines in a string, so that error messages can convert string-relative offsets into line numbers.
More...
#include "donner/base/parser/LineOffsets.h"
|
| | LineOffsets (std::string_view input) |
| | Construct a LineOffsets object for the given input string.
|
|
const std::vector< size_t > & | offsets () const |
| | Return the offsets of the start of each line.
|
| size_t | offsetToLine (size_t offset) const |
| | Return line numbers for the given offset.
|
| size_t | lineOffset (size_t line) const |
| | Returns the offset of a given 1-indexed line number.
|
| FileOffset | fileOffset (size_t offset) const |
| | Returns the offset as a FileOffset with line information.
|
Helper class for finding newlines in a string, so that error messages can convert string-relative offsets into line numbers.
This supports all newline styles, including \r\n and \r.
◆ LineOffsets()
| donner::parser::LineOffsets::LineOffsets |
( |
std::string_view | input | ) |
|
|
inlineexplicit |
Construct a LineOffsets object for the given input string.
- Parameters
-
◆ fileOffset()
| FileOffset donner::parser::LineOffsets::fileOffset |
( |
size_t | offset | ) |
const |
|
inline |
Returns the offset as a FileOffset with line information.
- Parameters
-
◆ lineOffset()
| size_t donner::parser::LineOffsets::lineOffset |
( |
size_t | line | ) |
const |
|
inline |
Returns the offset of a given 1-indexed line number.
- Parameters
-
| line | Line number, starting from 1. |
◆ offsetToLine()
| size_t donner::parser::LineOffsets::offsetToLine |
( |
size_t | offset | ) |
const |
|
inline |
Return line numbers for the given offset.
For example, given a string: "abc\n123", offsets 0-3 would be considered line 1, and offsets after 4 (corresponding to the index of '1'), would be line 2. Values beyond the length of the string return the last line number.
- Parameters
-
- Returns
- size_t Line number, 1-indexed.
The documentation for this class was generated from the following file:
- donner/base/parser/LineOffsets.h