Skip to content

Commit ca0139e

Browse files
committed
After Markus’s review
1 parent bd66b45 commit ca0139e

File tree

2 files changed

+37
-14
lines changed

2 files changed

+37
-14
lines changed

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

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,14 @@ enum SpecialProperty {
4949
public final UcdProperty property;
5050
public final SpecialProperty special;
5151

52+
/**
53+
* Represents a mapping from one field of a UCD file to another. For instance, given the data
54+
* line ABCD ; Value ; 1234 FieldMapping(1) maps U+ABCD to Value, FieldMapping(2) maps U+ABCD to
55+
* 1234 (which may be interpreted as U+1234) depending on the property type, and FieldMapping(2,
56+
* 1) maps U+1234 to Value.
57+
*/
5258
public static class FieldMapping implements Comparable<FieldMapping> {
59+
/** A mapping from field 0 to field `valueField`. This is the most common case. */
5360
FieldMapping(int valueField) {
5461
this(0, valueField);
5562
}
@@ -61,15 +68,20 @@ public static class FieldMapping implements Comparable<FieldMapping> {
6168

6269
@Override
6370
public int compareTo(FieldMapping other) {
64-
return Comparator.<FieldMapping>comparingInt(m -> m.keyField)
65-
.thenComparing(m -> m.valueField)
66-
.compare(this, other);
71+
return comparator.compare(this, other);
72+
}
73+
74+
@Override
75+
public String toString() {
76+
return keyField + " ↦ " + valueField;
6777
}
6878

6979
final int keyField;
7080
final int valueField;
81+
static final Comparator<FieldMapping> comparator =
82+
Comparator.<FieldMapping>comparingInt(m -> m.keyField)
83+
.thenComparing(m -> m.valueField);
7184
}
72-
;
7385

7486
/**
7587
* Maps from Unicode versions to field mapping. A property whose field mapping depends on the
@@ -696,14 +708,12 @@ static void parseSourceFile(
696708
propInfoSet);
697709
break;
698710
case Field:
711+
final var mapping = propInfo.getFieldMapping(indexUnicodeProperties.ucdVersion);
699712
if (propInfoSet.size() == 1
700713
&& (propInfo = propInfoSet.iterator().next()).special
701714
== SpecialProperty.None
702-
&& propInfo.getFieldMapping(indexUnicodeProperties.ucdVersion).keyField
703-
== 0
704-
&& propInfo.getFieldMapping(indexUnicodeProperties.ucdVersion)
705-
.valueField
706-
== 1) {
715+
&& mapping.keyField == 0
716+
&& mapping.valueField == 1) {
707717
if (fileName.equals("math/*/MathClass")
708718
&& indexUnicodeProperties.ucdVersion.compareTo(
709719
VersionInfo.UNICODE_6_3)

unicodetools/src/main/resources/org/unicode/props/IndexUnicodeProperties.txt

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ FileType ; SealSources ; PropertyValue
4545

4646
FileType ; NameAliases ; NameAliases
4747
FileType ; NameAliasesProv ; NameAliases
48+
# TODO(egg): These probably want to be somehow associated with their base character.
4849
FileType ; StandardizedVariants ; StandardizedVariants
4950
FileType ; emoji-variation-sequences ; StandardizedVariants
5051

@@ -58,6 +59,8 @@ FileType ; CJKRadicals ; CJKRadicals
5859
# NamedSequences File Type
5960
# The code point is not in field 0, but instead in field 1.
6061
# The value is in field 0
62+
# TODO(egg): This could be handled with a field mapping 1 ↦ 0 instead of a
63+
# dedicated file type.
6164

6265
FileType ; NamedSequences ; NamedSequences
6366
FileType ; NamedSequencesProv ; NamedSequences
@@ -70,11 +73,21 @@ FileType ; NamesList ; NamesList
7073
# =======================================
7174

7275
# Files where particular properties can be found, and in which field
73-
# The format is:
74-
# Field0 : file name
75-
# Field1 : property name
76-
# Field2 : field number in file (default is 1)
77-
# Field3 : special handling
76+
# The format of these property location lines is:
77+
# <file name without extension>
78+
# ; <property alias>
79+
# [ ; <field mapping> [ ; <special handling> ] ]
80+
# [ ; <version> ]
81+
# Where <field mapping> is <key field index> ↦ <value field index>
82+
# or <value field index> (with the key field being field 0 by default).
83+
# If the <field mapping> is omitted, it is 0 ↦ 1 by default.
84+
# No <field mapping> is given for files whose type determine the field mapping,
85+
# such as PropertyValue: in a PropertyValue file, the key is always
86+
# field 0, the value field 2, and field 1 determines the property.
87+
# <version> has the form v<n>[.<n>.[.<n>]]; it determines the latest applicable
88+
# version for a past location of the property. If it is omitted, the location
89+
# is still current.
90+
# The <special handling> is only used for SpecialCasing:
7891
# Skip1FT : Skip line if field 1 is F or T
7992
# Skip1ST : Skip line if field 1 is S or T
8093
# SkipAny4 : Skip line if field 4 is not empty

0 commit comments

Comments
 (0)