Here you can find the source of convertToJavaClassname(final String classname, final Map
public static String convertToJavaClassname(final String classname, final Map<Character, String> replacement)
//package com.java2s; //License from project: Open Source License import java.text.CharacterIterator; import java.text.StringCharacterIterator; import java.util.Map; public class Main { public static String convertToJavaClassname(final String classname, final Map<Character, String> replacement) { if (classname == null) { return null; }// www . ja v a 2 s. c o m final StringBuilder sb = new StringBuilder(); final CharacterIterator iter = new StringCharacterIterator(classname); char c = iter.first(); if (c == CharacterIterator.DONE) { return null; } if (!Character.isJavaIdentifierStart(c) && !Character.isIdentifierIgnorable(c)) { String repl = replacement.get(c); if (repl == null) { repl = "_"; System.err.println("no replacement for illegal character found: " + c); } sb.append(repl); } else { sb.append(c); } c = iter.next(); while (c != CharacterIterator.DONE) { if (!Character.isJavaIdentifierPart(c) && !Character.isIdentifierIgnorable(c)) { String repl = replacement.get(c); if (repl == null) { repl = "_"; System.err.println("no replacement for illegal character found: " + c); } sb.append(repl); } else { sb.append(c); } c = iter.next(); } return sb.toString(); } }