pub fn index(s: &str, line: u32, column: u32) -> usizeExpand description
Get str byte index of line and column
If the line out the length of the s, return s.len()
§Panics
- line by zero
§Examples
assert_eq!(index("", 1, 1), 0);
assert_eq!(index("a", 1, 1), 0);
assert_eq!(index("a", 1, 2), 1);
assert_eq!(index("a\n", 1, 2), 1);
assert_eq!(index("a\n", 2, 1), 2);
assert_eq!(index("a\nx", 2, 2), 3);
assert_eq!(index("你好\n世界", 1, 2), 3); // byte index
assert_eq!(index("你好\n世界", 1, 3), 6);
assert_eq!(index("你好\n世界", 2, 1), 7);