From 987a92002ff1d56634e43b5243d7f731e2ef38f6 Mon Sep 17 00:00:00 2001 From: Minijackson Date: Sun, 23 Feb 2020 19:59:23 +0100 Subject: clang-parser: fix comment parsing with UTF-8 --- src/parser/clang/parsing.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/parser/clang/parsing.rs b/src/parser/clang/parsing.rs index 82f0a94..f772d4f 100644 --- a/src/parser/clang/parsing.rs +++ b/src/parser/clang/parsing.rs @@ -265,6 +265,7 @@ pub fn parse_comment(raw: String) -> String { let mut result = String::new(); 'parse_loop: loop { + // After the beginning of line comment delimiter / embellishment let maybe_space = chars.next(); let mut empty_line = false; match maybe_space { @@ -278,9 +279,12 @@ pub fn parse_comment(raw: String) -> String { Some(ch) => result.push(ch), } + // After the whitespace following the comment delimiter / embellishment if !empty_line { let rest = chars.as_str(); - match rest.find('\n') { + // Not using .find() here because it returns the byte offset instead of the character + // offset + match rest.chars().position(|c| c == '\n') { None => { result.push_str(rest); break; @@ -302,7 +306,7 @@ pub fn parse_comment(raw: String) -> String { } }; - // `chars` is right after the first non whitespace character + // `chars` is right after the first non whitespace character of the line match style { CommentStyle::Starred if first_non_ws_ch == '*' => { if &chars.as_str()[..1] == "/" { -- cgit v1.2.3