diff options
Diffstat (limited to 'src/lib.rs')
-rw-r--r-- | src/lib.rs | 21 |
1 files changed, 17 insertions, 4 deletions
@@ -5,6 +5,7 @@ #![warn(clippy::redundant_closure_for_method_calls)] extern crate alloc; +use alloc::borrow::ToOwned; use alloc::boxed::Box; use alloc::string::String; use alloc::sync::Arc; @@ -271,10 +272,24 @@ fn parse_bool(location: &Location, string: &str) -> Result<bool> { fn parse_list(string: &str) -> Vec<String> { let mut list = vec![]; let mut item = String::new(); + let mut push = |item: &mut String, push_empty: bool| { + let mut item = take(item); + while item.ends_with([' ', '\t']) { + item.pop(); + } + let leading_space_stripped = item.trim_start_matches([' ', '\t']); + if push_empty || !leading_space_stripped.is_empty() { + list.push(if leading_space_stripped.len() == item.len() { + item + } else { + leading_space_stripped.to_owned() + }); + } + }; let mut chars = string.chars(); while let Some(c) = chars.next() { if c == ',' { - list.push(item); + push(&mut item, true); item = String::new(); } else if c == '\\' { if let Some(next) = chars.next() { @@ -292,9 +307,7 @@ fn parse_list(string: &str) -> Vec<String> { item.push(c); } } - if !item.is_empty() { - list.push(item); - } + push(&mut item, false); list } |