package com.foreverwin.mesnac.common.util;


import org.apache.commons.lang.StringUtils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;



public class RegUtils {
	public interface FindCallback {
		public String execute(String source);
	}

	public static String findAndReplace(String regEx, String targetStr,
			FindCallback callback) {
		Pattern p = Pattern.compile(regEx); // 正则表达式去匹配所有匹配的字符串
		Matcher m = p.matcher(targetStr);
		StringBuffer buf = new StringBuffer();
		while (m.find()) {
			String newStr = callback.execute(m.group());
			m.appendReplacement(buf, newStr);
		}
		m.appendTail(buf);
		return buf.toString();
	}
	public static String tranProperty(String source){
		 String reg = "\\_[a-zA-Z\\.0-9\\_\\-\\?\\*\\/\\(\\)]";
		source = StringUtils.lowerCase(source);
		source = RegUtils.findAndReplace(reg, source, new FindCallback(){

			@Override
			public String execute(String source) { 
				source = StringUtils.replace(source, "_", "");
				System.out.println(source);
				return StringUtils.upperCase(source);
			}});
		return source;
	}
}
