in scripts/src/main/java/com/gu/typesafe/config/impl/ConfigImplUtil.java [78:102]
static String renderStringUnquotedIfPossible(String s) {
// this can quote unnecessarily as long as it never fails to quote when
// necessary
if (s.length() == 0)
return renderJsonString(s);
// if it starts with a hyphen or number, we have to quote
// to ensure we end up with a string and not a number
int first = s.codePointAt(0);
if (Character.isDigit(first) || first == '-')
return renderJsonString(s);
if (s.startsWith("include") || s.startsWith("true") || s.startsWith("false")
|| s.startsWith("null") || s.contains("//"))
return renderJsonString(s);
// only unquote if it's pure alphanumeric
for (int i = 0; i < s.length(); ++i) {
char c = s.charAt(i);
if (!(Character.isLetter(c) || Character.isDigit(c) || c == '-'))
return renderJsonString(s);
}
return s;
}