public static String safeName(String str) {
if (StringUtils.isNullOrEmpty(str)) {
throw new IllegalArgumentException("Cannot create safe name from empty/null string: " + str);
}
CharIterator ci = new CharIterator(str);
while (ci.hasNext()) {
ci.next();
if (!ci.isLetter() && !ci.isDigit()) {
// replaces unexpected chars with underscore
ci.set('_');
}
}
str = ci.toString();
if (!Character.isLetter(str.charAt(0))) {
str = "db" + str;
}
return str;
}