Function codespan_reporting::files::column_index
source · Expand description
The column index at the given byte index in the source file. This is the number of characters to the given byte index.
If the byte index is smaller than the start of the line, then 0
is returned.
If the byte index is past the end of the line, the column index of the last
character + 1
is returned.
Example
use codespan_reporting::files;
let source = "\n\n🗻∈🌏\n\n";
assert_eq!(files::column_index(source, 0..1, 0), 0);
assert_eq!(files::column_index(source, 2..13, 0), 0);
assert_eq!(files::column_index(source, 2..13, 2 + 0), 0);
assert_eq!(files::column_index(source, 2..13, 2 + 1), 0);
assert_eq!(files::column_index(source, 2..13, 2 + 4), 1);
assert_eq!(files::column_index(source, 2..13, 2 + 8), 2);
assert_eq!(files::column_index(source, 2..13, 2 + 10), 2);
assert_eq!(files::column_index(source, 2..13, 2 + 11), 3);
assert_eq!(files::column_index(source, 2..13, 2 + 12), 3);