Skip to content

Commit 09bc171

Browse files
committed
icu4x-datagen: implement ability to invert regex
1 parent 8da5bcb commit 09bc171

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

provider/icu4x-datagen/src/main.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ use std::str::FromStr;
4646
struct Filter {
4747
domain: String,
4848
regex: Regex,
49+
inverted: bool,
4950
}
5051

5152
#[derive(Debug)]
@@ -80,6 +81,11 @@ impl FromStr for Filter {
8081
fn from_str(s: &str) -> Result<Self, Self::Err> {
8182
let (domain, regex) = s.split_once('=').ok_or(FilterError::NoFilter)?;
8283

84+
let (regex, inverted) = regex
85+
.strip_prefix('-')
86+
.map(|regex| (regex, true))
87+
.unwrap_or((regex, false));
88+
8389
let regex = regex.strip_prefix('/').ok_or(FilterError::NoOpeningSlash)?;
8490
let regex = regex.strip_suffix('/').ok_or(FilterError::NoClosingSlash)?;
8591

@@ -90,6 +96,7 @@ impl FromStr for Filter {
9096
Ok(Filter {
9197
domain: domain.to_owned(),
9298
regex,
99+
inverted,
93100
})
94101
}
95102
}
@@ -589,8 +596,10 @@ fn main() -> eyre::Result<()> {
589596

590597
for filter in &cli.attribute_filter {
591598
let regex = filter.regex.clone();
592-
driver =
593-
driver.with_marker_attributes_filter(&filter.domain, move |attr| regex.is_match(attr))
599+
let inverted = filter.inverted;
600+
driver = driver.with_marker_attributes_filter(&filter.domain, move |attr| {
601+
regex.is_match(attr) ^ inverted
602+
})
594603
}
595604

596605
let metadata: Result<ExportMetadata, DataError> = match cli.format {

0 commit comments

Comments
 (0)