Skip to content

Commit 215422f

Browse files
committed
Multivalued IndexUnicodeProperties
1 parent 117cc5f commit 215422f

File tree

2 files changed

+31
-14
lines changed

2 files changed

+31
-14
lines changed

unicodetools/src/main/java/org/unicode/props/IndexUnicodeProperties.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
* @author markdavis
5858
*/
5959
public class IndexUnicodeProperties extends UnicodeProperty.Factory {
60-
static final String SET_SEPARATOR = "|";
60+
static final String SET_SEPARATOR = ",";
6161
/** Control file caching */
6262
static final boolean GZIP = true;
6363

@@ -678,6 +678,10 @@ class IndexUnicodeProperty extends UnicodeProperty.BaseProperty {
678678
stringToNamedEnum = ImmutableMap.copyOf(_stringToNamedEnum);
679679
enumValueNames = ImmutableSet.copyOf(_mainNames);
680680
}
681+
if (PropertyParsingInfo.property2PropertyInfo.get(item).getMultivalued()
682+
!= ValueCardinality.Singleton) {
683+
setMultivalued(true);
684+
}
681685
}
682686

683687
protected UnicodeMap<String> _getUnicodeMap() {

unicodetools/src/main/java/org/unicode/props/UnicodeProperty.java

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,17 @@ public final String getFirstNameAlias() {
332332

333333
public final String getFirstValueAlias(String value) {
334334
if (valueToFirstValueAlias == null) _getFirstValueAliasCache();
335+
if (isMultivalued) {
336+
List<String> result = new ArrayList<>();
337+
for (String part : value.split(",")) {
338+
String partAlias = valueToFirstValueAlias.get(part);
339+
if (partAlias == null) {
340+
throw new IllegalArgumentException(value + " is not a value alias for " + name);
341+
}
342+
result.add(partAlias);
343+
}
344+
return String.join(",", result);
345+
}
335346
String result = valueToFirstValueAlias.get(value);
336347
if (result == null) {
337348
throw new IllegalArgumentException(value + " is not a value alias for " + name);
@@ -423,26 +434,28 @@ public UnicodeSet getSet(PatternMatcher matcher, UnicodeSet result) {
423434
}
424435
return addUntested(result, uniformUnassigned);
425436
}
426-
List<String> temp = new ArrayList<>(1); // to avoid reallocating...
437+
List<String> valueAliases = new ArrayList<>(1); // to avoid reallocating...
438+
List<String> partAliases = new ArrayList<>(1);
427439
UnicodeMap<String> um = getUnicodeMap_internal();
428440
Iterator<String> it = um.getAvailableValues(null).iterator();
429441
main:
430442
while (it.hasNext()) {
431443
String value = it.next();
432-
temp.clear();
433-
final List<String> valueAliases = getValueAliases(value, temp);
434-
Iterator<String> it2 = valueAliases.iterator();
435-
while (it2.hasNext()) {
436-
String value2 = it2.next();
437-
// System.out.println("Values:" + value2);
438-
if (isMultivalued && value2.contains(",")) {
439-
for (String part : SPLIT_COMMAS.split(value2)) {
440-
if (matcher.test(part) || matcher.test(toSkeleton(part))) {
441-
um.keySet(value, result);
442-
continue main;
444+
valueAliases.clear();
445+
getValueAliases(value, valueAliases);
446+
for (String valueAlias : valueAliases) {
447+
if (isMultivalued && valueAlias.contains(",")) {
448+
for (String part : SPLIT_COMMAS.split(valueAlias)) {
449+
partAliases.clear();
450+
getValueAliases(part, partAliases);
451+
for (String partAlias : partAliases) {
452+
if (matcher.test(partAlias) || matcher.test(toSkeleton(partAlias))) {
453+
um.keySet(value, result);
454+
continue main;
455+
}
443456
}
444457
}
445-
} else if (matcher.test(value2) || matcher.test(toSkeleton(value2))) {
458+
} else if (matcher.test(valueAlias) || matcher.test(toSkeleton(valueAlias))) {
446459
um.keySet(value, result);
447460
continue main;
448461
}

0 commit comments

Comments
 (0)