DocViewProperty { protected static void escape(StringBuffer buf, String value, boolean isMulti) { for (int i=0; i<value.length(); i++) { char c = value.charAt(i); if (c == '\\') { buf.append("\\\\"); } else if (c == ',' && isMulti) { buf.append("\\,"); } else if (i == 0 && !isMulti && (c == '[' || c == '{')) { buf.append('\\').append(c); } else if ( XMLChar.isInvalid(c)) { buf.append("\\u"); buf.append(Text.hexTable[(c >> 12) & 15]); buf.append(Text.hexTable[(c >> 8) & 15]); buf.append(Text.hexTable[(c >> 4) & 15]); buf.append(Text.hexTable[c & 15]); } else { buf.append(c); } } } DocViewProperty(String name, String[] values, boolean multi, int type);  DocViewProperty(String name, String[] values, boolean multi, int type, boolean isRef); static DocViewProperty parse(String name, String value); static String format(Property prop); static String format(Property prop, boolean sort, boolean useBinaryReferences); static boolean isAmbiguous(Property prop); boolean apply(Node node); @Override int hashCode(); @Override boolean equals(Object obj); @Override String toString(); final String name; final String[] values; final boolean isMulti; final int type; final boolean isReferenceProperty; }
@Test public void testEscape() { assertEscaped("hello", "hello", false); assertEscaped("hello, world", "hello, world", false); assertEscaped("hello, world", "hello\\, world", true); assertEscaped("[hello]", "\\[hello]", false); assertEscaped("[hello]", "[hello]", true); assertEscaped("{hello}", "\\{hello}", false); assertEscaped("{hello}", "{hello}", true); assertEscaped("hello\u000fworld", "hello\\u000fworld", false); assertEscaped("hello\u000fworld", "hello\\u000fworld", true); assertEscaped("hello\\world", "hello\\\\world", false); assertEscaped("hello\\world", "hello\\\\world", true); }