Skip to content

Commit

Permalink
Do not mangle author string inside <...>
Browse files Browse the repository at this point in the history
  • Loading branch information
CreepySkeleton authored and TeXitoi committed Sep 17, 2019
1 parent 52fa726 commit fe9e049
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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))
Expand Down
24 changes: 22 additions & 2 deletions structopt-derive/src/attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 <http://website1.com>:author2" => "author1 <http://website1.com>, 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
}

0 comments on commit fe9e049

Please sign in to comment.