json_template/path/
mod.rs1pub struct Path<'a> {
5 path: &'a str
6}
7
8impl<'a> Path<'a> {
9 pub fn new(path: &'a str) -> Self {
11 Self { path }
12 }
13
14 pub fn str(&self) -> &str {
16 self.path
17 }
18
19 pub fn segments(&self) -> Vec<&str> {
25 let mut level = 0;
26 let mut current_segment_start = 0;
27 let mut current_segment_end = 0;
28 let mut segments = Vec::new();
29 for character in self.str().chars() {
30 match character {
31 '{' => level += 1,
32 '}' => level -= 1,
33 '.' => if level == 0 {
34 segments.push(&self.str()[current_segment_start .. current_segment_end]);
35 current_segment_start = current_segment_end + 1;
36 },
37 _ => {}
38 }
39 current_segment_end += 1;
40 }
41 segments.push(&self.str()[current_segment_start .. current_segment_end]);
42 segments
43 }
44}