1#[derive(Debug, Clone)]
2pub struct Line {
3 pub key: String,
4 pub value: String,
5 pub line_number: u32,
6}
7
8impl Line {
9 pub fn new(key: &str, value: &str, line_number: u32) -> Self {
10 Line {
11 key: Line::sanitize_key(key),
12 value: Line::sanitize_value(value),
13 line_number,
14 }
15 }
16
17 pub fn add_multiline(&mut self, value: &str) -> &Self {
18 let new_value = Line::remove_last_char(&self.value);
19 self.value = [new_value, Line::sanitize_value(value).as_str()].concat();
20 self
21 }
22
23 fn remove_last_char(value: &str) -> &str {
24 let mut chars = value.chars();
25 chars.next_back();
26 chars.as_str()
27 }
28
29 fn sanitize_key(key: &str) -> String {
30 key.trim_end().to_string()
32 }
33
34 fn sanitize_value(value: &str) -> String {
35 value.trim_start().to_string()
37 }
38}