@@ -24,6 +24,19 @@ impl ConfigurationSection {
24
24
fn get_section < I : Iterator < Item = String > > (
25
25
file : & mut Enumerate < I > ,
26
26
) -> Option < ConfigurationSection > {
27
+ lazy_static ! {
28
+ static ref CONFIG_NAME_REGEX : regex:: Regex =
29
+ regex:: Regex :: new( r"^## `([^`]+)`" ) . expect( "failed creating configuration pattern" ) ;
30
+ // Configuration values, which will be passed to `from_str`:
31
+ //
32
+ // - must be prefixed with `####`
33
+ // - must be wrapped in backticks
34
+ // - may by wrapped in double quotes (which will be stripped)
35
+ static ref CONFIG_VALUE_REGEX : regex:: Regex =
36
+ regex:: Regex :: new( r#"^#### `"?([^`]+?)"?`"# )
37
+ . expect( "failed creating configuration value pattern" ) ;
38
+ }
39
+
27
40
loop {
28
41
match file. next ( ) {
29
42
Some ( ( i, line) ) => {
@@ -40,14 +53,9 @@ impl ConfigurationSection {
40
53
let start_line = ( i + 2 ) as u32 ;
41
54
42
55
return Some ( ConfigurationSection :: CodeBlock ( ( block, start_line) ) ) ;
43
- } else if let Some ( c) = static_regex ! ( r"^## `([^`]+)`" ) . captures ( & line) {
56
+ } else if let Some ( c) = CONFIG_NAME_REGEX . captures ( & line) {
44
57
return Some ( ConfigurationSection :: ConfigName ( String :: from ( & c[ 1 ] ) ) ) ;
45
- } else if let Some ( c) = static_regex ! ( r#"^#### `"?([^`]+?)"?`"# ) . captures ( & line) {
46
- // Configuration values, which will be passed to `from_str`
47
- //
48
- // - must be prefixed with `####`
49
- // - must be wrapped in backticks
50
- // - may by wrapped in double quotes (which will be stripped)
58
+ } else if let Some ( c) = CONFIG_VALUE_REGEX . captures ( & line) {
51
59
return Some ( ConfigurationSection :: ConfigValue ( String :: from ( & c[ 1 ] ) ) ) ;
52
60
}
53
61
}
0 commit comments