MCPcopy Create free account
hub / github.com/csskit/csskit / line_and_column

Method line_and_column

crates/css_lexer/src/span.rs:71–88  ·  view source on GitHub ↗

Given a string `source`, establish the line number and column number that this span would reside in.

(self, source: &'_ str)

Source from the content-addressed store, hash-verified

69
70 /// Given a string `source`, establish the line number and column number that this span would reside in.
71 pub fn line_and_column(self, source: &'_ str) -> (u32, u32) {
72 let mut line = 0;
73 let mut column = 0;
74 let mut offset = self.start.0;
75 for char in source.chars() {
76 if offset == 0 {
77 break;
78 }
79 if char == '\n' {
80 column = 0;
81 line += 1;
82 } else {
83 column += 1;
84 }
85 offset -= char.len_utf8() as u32;
86 }
87 (line, column)
88 }
89}
90
91/// Extends this [Span], ensuring that the resulting new [Span] is broader than both this and the given [Span].

Callers 4

newMethod · 0.80
render_textMethod · 0.80
from_spanMethod · 0.80
render_textMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected