判断读取的字串时U码还是Z码

package com.huawei.g11n.check;

public class TestUOrZ {
	private static String judgeStringCodeTypeByChar(String strValue){
					String codeType = "";
					//判断字串的编码
					if(null != strValue && !"".equals(strValue)){
						for(int j = 0; j < strValue.length(); j++){
							String temp = strValue.charAt(j)+"";
							codeType=codeType+checkForMayamarByChar(temp.getBytes(), temp.getBytes().length);
						}
					}
					return codeType;
	}
	/**
	 * @param data:表示某个字符的字节数组
	 * @param len:表示字节数组的长度
	 * @return
	 */
	private static String checkForMayamarByChar(byte[] data, int len){
		 String codeType = "";
		 int first,second,third,unicode;
	     int unicodecount = 0;
	     if(len < 3){
	    	 return codeType;
	     }
	     for(int i = 0; i<len - 2;i++){
	        first = (int)(data[i]);
	        second = (int)(data[i+1]);
	        third = (int)(data[i+2]);
	        unicode =  ((first&0x000f)<<12) | ((second&0x003f)<<6) | (third&0x003f);
	        if((data[i] & 0xF0) != 0xE0){
	        	continue;
	        } 
	        if( unicode > 0x104F && unicode < 0x109f ){
	        	codeType="Z";
	            break;
	        } else if( unicode == 0x1022 || unicode == 0x1028 || unicode == 0x1035 || unicode == 0x103e || unicode == 0x103f) {
	        	codeType="U";
	            break;
	        } else if( unicode > 0x1000 && unicode < 0x1050 ){
	            unicodecount++;
	            if(unicodecount>200){
	            	codeType="U";
	                break;
	            }
	        }
	     }
	    return codeType;
	}
}

调用judgeStringCodeTypeByChar方法即可

猜你喜欢

转载自blog.csdn.net/weixin_41796956/article/details/82979071