Here you can find the source of sanitizePackageName(String raw)
Parameter | Description |
---|---|
raw | basic package name, which may include illegal characters |
public static String sanitizePackageName(String raw)
//package com.java2s; public class Main { /**//from www .j ava2 s . c om * Convert a raw package name to a legal Java package name. The raw package name must be in standard package name * form, with periods separating the individual directory components of the package name. * * @param raw basic package name, which may include illegal characters * @return sanitized package name */ public static String sanitizePackageName(String raw) { StringBuffer buff = new StringBuffer(raw.length()); boolean first = true; for (int i = 0; i < raw.length();) { char chr = buff.charAt(i); if (first) { if (Character.isJavaIdentifierStart(chr)) { first = false; i++; } else { buff.deleteCharAt(i); } } else if (chr == '.') { first = true; i++; } else if (!Character.isJavaIdentifierPart(chr)) { buff.deleteCharAt(i); } else { i++; } } return buff.toString(); } }