Skip to content

Commit d17e067

Browse files
committed
Make it work
1 parent 2e20b58 commit d17e067

File tree

2 files changed

+91
-76
lines changed

2 files changed

+91
-76
lines changed

UnicodeJsps/src/main/java/org/unicode/jsp/UnicodeJsp.java

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import java.io.IOException;
1414
import java.io.PrintWriter;
1515
import java.io.StringWriter;
16+
import java.util.ArrayList;
1617
import java.util.Arrays;
1718
import java.util.Collection;
1819
import java.util.List;
@@ -131,8 +132,15 @@ else if (choice.equals("Sentence"))
131132

132133
public static void showProperties(
133134
int cp, String history, boolean showDevProperties, Appendable out) throws IOException {
135+
List<String> originalParameters = new ArrayList<>();
136+
if (!history.isEmpty()) {
137+
originalParameters.add("history=" + history);
138+
}
139+
if (showDevProperties) {
140+
originalParameters.add("showDevProperties=1");
141+
}
134142
showDevProperties = Settings.latestVersionPhase == ReleasePhase.BETA || showDevProperties;
135-
UnicodeUtilities.showProperties(cp, history, showDevProperties, out);
143+
UnicodeUtilities.showProperties(cp, history, showDevProperties, originalParameters, out);
136144
}
137145

138146
static String defaultIdnaInput =
@@ -201,10 +209,18 @@ public static void showSet(
201209
boolean collate,
202210
Appendable out)
203211
throws IOException {
212+
List<String> originalParameters =
213+
showDevProperties ? List.of("showDevProperties=1") : List.of();
204214
showDevProperties = Settings.latestVersionPhase == ReleasePhase.BETA || showDevProperties;
205215
CodePointShower codePointShower =
206216
new CodePointShower(
207-
grouping, info, showDevProperties, abbreviate, ucdFormat, collate);
217+
grouping,
218+
info,
219+
showDevProperties,
220+
abbreviate,
221+
ucdFormat,
222+
collate,
223+
originalParameters);
208224
UnicodeUtilities.showSetMain(a, showDevProperties, codePointShower, out);
209225
}
210226

@@ -416,8 +432,10 @@ public static String testIdnaLines(String lines, String filter) {
416432
}
417433

418434
public static String getIdentifier(String script, boolean showDevProperties) {
435+
List<String> originalParameters =
436+
showDevProperties ? List.of("showDevProperties=1") : List.of();
419437
showDevProperties = Settings.latestVersionPhase == ReleasePhase.BETA || showDevProperties;
420-
return UnicodeUtilities.getIdentifier(script, showDevProperties);
438+
return UnicodeUtilities.getIdentifier(script, showDevProperties, originalParameters);
421439
}
422440

423441
static final String VERSIONS =

UnicodeJsps/src/main/java/org/unicode/jsp/UnicodeUtilities.java

Lines changed: 70 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
import java.util.regex.Matcher;
4141
import java.util.regex.Pattern;
4242
import java.util.stream.Collectors;
43+
import java.util.stream.IntStream;
44+
import java.util.stream.Stream;
4345
import org.unicode.cldr.tool.TablePrinter;
4446
import org.unicode.cldr.util.Predicate;
4547
import org.unicode.cldr.util.UnicodeSetPrettyPrinter;
@@ -90,7 +92,7 @@ public class UnicodeUtilities {
9092

9193
String CONTENT_RULES = "'>' > '&gt;' ;";
9294

93-
String HTML_RULES = BASE_RULES + CONTENT_RULES + "'\"' > '&quot;' ; '' > '&apos;'";
95+
String HTML_RULES = BASE_RULES + CONTENT_RULES + "'\"' > '&quot;' ; '' > '&apos;' ;";
9496

9597
toHTMLInput = Transliterator.createFromRules("any-xml", HTML_RULES, Transliterator.FORWARD);
9698

@@ -514,7 +516,8 @@ public static void showSet(
514516
}
515517
}
516518

517-
public static String getIdentifier(String script, boolean showDevProperties) {
519+
public static String getIdentifier(
520+
String script, boolean showDevProperties, List<String> originalParameters) {
518521
StringBuilder result = new StringBuilder();
519522
UnicodeProperty scriptProp = getFactory().getProperty("sc");
520523
UnicodeSet scriptSet;
@@ -560,7 +563,8 @@ public static String getIdentifier(String script, boolean showDevProperties) {
560563
showSet(
561564
allowed,
562565
showDevProperties,
563-
new CodePointShower("", "", showDevProperties, true, false, false),
566+
new CodePointShower(
567+
"", "", showDevProperties, true, false, false, originalParameters),
564568
result);
565569
}
566570

@@ -580,7 +584,14 @@ public static String getIdentifier(String script, boolean showDevProperties) {
580584
showSet(
581585
items,
582586
showDevProperties,
583-
new CodePointShower("", "", showDevProperties, true, false, false)
587+
new CodePointShower(
588+
"",
589+
"",
590+
showDevProperties,
591+
true,
592+
false,
593+
false,
594+
originalParameters)
584595
.setRestricted(true),
585596
result);
586597
}
@@ -628,6 +639,7 @@ static class CodePointShower {
628639
public final boolean collate;
629640
public final List<UnicodeProperty> groupingProps;
630641
public final List<UnicodeProperty> infoProps;
642+
public final List<String> originalParameters;
631643

632644
public boolean restricted;
633645

@@ -642,14 +654,16 @@ public CodePointShower(
642654
boolean showDevProperties,
643655
boolean abbreviate,
644656
boolean ucdFormat,
645-
boolean collate) {
657+
boolean collate,
658+
List<String> originalParameters) {
646659
this.groupingProps = getProps(grouping);
647660
this.infoProps = getProps(info);
648661
this.doTable = true; // !infoProps.isEmpty();
649662
this.showDevProperties = showDevProperties;
650663
this.abbreviate = abbreviate;
651664
this.ucdFormat = ucdFormat;
652665
this.collate = collate;
666+
this.originalParameters = originalParameters;
653667
}
654668

655669
void showCodePoint(int codePoint, Appendable out) throws IOException {
@@ -658,10 +672,6 @@ void showCodePoint(int codePoint, Appendable out) throws IOException {
658672
showString(string, separator, out);
659673
}
660674

661-
private List<String> args() {
662-
return showDevProperties ? List.of("showDevProperties=1") : List.of();
663-
}
664-
665675
private void showString(final String string, String separator, Appendable out)
666676
throws IOException {
667677
if (doTable) {
@@ -687,7 +697,8 @@ private void showString(final String string, String separator, Appendable out)
687697
+ literal
688698
+ "\u00A0</td>"
689699
+ "<td width='7m'>"
690-
+ UnicodeUtilities.getHex(string, separator, ucdFormat, args())
700+
+ UnicodeUtilities.getHex(
701+
string, separator, ucdFormat, originalParameters)
691702
+ "</td>"
692703
+ "<td"
693704
+ (restricted ? " class='redName'" : "")
@@ -696,7 +707,7 @@ private void showString(final String string, String separator, Appendable out)
696707
+ "</td>");
697708
} else if (ucdFormat) {
698709
out.append(
699-
UnicodeUtilities.getHex(string, separator, ucdFormat, args())
710+
UnicodeUtilities.getHex(string, separator, ucdFormat, originalParameters)
700711
+ " ;\t"
701712
+ name);
702713
} else {
@@ -706,7 +717,8 @@ private void showString(final String string, String separator, Appendable out)
706717
"\u00A0"
707718
+ literal
708719
+ "\u00A0\t"
709-
+ UnicodeUtilities.getHex(string, separator, ucdFormat, args())
720+
+ UnicodeUtilities.getHex(
721+
string, separator, ucdFormat, originalParameters)
710722
+ " \t"
711723
+ name);
712724
if (hasJoiner) {
@@ -781,7 +793,8 @@ private void showAbbreviated(UnicodeSet a, Appendable out) throws IOException {
781793
} else {
782794
if (codePointShower.ucdFormat) {
783795
out.append(
784-
UnicodeUtilities.getHex(s, codePointShower.ucdFormat, args()));
796+
UnicodeUtilities.getHex(
797+
s, codePointShower.ucdFormat, originalParameters));
785798
out.append("..");
786799
codePointShower.showCodePoint(end, out);
787800
} else {
@@ -1392,7 +1405,12 @@ private static String getScriptCat(String versionPrefix, int cp) {
13921405
}
13931406

13941407
public static void showProperties(
1395-
int cp, String history, boolean showDevProperties, Appendable out) throws IOException {
1408+
int cp,
1409+
String history,
1410+
boolean showDevProperties,
1411+
List<String> originalParameters,
1412+
Appendable out)
1413+
throws IOException {
13961414
String text = UTF16.valueOf(cp);
13971415

13981416
String name = getFactory().getProperty("Name").getValue(cp);
@@ -1516,26 +1534,23 @@ public static void showProperties(
15161534
cp,
15171535
minVersion,
15181536
maxVersion,
1519-
history,
1520-
showDevProperties,
1537+
originalParameters,
15211538
out);
15221539
showProperties(
15231540
nonUCDProperties.stream().map(UcdProperty::toString).collect(Collectors.toList()),
15241541
"Non-UCD properties for U+" + hex,
15251542
cp,
15261543
minVersion,
15271544
maxVersion,
1528-
history,
1529-
showDevProperties,
1545+
originalParameters,
15301546
out);
15311547
showProperties(
15321548
ucdNonProperties.stream().map(UcdProperty::toString).collect(Collectors.toList()),
15331549
"Other " + (isUnihan ? "non-Unihan " : "") + "UCD data for U+" + hex,
15341550
cp,
15351551
minVersion,
15361552
maxVersion,
1537-
history,
1538-
showDevProperties,
1553+
originalParameters,
15391554
out);
15401555
if (isUnihan) {
15411556
showProperties(
@@ -1544,8 +1559,7 @@ public static void showProperties(
15441559
cp,
15451560
minVersion,
15461561
maxVersion,
1547-
history,
1548-
showDevProperties,
1562+
originalParameters,
15491563
out);
15501564
}
15511565
showProperties(
@@ -1554,8 +1568,7 @@ public static void showProperties(
15541568
cp,
15551569
minVersion,
15561570
maxVersion,
1557-
history,
1558-
showDevProperties,
1571+
originalParameters,
15591572
out);
15601573
out.append("</table>\n");
15611574
}
@@ -1566,8 +1579,7 @@ private static void showProperties(
15661579
int cp,
15671580
VersionInfo minVersion,
15681581
VersionInfo maxVersion,
1569-
String historyParameter,
1570-
boolean showDevProperties,
1582+
List<String> originalParameters,
15711583
Appendable out)
15721584
throws IOException {
15731585
out.append("<tr><th colspan=2>" + title + "</th></tr>" + "<tr><td width='50%'>\n");
@@ -1577,13 +1589,7 @@ private static void showProperties(
15771589
if (prop.getName().equals("confusable")) continue;
15781590

15791591
showPropertyValue(
1580-
properties.get(i),
1581-
cp,
1582-
minVersion,
1583-
maxVersion,
1584-
historyParameter,
1585-
showDevProperties,
1586-
out);
1592+
properties.get(i), cp, minVersion, maxVersion, originalParameters, out);
15871593
}
15881594
out.append("</table>\n");
15891595

@@ -1595,13 +1601,7 @@ private static void showProperties(
15951601
if (prop.getName().equals("confusable")) continue;
15961602

15971603
showPropertyValue(
1598-
properties.get(i),
1599-
cp,
1600-
minVersion,
1601-
maxVersion,
1602-
historyParameter,
1603-
showDevProperties,
1604-
out);
1604+
properties.get(i), cp, minVersion, maxVersion, originalParameters, out);
16051605
}
16061606
out.append("</table>\n");
16071607
out.append("</td></tr>\n");
@@ -1732,8 +1732,7 @@ private static void showPropertyValue(
17321732
int codePoint,
17331733
VersionInfo minVersion,
17341734
VersionInfo maxVersion,
1735-
String historyParameter,
1736-
boolean showDevProperties,
1735+
List<String> originalParameters,
17371736
Appendable out)
17381737
throws IOException {
17391738
var indexedProperty = UcdProperty.forString(propName);
@@ -1855,24 +1854,6 @@ class PropertyAssignment {
18551854
htmlEscapedPropertyPredicate = "@none@";
18561855
}
18571856
}
1858-
List<String> displayedValues = htmlValues;
1859-
if (isStringValued) {
1860-
List<String> args = new ArrayList<>();
1861-
if (!historyParameter.isEmpty()) {
1862-
args.add("history=" + historyParameter);
1863-
}
1864-
if (showDevProperties) {
1865-
args.add("showDevProperties=1");
1866-
}
1867-
displayedValues = new ArrayList<>();
1868-
for (int i = 0; i < assignment.values.size(); ++i) {
1869-
displayedValues.add(
1870-
htmlValues.get(i)
1871-
+ " &lt;"
1872-
+ getHex(assignment.values.get(i), ", ", false, args)
1873-
+ "&gt;");
1874-
}
1875-
}
18761857
final String href =
18771858
htmlEscapedPropertyPredicate == null
18781859
? null
@@ -1882,26 +1863,42 @@ class PropertyAssignment {
18821863
+ "="
18831864
+ htmlEscapedPropertyPredicate
18841865
+ ":]";
1866+
final String aTag = href == null ? null : "<a target='u' href='" + href + "'>";
1867+
Stream<String> displayedValues = null;
1868+
if (assignment.values != null) {
1869+
if (isStringValued && assignment.values.get(0) != null) {
1870+
displayedValues =
1871+
IntStream.range(0, assignment.values.size())
1872+
.mapToObj(
1873+
i ->
1874+
(aTag == null ? "" : aTag)
1875+
+ htmlValues.get(i)
1876+
+ (aTag == null ? "" : "</a>")
1877+
+ "&nbsp;&lt;"
1878+
+ getHex(
1879+
assignment.values.get(i),
1880+
", ",
1881+
false,
1882+
originalParameters)
1883+
+ "&gt;");
1884+
} else {
1885+
displayedValues =
1886+
htmlValues.stream().map(x -> aTag == null ? x : aTag + x + "</a>");
1887+
}
1888+
}
18851889
out.append(
18861890
"<td "
18871891
+ tdClass
18881892
+ " colspan="
18891893
+ assignment.span
18901894
+ ">"
1891-
+ (assignment.values != null
1892-
? (href == null
1893-
? "<span"
1894-
+ (isNew ? " class='changed'" : "")
1895-
+ ">"
1896-
: ("<a target='u' "
1897-
+ (isNew ? "class='changed' " : "")
1898-
+ "href='"
1899-
+ href
1900-
+ "'>"))
1895+
+ (displayedValues != null
1896+
? (isNew ? "<span class='changed'>" : "")
19011897
+ versionRange
1902-
+ displayedValues.stream()
1903-
.collect(Collectors.joining("<wbr>|"))
1904-
+ (href == null ? "</span>" : "</a>")
1898+
+ (isStringValued && href != null ? "</a>" : "")
1899+
+ displayedValues.collect(
1900+
Collectors.joining("<wbr>|&#x2060;"))
1901+
+ (isNew ? "</span>" : "")
19051902
: "")
19061903
+ "</td>");
19071904
}

0 commit comments

Comments
 (0)