Skip to content

Commit 15c704b

Browse files
committed
fix(Delimiters): descriptors can split on things other than whitespace
1 parent 8f98713 commit 15c704b

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

src/docs.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -118,16 +118,11 @@ mod kv {
118118
/// as_kv(example) // returns [KV {key: "filename", value: "don't test me"}]
119119
/// ```
120120
pub fn as_kv(input: &str) -> Result<KV, nom::ErrorKind> {
121-
let parts: Vec<_> = input.split(": ").collect();
122-
let result = KV {
123-
key: parts[0].trim().to_string(),
124-
value: parts[1..].join("").to_string(),
121+
let parts: Vec<_> = if input.contains(":") {
122+
input.split(": ").collect()
123+
} else {
124+
input.split_whitespace().collect()
125125
};
126-
Ok(result)
127-
}
128-
129-
pub fn as_kv_whitespace(input: &str) -> Result<KV, nom::ErrorKind> {
130-
let parts: Vec<_> = input.split_whitespace().collect();
131126
let result = KV {
132127
key: parts[0].trim().to_string(),
133128
value: parts[1..].join(" ").to_string(),
@@ -179,7 +174,7 @@ mod doc {
179174
take_until_and_consume!(delims.opt),
180175
take_until_and_consume!("\n")
181176
),
182-
as_kv_whitespace
177+
as_kv
183178
))))
184179
>> par: opt!(many0!(complete!(map_res!(
185180
preceded!(

0 commit comments

Comments
 (0)