Skip to main content

line_column_from_string_pos

Function line_column_from_string_pos 

Source
pub fn line_column_from_string_pos(string: &str, pos: u64) -> (u64, u64)
Expand description

Converts a byte position in a string to a line and column number.

This function is useful for error reporting and text editor-like functionality, where you need to display human-readable positions.

§Arguments

  • string - The string to analyze
  • pos - The byte position in the string

§Returns

Returns a tuple of (line, column) where both are 0-indexed.

§Note

Works with both \r\n (Windows) and \n (Unix) line endings.