类org.apache.commons.lang.CharSet源码实例Demo

下面列出了怎么用org.apache.commons.lang.CharSet的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: rebuild   文件: Field2Schema.java
/**
 * 中文 -> 拼音(仅保留字母数字)
 * 全英文+数字直接返回,不支持的字符会使用随机数
 * 
 * @param text
 * @return
 */
protected String toPinyinName(final String text) {
	String identifier = text;
	if (text.length() < 4) {
		identifier = "rb" + text + RandomUtils.nextInt(10);
	}
	
	// 全英文直接返回
	if (identifier.matches("[a-zA-Z0-9]+")) {
		if (!CharSet.ASCII_ALPHA.contains(identifier.charAt(0))
				|| BlackList.isBlack(identifier) || BlackList.isSQLKeyword(identifier)) {
			identifier = "rb" + identifier;
		}
		return identifier;
	}
	
	identifier = HanLP.convertToPinyinString(identifier, "", false);
	identifier = identifier.replaceAll("[^a-zA-Z0-9]", "");
	if (StringUtils.isBlank(identifier)) {
		identifier = String.valueOf(System.currentTimeMillis() / 1000);
	}

	char start = identifier.charAt(0);
	if (!CharSet.ASCII_ALPHA.contains(start)) {
		identifier = "rb" + identifier;
	}
	
	identifier = identifier.toLowerCase();
	if (identifier.length() > 42) {
		identifier = identifier.substring(0, 42);
	}
	
	if (!StringHelper.isIdentifier(identifier)) {
		throw new ModifiyMetadataException("无效名称 : " + text);
	}
	return identifier;
}
 
 类所在包
 类方法
 同包方法