QuoteUtil { public static void quoteIfNeeded(StringBuilder buf, String str, String delim) { if (str == null) { return; } int len = str.length(); if (len == 0) { return; } int ch; for (int i = 0; i < len; i++) { ch = str.codePointAt(i); if (delim.indexOf(ch) >= 0) { quote(buf, str); return; } } buf.append(str); }  static String dequote(String str); static void escape(StringBuilder buf, String str); static void quote(StringBuilder buf, String str); static void quoteIfNeeded(StringBuilder buf, String str, String delim); static Iterator<String> splitAt(String str, String delims); static String unescape(String str); static String join(Object[] objs, String delim); static String join(Collection<?> objs, String delim); static final String ABNF_REQUIRED_QUOTING; }
@Test public void testQuoteIfNeeded() { StringBuilder buf = new StringBuilder(); QuoteUtil.quoteIfNeeded(buf, "key", ","); assertEquals("key", buf.toString()); }
@Test public void testQuoteIfNeedednull() { StringBuilder buf = new StringBuilder(); QuoteUtil.quoteIfNeeded(buf, null, ";="); assertEquals("", buf.toString()); }