@Test public void testFormatStringLiteral() { Assert.assertEquals("'|'", StringLiteral.formatStringLiteral("\u007C")); Assert.assertEquals("U&'\\0000\\FFFF'", StringLiteral.formatStringLiteral("\u0000\uffff")); }
static String formatStringLiteral(String s) { s = s.replace("'", "''"); if (charMatches((char) 0x20, (char) 0x7E, s)) { return "'" + s + "'"; } StringBuilder builder = new StringBuilder(); builder.append("U&'"); PrimitiveIterator.OfInt iterator = s.codePoints().iterator(); while (iterator.hasNext()) { int codePoint = iterator.nextInt(); checkArgument(codePoint >= 0, "Invalid UTF-8 encoding in characters: %s", s); if (isAsciiPrintable(codePoint)) { char ch = (char) codePoint; if (ch == '\\') { builder.append(ch); } builder.append(ch); } else if (codePoint <= 0xFFFF) { builder.append('\\'); builder.append(String.format("%04X", codePoint)); } else { builder.append("\\+"); builder.append(String.format("%06X", codePoint)); } } builder.append("'"); return builder.toString(); }
StringLiteral extends Literal { static String formatStringLiteral(String s) { s = s.replace("'", "''"); if (charMatches((char) 0x20, (char) 0x7E, s)) { return "'" + s + "'"; } StringBuilder builder = new StringBuilder(); builder.append("U&'"); PrimitiveIterator.OfInt iterator = s.codePoints().iterator(); while (iterator.hasNext()) { int codePoint = iterator.nextInt(); checkArgument(codePoint >= 0, "Invalid UTF-8 encoding in characters: %s", s); if (isAsciiPrintable(codePoint)) { char ch = (char) codePoint; if (ch == '\\') { builder.append(ch); } builder.append(ch); } else if (codePoint <= 0xFFFF) { builder.append('\\'); builder.append(String.format("%04X", codePoint)); } else { builder.append("\\+"); builder.append(String.format("%06X", codePoint)); } } builder.append("'"); return builder.toString(); } }
StringLiteral extends Literal { static String formatStringLiteral(String s) { s = s.replace("'", "''"); if (charMatches((char) 0x20, (char) 0x7E, s)) { return "'" + s + "'"; } StringBuilder builder = new StringBuilder(); builder.append("U&'"); PrimitiveIterator.OfInt iterator = s.codePoints().iterator(); while (iterator.hasNext()) { int codePoint = iterator.nextInt(); checkArgument(codePoint >= 0, "Invalid UTF-8 encoding in characters: %s", s); if (isAsciiPrintable(codePoint)) { char ch = (char) codePoint; if (ch == '\\') { builder.append(ch); } builder.append(ch); } else if (codePoint <= 0xFFFF) { builder.append('\\'); builder.append(String.format("%04X", codePoint)); } else { builder.append("\\+"); builder.append(String.format("%06X", codePoint)); } } builder.append("'"); return builder.toString(); } StringLiteral(NodeLocation location, String value); private  StringLiteral(Optional<NodeLocation> location, String value); }
StringLiteral extends Literal { static String formatStringLiteral(String s) { s = s.replace("'", "''"); if (charMatches((char) 0x20, (char) 0x7E, s)) { return "'" + s + "'"; } StringBuilder builder = new StringBuilder(); builder.append("U&'"); PrimitiveIterator.OfInt iterator = s.codePoints().iterator(); while (iterator.hasNext()) { int codePoint = iterator.nextInt(); checkArgument(codePoint >= 0, "Invalid UTF-8 encoding in characters: %s", s); if (isAsciiPrintable(codePoint)) { char ch = (char) codePoint; if (ch == '\\') { builder.append(ch); } builder.append(ch); } else if (codePoint <= 0xFFFF) { builder.append('\\'); builder.append(String.format("%04X", codePoint)); } else { builder.append("\\+"); builder.append(String.format("%06X", codePoint)); } } builder.append("'"); return builder.toString(); } StringLiteral(NodeLocation location, String value); private  StringLiteral(Optional<NodeLocation> location, String value); String getValue(); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); }
StringLiteral extends Literal { static String formatStringLiteral(String s) { s = s.replace("'", "''"); if (charMatches((char) 0x20, (char) 0x7E, s)) { return "'" + s + "'"; } StringBuilder builder = new StringBuilder(); builder.append("U&'"); PrimitiveIterator.OfInt iterator = s.codePoints().iterator(); while (iterator.hasNext()) { int codePoint = iterator.nextInt(); checkArgument(codePoint >= 0, "Invalid UTF-8 encoding in characters: %s", s); if (isAsciiPrintable(codePoint)) { char ch = (char) codePoint; if (ch == '\\') { builder.append(ch); } builder.append(ch); } else if (codePoint <= 0xFFFF) { builder.append('\\'); builder.append(String.format("%04X", codePoint)); } else { builder.append("\\+"); builder.append(String.format("%06X", codePoint)); } } builder.append("'"); return builder.toString(); } StringLiteral(NodeLocation location, String value); private  StringLiteral(Optional<NodeLocation> location, String value); String getValue(); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString();  }