Fix unicode char parsing in comments.

This commit is contained in:
KtorZ
2023-02-22 17:33:13 +01:00
parent fbf65de1dc
commit 539ed2dea4
2 changed files with 21 additions and 3 deletions

View File

@@ -23,10 +23,15 @@ pub struct Comment<'a> {
impl<'a> From<(&Span, &'a str)> for Comment<'a> {
fn from(src: (&Span, &'a str)) -> Comment<'a> {
let start = src.0.start;
let end = src.0.end;
fn char_indice(s: &str, i: usize) -> usize {
s.char_indices().nth(i).expect("char at given indice").0
}
let start = char_indice(src.1, src.0.start);
let end = char_indice(src.1, src.0.end);
Comment {
start,
start: src.0.start,
content: src.1.get(start..end).expect("From span to comment"),
}
}