@@ -25,7 +25,7 @@ impl<'a> DesktopEntry<'a> {
25
25
pub fn from_str < L > (
26
26
path : & ' a Path ,
27
27
input : & ' a str ,
28
- locales : & [ L ] ,
28
+ locales_filter : Option < & [ L ] > ,
29
29
) -> Result < DesktopEntry < ' a > , DecodeError >
30
30
where
31
31
L : AsRef < str > ,
@@ -36,15 +36,15 @@ impl<'a> DesktopEntry<'a> {
36
36
let mut active_group = Cow :: Borrowed ( "" ) ;
37
37
let mut ubuntu_gettext_domain = None ;
38
38
39
- let locales = add_generic_locales ( locales ) ;
39
+ let locales_filter = locales_filter . map ( add_generic_locales ) ;
40
40
41
41
for line in input. lines ( ) {
42
42
process_line (
43
43
line,
44
44
& mut groups,
45
45
& mut active_group,
46
46
& mut ubuntu_gettext_domain,
47
- & locales ,
47
+ locales_filter . as_deref ( ) ,
48
48
Cow :: Borrowed ,
49
49
)
50
50
}
@@ -59,25 +59,25 @@ impl<'a> DesktopEntry<'a> {
59
59
60
60
pub fn from_paths < ' i , ' l : ' i , L > (
61
61
paths : impl Iterator < Item = PathBuf > + ' i ,
62
- locales : & ' l [ L ] ,
62
+ locales_filter : Option < & ' l [ L ] > ,
63
63
) -> impl Iterator < Item = Result < DesktopEntry < ' static > , DecodeError > > + ' i
64
64
where
65
65
L : AsRef < str > ,
66
66
{
67
67
let mut buf = String :: new ( ) ;
68
- let locales = add_generic_locales ( locales ) ;
68
+ let locales_filter = locales_filter . map ( add_generic_locales ) ;
69
69
70
- paths. map ( move |path| decode_from_path_with_buf ( path, & locales , & mut buf) )
70
+ paths. map ( move |path| decode_from_path_with_buf ( path, locales_filter . as_deref ( ) , & mut buf) )
71
71
}
72
72
73
73
/// Return an owned [`DesktopEntry`]
74
- pub fn from_path < L > ( path : PathBuf , locales : & [ L ] ) -> Result < DesktopEntry < ' static > , DecodeError >
74
+ pub fn from_path < L > ( path : PathBuf , locales_filter : Option < & [ L ] > ) -> Result < DesktopEntry < ' static > , DecodeError >
75
75
where
76
76
L : AsRef < str > ,
77
77
{
78
78
let mut buf = String :: new ( ) ;
79
- let locales = add_generic_locales ( locales ) ;
80
- decode_from_path_with_buf ( path, & locales , & mut buf)
79
+ let locales_filter = locales_filter . map ( add_generic_locales ) ;
80
+ decode_from_path_with_buf ( path, locales_filter . as_deref ( ) , & mut buf)
81
81
}
82
82
}
83
83
@@ -97,7 +97,7 @@ fn process_line<'buf, 'local_ref, 'res: 'local_ref + 'buf, F, L>(
97
97
groups : & ' local_ref mut Groups < ' res > ,
98
98
active_group : & ' local_ref mut Cow < ' res , str > ,
99
99
ubuntu_gettext_domain : & ' local_ref mut Option < Cow < ' res , str > > ,
100
- locales_filter : & [ L ] ,
100
+ locales_filter : Option < & [ L ] > ,
101
101
convert_to_cow : F ,
102
102
) where
103
103
F : Fn ( & ' buf str ) -> Cow < ' res , str > ,
@@ -124,8 +124,9 @@ fn process_line<'buf, 'local_ref, 'res: 'local_ref + 'buf, F, L>(
124
124
let key_name = & key[ ..start] ;
125
125
let locale = & key[ start + 1 ..key. len ( ) - 1 ] ;
126
126
127
- if !locales_filter. iter ( ) . any ( |l| l. as_ref ( ) == locale) {
128
- return ;
127
+ match locales_filter {
128
+ Some ( locales_filter) if !locales_filter. iter ( ) . any ( |l| l. as_ref ( ) == locale) => return ,
129
+ _ => ( ) ,
129
130
}
130
131
131
132
groups
@@ -157,7 +158,7 @@ fn process_line<'buf, 'local_ref, 'res: 'local_ref + 'buf, F, L>(
157
158
#[ inline]
158
159
fn decode_from_path_with_buf < L > (
159
160
path : PathBuf ,
160
- locales : & [ L ] ,
161
+ locales_filter : Option < & [ L ] > ,
161
162
buf : & mut String ,
162
163
) -> Result < DesktopEntry < ' static > , DecodeError >
163
164
where
@@ -179,7 +180,7 @@ where
179
180
& mut groups,
180
181
& mut active_group,
181
182
& mut ubuntu_gettext_domain,
182
- locales ,
183
+ locales_filter ,
183
184
|s| Cow :: Owned ( s. to_owned ( ) ) ,
184
185
) ;
185
186
buf. clear ( ) ;
0 commit comments