Skip to content

Commit

Permalink
CLDR-16520 Break lines between cells for diffability (#2819)
Browse files Browse the repository at this point in the history
  • Loading branch information
macchiati authored Mar 30, 2023
1 parent cf6c56b commit 2506ddc
Showing 1 changed file with 12 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

public class TablePrinter {

public static final String LS = System.lineSeparator();

public static void main(String[] args) {
// quick test;
TablePrinter tablePrinter = new TablePrinter()
Expand Down Expand Up @@ -350,7 +352,7 @@ private String tsvFormat(Comparable value) {
if (value instanceof Number) {
int debug = 0;
}
String s = value.toString().replace("\n", " • ");
String s = value.toString().replace(LS, " • ");
return BIDI.containsNone(s) ? s : RLE + s + PDF;
}

Expand All @@ -372,7 +374,7 @@ public String toTableInternal(Comparable[][] sortedFlat) {
if (tableAttributes != null) {
result.append(' ').append(tableAttributes);
}
result.append(">" + System.lineSeparator());
result.append(">" + LS);

if (caption != null) {
result.append("<caption>").append(caption).append("</caption>");
Expand Down Expand Up @@ -401,18 +403,18 @@ public String toTableInternal(Comparable[][] sortedFlat) {
}
}
if (divider) {
result.append("\t<tr><td class='divider' colspan='" + visibleWidth + "'></td></tr>");
result.append(" <tr><td class='divider' colspan='" + visibleWidth + "'></td></tr>" + LS);
}
}
result.append("\t<tr>");
result.append(" <tr>");
for (int j = 0; j < sortedFlat[i].length; ++j) {
int identical = findIdentical(sortedFlat, i, j);
if (identical == 0) continue;
if (columnsFlat[j].hidden) {
continue;
}
patternArgs[0] = sortedFlat[i][j];
result.append(columnsFlat[j].isHeader ? "<th" : "<td");
result.append(LS + "\t").append(columnsFlat[j].isHeader ? "<th" : "<td");
if (columnsFlat[j].cellAttributes != null) {
try {
result.append(' ').append(columnsFlat[j].cellAttributes.format(patternArgs));
Expand Down Expand Up @@ -440,7 +442,7 @@ public String toTableInternal(Comparable[][] sortedFlat) {
}
result.append(columnsFlat[j].isHeader ? "</th>" : "</td>");
}
result.append("</tr>" + System.lineSeparator());
result.append("</tr>" + LS);
}
result.append("</table>");
return result.toString();
Expand All @@ -455,24 +457,24 @@ private String format(Comparable comparable) {
if (comparable == null) {
return null;
}
String s = comparable.toString().replace("\n", "<br>");
String s = comparable.toString().replace(LS, "<br>");
return BIDI.containsNone(s) ? s : RLE + s + PDF;
}

private void showHeader(StringBuilder result) {
result.append("\t<tr>");
result.append(" <tr>");
for (int j = 0; j < columnsFlat.length; ++j) {
if (columnsFlat[j].hidden) {
continue;
}
result.append("<th");
result.append(LS + "\t<th");
if (columnsFlat[j].headerAttributes != null) {
result.append(' ').append(columnsFlat[j].headerAttributes);
}
result.append('>').append(columnsFlat[j].header).append("</th>");

}
result.append("</tr>" + System.lineSeparator());
result.append("</tr>" + LS);
}

/**
Expand Down

0 comments on commit 2506ddc

Please sign in to comment.