3
3
use std:: { borrow:: Cow , sync:: OnceLock } ;
4
4
5
5
use super :: Value ;
6
- use regex:: { Captures , Match , Regex , Replacer } ;
6
+ use regex:: { Captures , Regex , Replacer } ;
7
7
8
8
/// A regular expression replacer implementation for replacing formatted
9
9
/// values in a display macro string.
@@ -24,37 +24,31 @@ where
24
24
GetLocalizedFunc : Fn ( & str ) -> Option < Cow < ' a , str > > ,
25
25
{
26
26
fn replace_append ( & mut self , caps : & Captures < ' _ > , dst : & mut String ) {
27
- let default_replace = |dst : & mut String | dst. push_str ( caps. get ( 0 ) . unwrap ( ) . as_str ( ) ) ;
27
+ let mut default_replace = || dst. push_str ( caps. get ( 0 ) . unwrap ( ) . as_str ( ) ) ;
28
28
29
- let mut handle_value_capture = |cap_match : Match < ' _ > | {
29
+ // Replace $tag or ${tag}
30
+ if let Some ( cap_match) = caps. get ( 2 ) . or_else ( || caps. get ( 4 ) ) {
30
31
if let Some ( value) = ( self . get_value ) ( cap_match. as_str ( ) ) {
31
32
if let Value :: Ref ( val) = value {
32
33
dst. push_str ( val. dis . as_ref ( ) . unwrap_or ( & val. value ) ) ;
33
34
} else if let Value :: Str ( val) = value {
34
35
dst. push_str ( & val. value ) ;
35
36
} else {
36
- dst. push_str ( & value. to_string ( ) )
37
+ dst. push_str ( & value. to_string ( ) ) ;
37
38
}
38
39
} else {
39
- default_replace ( dst ) ;
40
+ default_replace ( ) ;
40
41
}
41
- } ;
42
-
43
- // Replace $tag
44
- if let Some ( cap_match) = caps. get ( 2 ) {
45
- handle_value_capture ( cap_match) ;
46
- // Replace ${tag}
47
- } else if let Some ( cap_match) = caps. get ( 4 ) {
48
- handle_value_capture ( cap_match) ;
42
+ }
49
43
// Replace $<pod::key>
50
- } else if let Some ( cap_match) = caps. get ( 6 ) {
44
+ else if let Some ( cap_match) = caps. get ( 6 ) {
51
45
if let Some ( value) = ( self . get_localized ) ( cap_match. as_str ( ) ) {
52
46
dst. push_str ( & value) ;
53
47
} else {
54
- default_replace ( dst ) ;
48
+ default_replace ( ) ;
55
49
}
56
50
} else {
57
- default_replace ( dst ) ;
51
+ default_replace ( ) ;
58
52
}
59
53
}
60
54
}
0 commit comments