Simplified code to use StringBuilder method chaining.

pull/134/head
Project Nayuki 6 years ago
parent b3fc497299
commit e2050c3e03

@ -209,14 +209,13 @@ public final class QrCode {
if (size + border * 2L > Integer.MAX_VALUE) if (size + border * 2L > Integer.MAX_VALUE)
throw new IllegalArgumentException("Border too large"); throw new IllegalArgumentException("Border too large");
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder()
sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); .append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")
sb.append("<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n"); .append("<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n")
sb.append(String.format( .append(String.format("<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" viewBox=\"0 0 %1$d %1$d\" stroke=\"none\">\n",
"<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" viewBox=\"0 0 %1$d %1$d\" stroke=\"none\">\n", size + border * 2))
size + border * 2)); .append("\t<rect width=\"100%\" height=\"100%\" fill=\"#FFFFFF\"/>\n")
sb.append("\t<rect width=\"100%\" height=\"100%\" fill=\"#FFFFFF\"/>\n"); .append("\t<path d=\"");
sb.append("\t<path d=\"");
boolean head = true; boolean head = true;
for (int y = 0; y < size; y++) { for (int y = 0; y < size; y++) {
for (int x = 0; x < size; x++) { for (int x = 0; x < size; x++) {
@ -229,9 +228,10 @@ public final class QrCode {
} }
} }
} }
sb.append("\" fill=\"#000000\"/>\n"); return sb
sb.append("</svg>\n"); .append("\" fill=\"#000000\"/>\n")
return sb.toString(); .append("</svg>\n")
.toString();
} }

Loading…
Cancel
Save