//.. 字符串转换 
import string.conv.table
namespace string.conv

GetSystemDefaultLCID := ::Kernel32.api("GetSystemDefaultLCID","int()")
LCMapString = ::Kernel32.api("LCMapStringA","int(int Locale,INT mapFlags int,str srcStr,int cchSrc,str &destStr,int cchDest)") 
mapString = function(str,locale,flags){
	var len = LCMapString( locale,flags, str, #str, 0,0) 
	if(len){
		var len,str = LCMapString( locale,flags, str, #str, len+1,len+1) 
		return str;
	}
} 
  
var rep = ..string.replace
traditionalized = function(str,local,lcid=0x804){
	if( local ){
		for(k,v in table.cn2tw ){ 
			str = rep(str,k,v); 
		}
	}
	return mapString(  str ,lcid, 0x4000000/*_LCMAP_TRADITIONAL_CHINESE*/ ); 
}

simplized = function(str,local,lcid=0x804){
	str = mapString(  str ,lcid, 0x2000000/*_LCMAP_SIMPLIFIED_CHINESE*/);
	if( local ){
		for(k,v in table.cn2tw ){ 
			str = rep(str,v,k);
		}
	}
	return str;
} 

gbkToBig5 = function(str){ 
	str = traditionalized(str,true);
	return ..string.fromto(str,936,950); 
}

big5ToGbk = function(str){
	str = ..string.fromto(str,950,936) 
	return simplized(str,true); 
}

var defaultLCID = GetSystemDefaultLCID();

upper = function(str){
	return  mapString(  str ,defaultLCID, 0x200/*_LCMAP_UPPERCASE*/);	
}

lower = function(str){
	return  mapString(  str ,defaultLCID, 0x100/*_LCMAP_LOWERCASE*/);	
}

toWide = function(str){
	return  mapString(  str ,defaultLCID, 0x800000/*_LCMAP_FULLWIDTH*/);	
}

fromWide = function(str){
	return  mapString(  str ,defaultLCID, 0x400000/*_LCMAP_HALFWIDTH*/);	
}

 
/**intellisense(string.conv)
toWide(__/*字符串*/) = 半角转全角
fromWide(__/*字符串*/) = 全角转半角
upper(__/*字符串*/) = 转大写
lower(__/*字符串*/) = 转小写
betyReverse(__/*字符串*/) = 每两个字节前后位置反转
traditionalized(.(简体字,是否转换习惯用语) = GBK编码繁体字转简体字\n参数二为可选参数
simplized(.(繁体字,是否转换习惯用语) = GBK编码简体字转繁体字\n参数二为可选参数
gbkToBig5(__/*GBK字符串*/) = GBK简体转BIG5繁体\n并转换台湾习惯用语
big5ToGbk(__/*GBK字符串*/) = BIG5繁体转GBK简体\n并转换台湾习惯用语 
end intellisense**/


 