ICU-20764 Allow top-level include and exclude in data filter rules.

This commit is contained in:
Shane Carr 2019-08-13 00:51:26 -07:00 committed by Shane F. Carr
parent 035eead0e8
commit d983221543
7 changed files with 29 additions and 9 deletions

View file

@ -222,7 +222,7 @@ There are two concrete differences between additive and subtractive mode:
| | Additive | Subtractive |
|-------------------------|-------------|-------------|
| Default Feature Filter | `"exclude"` | `"include"` |
| Default Resource Filter | `"-/*"` | `"+/*"` |
| Default Resource Filter | `"-/"` | `"+/"` |
To enable additive mode, add the following setting to your filter file:

View file

@ -319,9 +319,9 @@ class ResourceFilterInfo(object):
)
]
if self.strategy == "additive":
self.rules_by_file = [["-/*"] for _ in range(len(files))]
self.rules_by_file = [["-/"] for _ in range(len(files))]
else:
self.rules_by_file = [["+/*"] for _ in range(len(files))]
self.rules_by_file = [["+/"] for _ in range(len(files))]
def add_rules(self, file_filter, rules):
for file, rule_list in zip(self.input_files, self.rules_by_file):

View file

@ -38,7 +38,7 @@
"type": "array",
"items": {
"type": "string",
"pattern": "^[+-]/[\\S]+$"
"pattern": "^[+-]/[\\S]*$"
}
}
},

View file

@ -1270,13 +1270,11 @@ void NewResourceBundleTest::TestFilter() {
assertEquals("fornia", fornia.getType(), URES_TABLE);
{
// Filter: hawaii should not be included based on parent inheritance
ResourceBundle hawaii = fornia.get("hawaii", status);
REQUIRE_SUCCESS(status);
assertEquals("hawaii", hawaii.getType(), URES_STRING);
assertEquals("hawaii", u"idaho", hawaii.getString(status));
REQUIRE_SUCCESS(status);
REQUIRE_ERROR(U_MISSING_RESOURCE_ERROR, status);
// Filter: illinois should not be included
// Filter: illinois should not be included based on direct rule
ResourceBundle illinois = fornia.get("illinois", status);
REQUIRE_ERROR(U_MISSING_RESOURCE_ERROR, status);
}
@ -1350,6 +1348,20 @@ void NewResourceBundleTest::TestFilter() {
REQUIRE_ERROR(U_MISSING_RESOURCE_ERROR, status);
}
}
// Filter: northCarolina should be included based on direct rule,
// and so should its child, northDakota
ResourceBundle northCarolina = rb.get("northCarolina", status);
REQUIRE_SUCCESS(status);
assertEquals("northCarolina", northCarolina.getType(), URES_TABLE);
{
ResourceBundle northDakota = northCarolina.get("northDakota", status);
REQUIRE_SUCCESS(status);
assertEquals("northDakota", northDakota.getType(), URES_STRING);
assertEquals("northDakota", u"west-virginia", northDakota.getString(status));
REQUIRE_SUCCESS(status);
}
}
#if U_ENABLE_TRACING

View file

@ -1,6 +1,7 @@
# Copyright (C) 2018 and later: Unicode, Inc. and others.
# License & terms of use: http://www.unicode.org/copyright.html
-/
-/alabama
+/alabama/alaska/arizona
-/fornia/illinois
@ -9,3 +10,4 @@
+/mississippi/*/maine
-/mississippi/*/iowa
+/mississippi/louisiana/iowa
+/northCarolina

View file

@ -34,4 +34,7 @@ filtertest {
missouri {"new-york"}
}
}
northCarolina {
northDakota {"west-virginia"}
}
}

View file

@ -23,6 +23,9 @@ ResKeyPath::ResKeyPath(const std::string& path, UErrorCode& status) {
status = U_PARSE_ERROR;
return;
}
if (path.length() == 1) {
return;
}
size_t i;
size_t j = 0;
while (true) {