+/// Trims whitespace and aligns to indent, but otherwise does not change comments.
+fn light_rewrite_comment(orig: &str, offset: Indent, config: &Config) -> Option<String> {
+ let lines: Vec<&str> = orig.lines()
+ .map(|l| {
+ // This is basically just l.trim(), but in the case that a line starts
+ // with `*` we want to leave one space before it, so it aligns with the
+ // `*` in `/*`.
+ let first_non_whitespace = l.find(|c| !char::is_whitespace(c));
+ if let Some(fnw) = first_non_whitespace {
+ if l.as_bytes()[fnw] == '*' as u8 && fnw > 0 {
+ &l[fnw - 1..]
+ } else {
+ &l[fnw..]
+ }
+ } else {
+ ""
+ }
+ .trim_right()
+ })
+ .collect();
+ Some(lines.join(&format!("\n{}", offset.to_string(config))))
+}
+
+/// Trims comment characters and possibly a single space from the left of a string.
+/// Does not trim all whitespace.