| 1 | use craterust-analyzer cargo rrule 0.14.0 crate/::parserrust-analyzer cargo rrule 0.14.0 parser/::{regexrust-analyzer cargo rrule 0.14.0 parser/regex/::get_property_namerust-analyzer cargo rrule 0.14.0 parser/regex/get_property_name()., ParseErrorrust-analyzer cargo rrule 0.14.0 parser/error/ParseError#}; |
| 2 | |
| 3 | use superrust-analyzer cargo rrule 0.14.0 parser/content_line/::PropertyNamerust-analyzer cargo rrule 0.14.0 parser/content_line/PropertyName#; |
| 4 | |
| 5 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:)] |
| 6 | pub(craterust-analyzer cargo rrule 0.14.0 crate/) struct ContentLineCapturesrust-analyzer cargo rrule 0.14.0 parser/content_line/content_line_parts/ContentLineCaptures#<'a> { |
| 7 | pub property_namerust-analyzer cargo rrule 0.14.0 parser/content_line/content_line_parts/ContentLineCaptures#property_name.: PropertyNamerust-analyzer cargo rrule 0.14.0 parser/content_line/PropertyName#, |
| 8 | pub parametersrust-analyzer cargo rrule 0.14.0 parser/content_line/content_line_parts/ContentLineCaptures#parameters.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&'a str>, |
| 9 | pub valuerust-analyzer cargo rrule 0.14.0 parser/content_line/content_line_parts/ContentLineCaptures#value.: &'a str, |
| 10 | } |
| 11 | |
| 12 | impl<'a> ContentLineCapturesrust-analyzer cargo rrule 0.14.0 parser/content_line/content_line_parts/ContentLineCaptures#<'a> { |
| 13 | pub(craterust-analyzer cargo rrule 0.14.0 crate/) fn newrust-analyzer cargo rrule 0.14.0 parser/content_line/content_line_parts/impl#[`ContentLineCaptures<'a>`]new().(line: &'a str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo rrule 0.14.0 parser/content_line/content_line_parts/impl#[`ContentLineCaptures<'a>`], ParseErrorrust-analyzer cargo rrule 0.14.0 parser/error/ParseError#> { |
| 14 | // Default property name to RRULE. |
| 15 | let property_name = get_property_namerust-analyzer cargo rrule 0.14.0 parser/regex/get_property_name().(line)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()..unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().(PropertyNamerust-analyzer cargo rrule 0.14.0 parser/content_line/PropertyName#::RRulerust-analyzer cargo rrule 0.14.0 parser/content_line/PropertyName#RRule#); |
| 16 | match property_name { |
| 17 | // If the line did not contain a property name (i.e. no ':'), then the |
| 18 | // entire line is interpreted as the value |
| 19 | PropertyNamerust-analyzer cargo rrule 0.14.0 parser/content_line/PropertyName#::RRulerust-analyzer cargo rrule 0.14.0 parser/content_line/PropertyName#RRule# if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().line.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().(':') => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(ContentLineCapturesrust-analyzer cargo rrule 0.14.0 parser/content_line/content_line_parts/ContentLineCaptures# { |
| 20 | property_namerust-analyzer cargo rrule 0.14.0 parser/content_line/content_line_parts/ContentLineCaptures#property_name.: PropertyNamerust-analyzer cargo rrule 0.14.0 parser/content_line/PropertyName#::RRulerust-analyzer cargo rrule 0.14.0 parser/content_line/PropertyName#RRule#, |
| 21 | parametersrust-analyzer cargo rrule 0.14.0 parser/content_line/content_line_parts/ContentLineCaptures#parameters.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 22 | valuerust-analyzer cargo rrule 0.14.0 parser/content_line/content_line_parts/ContentLineCaptures#value.: line, |
| 23 | }), |
| 24 | property_name => { |
| 25 | let mut parameters = Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#; |
| 26 | if line.starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]starts_with().(&formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{};", property_name)) { |
| 27 | let only_colon_idx = line.findrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]find().(':'); |
| 28 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(only_colon_idx) = only_colon_idx { |
| 29 | parameters = |
| 30 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&line[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().property_name.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().().lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#only_colon_idx]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().); |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Selfrust-analyzer cargo rrule 0.14.0 parser/content_line/content_line_parts/impl#[`ContentLineCaptures<'a>`] { |
| 35 | property_namerust-analyzer cargo rrule 0.14.0 parser/content_line/content_line_parts/ContentLineCaptures#property_name., |
| 36 | parametersrust-analyzer cargo rrule 0.14.0 parser/content_line/content_line_parts/ContentLineCaptures#parameters., |
| 37 | valuerust-analyzer cargo rrule 0.14.0 parser/content_line/content_line_parts/ContentLineCaptures#value.: line |
| 38 | .split_oncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]split_once().(':') |
| 39 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|(_name, val)| val) |
| 40 | .unwrap_or_defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or_default().(), |
| 41 | }) |
| 42 | } |
| 43 | } |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | #[cfg(test)] |
| 48 | mod testsrust-analyzer cargo rrule 0.14.0 parser/content_line/content_line_parts/tests/ { |
| 49 | use superrust-analyzer cargo rrule 0.14.0 parser/content_line/content_line_parts/::*; |
| 50 | |
| 51 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 52 | fn parses_content_line_partsrust-analyzer cargo rrule 0.14.0 parser/content_line/content_line_parts/tests/parses_content_line_parts().() { |
| 53 | let tests = [ |
| 54 | ( |
| 55 | "DTSTART;TZID=America/Everywhere:20120251T023000Z", |
| 56 | ContentLineCapturesrust-analyzer cargo rrule 0.14.0 parser/content_line/content_line_parts/ContentLineCaptures# { |
| 57 | property_namerust-analyzer cargo rrule 0.14.0 parser/content_line/content_line_parts/ContentLineCaptures#property_name.: PropertyNamerust-analyzer cargo rrule 0.14.0 parser/content_line/PropertyName#::DtStartrust-analyzer cargo rrule 0.14.0 parser/content_line/PropertyName#DtStart#, |
| 58 | parametersrust-analyzer cargo rrule 0.14.0 parser/content_line/content_line_parts/ContentLineCaptures#parameters.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("TZID=America/Everywhere"), |
| 59 | valuerust-analyzer cargo rrule 0.14.0 parser/content_line/content_line_parts/ContentLineCaptures#value.: "20120251T023000Z", |
| 60 | }, |
| 61 | ), |
| 62 | ( |
| 63 | "DTSTART:20120251T023000Z", |
| 64 | ContentLineCapturesrust-analyzer cargo rrule 0.14.0 parser/content_line/content_line_parts/ContentLineCaptures# { |
| 65 | property_namerust-analyzer cargo rrule 0.14.0 parser/content_line/content_line_parts/ContentLineCaptures#property_name.: PropertyNamerust-analyzer cargo rrule 0.14.0 parser/content_line/PropertyName#::DtStartrust-analyzer cargo rrule 0.14.0 parser/content_line/PropertyName#DtStart#, |
| 66 | parametersrust-analyzer cargo rrule 0.14.0 parser/content_line/content_line_parts/ContentLineCaptures#parameters.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 67 | valuerust-analyzer cargo rrule 0.14.0 parser/content_line/content_line_parts/ContentLineCaptures#value.: "20120251T023000Z", |
| 68 | }, |
| 69 | ), |
| 70 | ( |
| 71 | "DTSTART;TZID=America/Everywhere:20120251T023000Z", |
| 72 | ContentLineCapturesrust-analyzer cargo rrule 0.14.0 parser/content_line/content_line_parts/ContentLineCaptures# { |
| 73 | property_namerust-analyzer cargo rrule 0.14.0 parser/content_line/content_line_parts/ContentLineCaptures#property_name.: PropertyNamerust-analyzer cargo rrule 0.14.0 parser/content_line/PropertyName#::DtStartrust-analyzer cargo rrule 0.14.0 parser/content_line/PropertyName#DtStart#, |
| 74 | parametersrust-analyzer cargo rrule 0.14.0 parser/content_line/content_line_parts/ContentLineCaptures#parameters.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("TZID=America/Everywhere"), |
| 75 | valuerust-analyzer cargo rrule 0.14.0 parser/content_line/content_line_parts/ContentLineCaptures#value.: "20120251T023000Z", |
| 76 | }, |
| 77 | ), |
| 78 | ( |
| 79 | "RDATE:19970714T123000Z", |
| 80 | ContentLineCapturesrust-analyzer cargo rrule 0.14.0 parser/content_line/content_line_parts/ContentLineCaptures# { |
| 81 | property_namerust-analyzer cargo rrule 0.14.0 parser/content_line/content_line_parts/ContentLineCaptures#property_name.: PropertyNamerust-analyzer cargo rrule 0.14.0 parser/content_line/PropertyName#::RDaterust-analyzer cargo rrule 0.14.0 parser/content_line/PropertyName#RDate#, |
| 82 | parametersrust-analyzer cargo rrule 0.14.0 parser/content_line/content_line_parts/ContentLineCaptures#parameters.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 83 | valuerust-analyzer cargo rrule 0.14.0 parser/content_line/content_line_parts/ContentLineCaptures#value.: "19970714T123000Z", |
| 84 | }, |
| 85 | ), |
| 86 | ( |
| 87 | "RDATE;VALUE=DATE:19970101,19970120,19970217,19970421", |
| 88 | ContentLineCapturesrust-analyzer cargo rrule 0.14.0 parser/content_line/content_line_parts/ContentLineCaptures# { |
| 89 | property_namerust-analyzer cargo rrule 0.14.0 parser/content_line/content_line_parts/ContentLineCaptures#property_name.: PropertyNamerust-analyzer cargo rrule 0.14.0 parser/content_line/PropertyName#::RDaterust-analyzer cargo rrule 0.14.0 parser/content_line/PropertyName#RDate#, |
| 90 | parametersrust-analyzer cargo rrule 0.14.0 parser/content_line/content_line_parts/ContentLineCaptures#parameters.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("VALUE=DATE"), |
| 91 | valuerust-analyzer cargo rrule 0.14.0 parser/content_line/content_line_parts/ContentLineCaptures#value.: "19970101,19970120,19970217,19970421", |
| 92 | }, |
| 93 | ), |
| 94 | ( |
| 95 | "RRULE:FREQ=DAILY;COUNT=10", |
| 96 | ContentLineCapturesrust-analyzer cargo rrule 0.14.0 parser/content_line/content_line_parts/ContentLineCaptures# { |
| 97 | property_namerust-analyzer cargo rrule 0.14.0 parser/content_line/content_line_parts/ContentLineCaptures#property_name.: PropertyNamerust-analyzer cargo rrule 0.14.0 parser/content_line/PropertyName#::RRulerust-analyzer cargo rrule 0.14.0 parser/content_line/PropertyName#RRule#, |
| 98 | parametersrust-analyzer cargo rrule 0.14.0 parser/content_line/content_line_parts/ContentLineCaptures#parameters.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 99 | valuerust-analyzer cargo rrule 0.14.0 parser/content_line/content_line_parts/ContentLineCaptures#value.: "FREQ=DAILY;COUNT=10", |
| 100 | }, |
| 101 | ), |
| 102 | ( |
| 103 | "FREQ=DAILY;COUNT=10", |
| 104 | ContentLineCapturesrust-analyzer cargo rrule 0.14.0 parser/content_line/content_line_parts/ContentLineCaptures# { |
| 105 | // Defaults to RRULE |
| 106 | property_namerust-analyzer cargo rrule 0.14.0 parser/content_line/content_line_parts/ContentLineCaptures#property_name.: PropertyNamerust-analyzer cargo rrule 0.14.0 parser/content_line/PropertyName#::RRulerust-analyzer cargo rrule 0.14.0 parser/content_line/PropertyName#RRule#, |
| 107 | parametersrust-analyzer cargo rrule 0.14.0 parser/content_line/content_line_parts/ContentLineCaptures#parameters.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 108 | valuerust-analyzer cargo rrule 0.14.0 parser/content_line/content_line_parts/ContentLineCaptures#value.: "FREQ=DAILY;COUNT=10", |
| 109 | }, |
| 110 | ), |
| 111 | ]; |
| 112 | for (input, expected_output) in tests { |
| 113 | let output = ContentLineCapturesrust-analyzer cargo rrule 0.14.0 parser/content_line/content_line_parts/ContentLineCaptures#::newrust-analyzer cargo rrule 0.14.0 parser/content_line/content_line_parts/impl#[`ContentLineCaptures<'a>`]new().(input); |
| 114 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(output, Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(expected_output)); |
| 115 | } |
| 116 | } |
| 117 | } |