1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
use rusty_yaml::Yaml;
pub fn unwrap<S: ToString>(yaml: &Yaml, section: S) -> String {
let result = yaml
.get_section(section.to_string())
.unwrap()
.nth(0)
.to_string();
let first = match result.chars().nth(0) {
Some(v) => v,
None => ' ',
};
let last = match result.chars().nth(result.len() - 1) {
Some(v) => v,
None => ' ',
};
if first == last {
match first {
'\'' | '"' => result[1..result.len() - 1].to_string(),
_ => result.to_string(),
}
} else {
result.to_string()
}
}
pub fn unmatched_quotes(yaml: &Yaml) -> Option<String> {
for line in yaml.to_string().lines() {
if line.matches('"').count() % 2 != 0 {
return Some(line.to_string());
}
}
None
}