/** as {@link #unwrapJavaString(String)} if the given string is wrapped in double quotes; * otherwise just returns the given string */ public static String unwrapJavaStringIfWrapped(String s) { if (!StringEscapes.isWrappedInDoubleQuotes(s)) return s; return unwrapJavaString(s); }
/** if s is wrapped in single or double quotes containing no unescaped quotes of that type */ public static boolean isWrappedInMatchingQuotes(String s) { return isWrappedInDoubleQuotes(s) || isWrappedInSingleQuotes(s); }
/** as {@link #unwrapJsonishListIfPossible(String)} but throwing errors * if something which looks like a string or set of brackets is not well-formed * (this does the work for that method) * @throws IllegalArgumentException if looks to have quoted list or surrounding brackets but they are not syntactically valid */ public static List<String> unwrapOptionallyQuotedJavaStringList(String input) { if (input==null) return null; MutableList<String> result = MutableList.of(); String i1 = input.trim(); boolean inBrackets = (i1.startsWith("[") && i1.endsWith("]")); if (inBrackets) i1 = i1.substring(1, i1.length()-1).trim(); QuotedStringTokenizer qst = new QuotedStringTokenizer(i1, "\"", true, ",", false); while (qst.hasMoreTokens()) { String t = qst.nextToken().trim(); if (isWrappedInDoubleQuotes(t)) result.add(unwrapJavaString(t)); else { if (inBrackets && (t.indexOf('[')>=0 || t.indexOf(']')>=0)) throw new IllegalArgumentException("Literal square brackets must be quoted, in element '"+t+"'"); result.add(t.trim()); } } return result; } }