Skip to content

Commit 7518243

Browse files
authored
CLDR-18952 Improve CLDRModify for modify_config 2 (#5026)
1 parent af3db11 commit 7518243

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

tools/cldr-code/src/main/java/org/unicode/cldr/tool/CLDRModify.java

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
import org.unicode.cldr.util.Factory;
6565
import org.unicode.cldr.util.FileProcessor;
6666
import org.unicode.cldr.util.GlossonymConstructor;
67+
import org.unicode.cldr.util.Joiners;
6768
import org.unicode.cldr.util.LanguageTagParser;
6869
import org.unicode.cldr.util.Level;
6970
import org.unicode.cldr.util.LocaleIDParser;
@@ -131,6 +132,8 @@ static final class ConfigMatch {
131132
final ConfigAction action;
132133
final boolean hexPath;
133134

135+
static UnicodeSet SUSPICIOUS_NON_REGEX = new UnicodeSet("[*|]").freeze();
136+
134137
public ConfigMatch(ConfigKeys key, String match) {
135138
if (key == ConfigKeys.action) {
136139
exactMatch = null;
@@ -139,7 +142,8 @@ public ConfigMatch(ConfigKeys key, String match) {
139142
hexPath = false;
140143
} else if (match.startsWith("/") && match.endsWith("/")) {
141144
if (key != ConfigKeys.locale && key != ConfigKeys.path && key != ConfigKeys.value) {
142-
throw new IllegalArgumentException("Regex only allowed for old path/value.");
145+
throw new IllegalArgumentException(
146+
"Regex only allowed for locale=, path=, or value'.");
143147
}
144148
exactMatch = null;
145149
regexMatch =
@@ -156,6 +160,17 @@ public ConfigMatch(ConfigKeys key, String match) {
156160
hexPath =
157161
(key == ConfigKeys.new_path || key == ConfigKeys.path)
158162
&& HEX.containsAll(match);
163+
if (key == ConfigKeys.locale || key == ConfigKeys.path) {
164+
if (SUSPICIOUS_NON_REGEX.containsSome(match)) {
165+
System.out.println(
166+
Joiners.ES.join(
167+
"The value ",
168+
match,
169+
" is being matched literally, but contains regex charcters. Did you mean /",
170+
match,
171+
"/ ?"));
172+
}
173+
}
159174
}
160175
}
161176

@@ -2366,7 +2381,8 @@ public void handleStart() {
23662381
keyValues.addAll(localeMatcher.getValue());
23672382
}
23682383
}
2369-
System.out.println("# Checking entries & changing:\t" + keyValues.size());
2384+
// System.out.println("# Checking entries & changing:\t" +
2385+
// keyValues.size());
23702386
for (Map<ConfigKeys, ConfigMatch> entry : keyValues) {
23712387
ConfigMatch action = entry.get(ConfigKeys.action);
23722388
ConfigMatch pathMatch = entry.get(ConfigKeys.path);
@@ -2479,9 +2495,12 @@ protected boolean handleLine(int lineCount, String line) {
24792495
myReader.process(CLDRModify.class, configFileName);
24802496
}
24812497

2482-
static final String DEBUG_PATH =
2483-
"//ldml/personNames/personName[@order=\"givenFirst\"][@length=\"long\"][@usage=\"referring\"][@formality=\"formal\"]/namePattern";
2498+
final String DEBUG_PATH = null;
2499+
2500+
// example:
2501+
// "//ldml/personNames/personName[@order=\"givenFirst\"][@length=\"long\"][@usage=\"referring\"][@formality=\"formal\"]/namePattern";
24842502

2503+
@SuppressWarnings("incomplete-switch")
24852504
@Override
24862505
public void handlePath(String xpath) {
24872506
// slow method; could optimize

0 commit comments

Comments
 (0)