diff --git a/CHANGELOG.md b/CHANGELOG.md index 63e361ff..87c97c11 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# v0.3.2 +* `structopt` does not replace `:` with `, ` inside "author" strings while inside `<...>`. + Fixes [#156](https://github.com/TeXitoi/structopt/issues/156) + # v0.3.1 (2019-09-06) * Fix error messages ([#241](https://github.com/TeXitoi/structopt/issues/241)) diff --git a/structopt-derive/src/attrs.rs b/structopt-derive/src/attrs.rs index d05e4dd7..1ff0023e 100644 --- a/structopt-derive/src/attrs.rs +++ b/structopt-derive/src/attrs.rs @@ -648,7 +648,27 @@ pub fn sub_type(t: &syn::Type) -> Option<&syn::Type> { } } -/// replace all `:` with `, ` +/// replace all `:` with `, ` when not inside the `<>` +/// +/// `"author1:author2:author3" => "author1, author2, author3"` +/// `"author1 :author2" => "author1 , author2" fn process_author_str(author: &str) -> String { - author.replace(":", ", ") + let mut res = String::with_capacity(author.len()); + let mut inside_angle_braces = 0usize; + + for ch in author.chars() { + if inside_angle_braces > 0 && ch == '>' { + inside_angle_braces -= 1; + res.push(ch); + } else if ch == '<' { + inside_angle_braces += 1; + res.push(ch); + } else if inside_angle_braces == 0 && ch == ':' { + res.push_str(", "); + } else { + res.push(ch); + } + } + + res }