win32localepeer.cpp

来自「这是VCF框架的代码」· C++ 代码 · 共 2,890 行 · 第 1/5 页

CPP
2,890
字号
//Win32LocalePeer.cpp/*Copyright 2000-2004 The VCF Project.Please see License.txt in the top level directorywhere you installed the VCF.*/#include "vcf/FoundationKit/FoundationKit.h"#include "vcf/FoundationKit/LocalePeer.h"#include "vcf/FoundationKit/Win32LocalePeer.h"#include "vcf/FoundationKit/DateTime.h"#include <locale.h>using namespace VCF;std::map<String,int> Win32LocalePeer::langIDs;std::map<String,int> Win32LocalePeer::countryIDs;static std::map<String,String> countryToWin32Country;static std::map<String,String> languageToWin32Language;Win32LocalePeer::Win32LocalePeer():lcid_(0){	lcid_ = GetUserDefaultLCID();	if ( Win32LocalePeer::langIDs.empty() ) {		Win32LocalePeer::langIDs["af"] = LANG_AFRIKAANS;		Win32LocalePeer::langIDs["sq"] = LANG_ALBANIAN;		Win32LocalePeer::langIDs["ar"] = LANG_ARABIC;		Win32LocalePeer::langIDs["hy"] = LANG_ARMENIAN;		Win32LocalePeer::langIDs["as"] = LANG_ASSAMESE;		Win32LocalePeer::langIDs["az"] = LANG_AZERI;		Win32LocalePeer::langIDs["eu"] = LANG_BASQUE;		Win32LocalePeer::langIDs["be"] = LANG_BELARUSIAN;		Win32LocalePeer::langIDs["bn"] = LANG_BENGALI;		Win32LocalePeer::langIDs["bg"] = LANG_BULGARIAN;		Win32LocalePeer::langIDs["ca"] = LANG_CATALAN;		Win32LocalePeer::langIDs["zh"] = LANG_CHINESE;		Win32LocalePeer::langIDs["hr"] = LANG_CROATIAN;		Win32LocalePeer::langIDs["cs"] = LANG_CZECH;		Win32LocalePeer::langIDs["da"] = LANG_DANISH;		Win32LocalePeer::langIDs["nl"] = LANG_DUTCH;		Win32LocalePeer::langIDs["en"] = LANG_ENGLISH;		Win32LocalePeer::langIDs["et"] = LANG_ESTONIAN;		Win32LocalePeer::langIDs["fo"] = LANG_FAEROESE;		Win32LocalePeer::langIDs["fa"] = LANG_FARSI;		Win32LocalePeer::langIDs["fi"] = LANG_FINNISH;		Win32LocalePeer::langIDs["fr"] = LANG_FRENCH;		Win32LocalePeer::langIDs["ka"] = LANG_GEORGIAN;		Win32LocalePeer::langIDs["de"] = LANG_GERMAN;		Win32LocalePeer::langIDs["el"] = LANG_GREEK;		Win32LocalePeer::langIDs["gu"] = LANG_GUJARATI;		Win32LocalePeer::langIDs["he"] = LANG_HEBREW;		Win32LocalePeer::langIDs["hi"] = LANG_HINDI;		Win32LocalePeer::langIDs["hu"] = LANG_HUNGARIAN;		Win32LocalePeer::langIDs["is"] = LANG_ICELANDIC;		Win32LocalePeer::langIDs["id"] = LANG_INDONESIAN;		Win32LocalePeer::langIDs["it"] = LANG_ITALIAN;		Win32LocalePeer::langIDs["ja"] = LANG_JAPANESE;		Win32LocalePeer::langIDs["kn"] = LANG_KANNADA;		Win32LocalePeer::langIDs["ks"] = LANG_KASHMIRI;		Win32LocalePeer::langIDs["kk"] = LANG_KAZAK;		Win32LocalePeer::langIDs["kok"] = LANG_KONKANI;		Win32LocalePeer::langIDs["ko"] = LANG_KOREAN;		Win32LocalePeer::langIDs["lv"] = LANG_LATVIAN;		Win32LocalePeer::langIDs["lt"] = LANG_LITHUANIAN;		Win32LocalePeer::langIDs["mk"] = LANG_MACEDONIAN;		Win32LocalePeer::langIDs["ms"] = LANG_MALAY;		Win32LocalePeer::langIDs["ml"] = LANG_MALAYALAM;		Win32LocalePeer::langIDs["mni"] = LANG_MANIPURI;		Win32LocalePeer::langIDs["mr"] = LANG_MARATHI;		Win32LocalePeer::langIDs["ne"] = LANG_NEPALI;		Win32LocalePeer::langIDs["no"] = LANG_NORWEGIAN;		Win32LocalePeer::langIDs["or"] = LANG_ORIYA;		Win32LocalePeer::langIDs["pl"] = LANG_POLISH;		Win32LocalePeer::langIDs["pt"] = LANG_PORTUGUESE;		Win32LocalePeer::langIDs["pa"] = LANG_PUNJABI;		Win32LocalePeer::langIDs["ro"] = LANG_ROMANIAN;		Win32LocalePeer::langIDs["ru"] = LANG_RUSSIAN;		Win32LocalePeer::langIDs["sa"] = LANG_SANSKRIT;		Win32LocalePeer::langIDs["sr"] = LANG_SERBIAN;		Win32LocalePeer::langIDs["sd"] = LANG_SINDHI;		Win32LocalePeer::langIDs["sk"] = LANG_SLOVAK;		Win32LocalePeer::langIDs["sl"] = LANG_SLOVENIAN;		Win32LocalePeer::langIDs["es"] = LANG_SPANISH;		Win32LocalePeer::langIDs["sw"] = LANG_SWAHILI;		Win32LocalePeer::langIDs["sv"] = LANG_SWEDISH;		Win32LocalePeer::langIDs["ta"] = LANG_TAMIL;		Win32LocalePeer::langIDs["tt"] = LANG_TATAR;		Win32LocalePeer::langIDs["te"] = LANG_TELUGU;		Win32LocalePeer::langIDs["th"] = LANG_THAI;		Win32LocalePeer::langIDs["tr"] = LANG_TURKISH;		Win32LocalePeer::langIDs["uk"] = LANG_UKRAINIAN;		Win32LocalePeer::langIDs["ur"] = LANG_URDU;		Win32LocalePeer::langIDs["uz"] = LANG_UZBEK;		Win32LocalePeer::langIDs["vi"] = LANG_VIETNAMESE;	}	if ( countryToWin32Country.empty() ) {		countryToWin32Country["AU"] = "aus";		countryToWin32Country["AT"] = "aut";		countryToWin32Country["BE"] = "bel";		countryToWin32Country["BR"] = "bra";		countryToWin32Country["CA"] = "can";		countryToWin32Country["CZ"] = "cze";		countryToWin32Country["DK"] = "dnk";		countryToWin32Country["FI"] = "fin";		countryToWin32Country["FR"] = "fra";		countryToWin32Country["DE"] = "deu";		countryToWin32Country["GR"] = "grc";		countryToWin32Country["HK"] = "hkg";		countryToWin32Country["HU"] = "hun";		countryToWin32Country["IS"] = "isl";		countryToWin32Country["IE"] = "irl";		countryToWin32Country["IT"] = "ita";		countryToWin32Country["JP"] = "jpn";		countryToWin32Country["MX"] = "mex";		countryToWin32Country["NL"] = "nld";		countryToWin32Country["NZ"] = "nzl";		countryToWin32Country["NO"] = "nor";		countryToWin32Country["CN"] = "chn";		countryToWin32Country["PL"] = "pol";		countryToWin32Country["PT"] = "prt";		countryToWin32Country["RU"] = "rus";		countryToWin32Country["SG"] = "sgp";		countryToWin32Country["SK"] = "svk";		countryToWin32Country["KR"] = "kor";		countryToWin32Country["ES"] = "esp";		countryToWin32Country["SE"] = "swe";		countryToWin32Country["CH"] = "che";		countryToWin32Country["TW"] = "twn";		countryToWin32Country["TR"] = "tur";		countryToWin32Country["UK"] = "gbr";		countryToWin32Country["US"] = "usa";	}	if ( languageToWin32Language.empty() ) {		languageToWin32Language["en"] = "english";		languageToWin32Language["zh_CN"] = "chinese";		languageToWin32Language["zh_HK"] = "chinese";		languageToWin32Language["zh_SG"] = "chinese";		languageToWin32Language["zh_MO"] = "chinese";		languageToWin32Language["nl_BK"] = "dutch";		languageToWin32Language["nl_BE"] = "dutch-belgian";		languageToWin32Language["en_US"] = "english-us";		languageToWin32Language["en_UK"] = "english-uk";		languageToWin32Language["en_GB"] = "english-uk";		languageToWin32Language["en_AU"] = "english-aus";		languageToWin32Language["en_CA"] = "english-can";		languageToWin32Language["en_NZ"] = "english-nz";		languageToWin32Language["fr_FR"] = "french";		languageToWin32Language["fr_BE"] = "french-belgian";		languageToWin32Language["fr_CA"] = "french-canadian";		languageToWin32Language["fr_CH"] = "french-swiss";		languageToWin32Language["de_DE"] = "german";		languageToWin32Language["de_CH"] = "german-swiss";		languageToWin32Language["de_AT"] = "german-austrian";		languageToWin32Language["is_IS"] = "icelandic";		languageToWin32Language["el_GR"] = "greek";		languageToWin32Language["hu_HU"] = "hungarian";		languageToWin32Language["it_IT"] = "italian";		languageToWin32Language["it_CH"] = "italian-swiss";		languageToWin32Language["ja_JP"] = "japanese";		languageToWin32Language["ko_KR"] = "korean";		languageToWin32Language["no_BK"] = "norwegian-bokmal";		languageToWin32Language["no_NO"] = "norwegian-nynorsk";		languageToWin32Language["pl_PL"] = "polish";		languageToWin32Language["pt_PT"] = "portuguese";		languageToWin32Language["pt_BR"] = "portuguese-brazilian";		languageToWin32Language["es_ES"] = "spanish";		languageToWin32Language["es_MX"] = "spanish-mexican";		languageToWin32Language["es_GT"] = "spanish-modern";		languageToWin32Language["es_CR"] = "spanish-modern";		languageToWin32Language["es_PA"] = "spanish-modern";		languageToWin32Language["es_DO"] = "spanish-modern";		languageToWin32Language["es_VE"] = "spanish-modern";		languageToWin32Language["es_CO"] = "spanish-modern";		languageToWin32Language["es_PE"] = "spanish-modern";		languageToWin32Language["es_AR"] = "spanish-modern";		languageToWin32Language["es_EC"] = "spanish-modern";		languageToWin32Language["es_CL"] = "spanish-modern";		languageToWin32Language["es_UY"] = "spanish-modern";		languageToWin32Language["es_PY"] = "spanish-modern";		languageToWin32Language["es_BO"] = "spanish-modern";		languageToWin32Language["es_SV"] = "spanish-modern";		languageToWin32Language["es_HN"] = "spanish-modern";		languageToWin32Language["es_NI"] = "spanish-modern";		languageToWin32Language["es_PR"] = "spanish-modern";		languageToWin32Language["sv_SE"] = "swedish";		languageToWin32Language["tr_TR"] = "turkish";	}	if ( Win32LocalePeer::countryIDs.empty() ) {		Win32LocalePeer::countryIDs["ar_SA"] = SUBLANG_ARABIC_SAUDI_ARABIA;		Win32LocalePeer::countryIDs["ar_IQ"] = SUBLANG_ARABIC_IRAQ;		Win32LocalePeer::countryIDs["ar_EG"] = SUBLANG_ARABIC_EGYPT;		Win32LocalePeer::countryIDs["ar_LY"] = SUBLANG_ARABIC_LIBYA;		Win32LocalePeer::countryIDs["ar_DZ"] = SUBLANG_ARABIC_ALGERIA;		Win32LocalePeer::countryIDs["ar_MA"] = SUBLANG_ARABIC_MOROCCO;		Win32LocalePeer::countryIDs["ar_TN"] = SUBLANG_ARABIC_TUNISIA;		Win32LocalePeer::countryIDs["ar_OM"] = SUBLANG_ARABIC_OMAN;		Win32LocalePeer::countryIDs["ar_YE"] = SUBLANG_ARABIC_YEMEN;		Win32LocalePeer::countryIDs["ar_SY"] = SUBLANG_ARABIC_SYRIA;		Win32LocalePeer::countryIDs["ar_JO"] = SUBLANG_ARABIC_JORDAN;		Win32LocalePeer::countryIDs["ar_LB"] = SUBLANG_ARABIC_LEBANON;		Win32LocalePeer::countryIDs["ar_KW"] = SUBLANG_ARABIC_KUWAIT;		Win32LocalePeer::countryIDs["ar_AE"] = SUBLANG_ARABIC_UAE;		Win32LocalePeer::countryIDs["ar_BH"] = SUBLANG_ARABIC_BAHRAIN;		Win32LocalePeer::countryIDs["ar_QA"] = SUBLANG_ARABIC_QATAR;		Win32LocalePeer::countryIDs["az_AZ"] = SUBLANG_AZERI_CYRILLIC;		Win32LocalePeer::countryIDs["zh_CN"] = SUBLANG_CHINESE_TRADITIONAL;		Win32LocalePeer::countryIDs["zh_HK"] = SUBLANG_CHINESE_HONGKONG;		Win32LocalePeer::countryIDs["zh_SG"] = SUBLANG_CHINESE_SINGAPORE;		Win32LocalePeer::countryIDs["zh_MO"] = SUBLANG_CHINESE_MACAU;		Win32LocalePeer::countryIDs["nl_BK"] = SUBLANG_DUTCH;		Win32LocalePeer::countryIDs["nl_BE"] = SUBLANG_DUTCH_BELGIAN;		Win32LocalePeer::countryIDs["en_US"] = SUBLANG_ENGLISH_US;		Win32LocalePeer::countryIDs["en_UK"] = SUBLANG_ENGLISH_UK;		Win32LocalePeer::countryIDs["en_GB"] = SUBLANG_ENGLISH_UK;		Win32LocalePeer::countryIDs["en_AU"] = SUBLANG_ENGLISH_AUS;		Win32LocalePeer::countryIDs["en_CA"] = SUBLANG_ENGLISH_CAN;		Win32LocalePeer::countryIDs["en_NZ"] = SUBLANG_ENGLISH_NZ;		Win32LocalePeer::countryIDs["en_IE"] = SUBLANG_ENGLISH_EIRE;		Win32LocalePeer::countryIDs["en_ZA"] = SUBLANG_ENGLISH_SOUTH_AFRICA;		Win32LocalePeer::countryIDs["en_JM"] = SUBLANG_ENGLISH_JAMAICA;		Win32LocalePeer::countryIDs["en_BZ"] = SUBLANG_ENGLISH_BELIZE;		Win32LocalePeer::countryIDs["en_TT"] = SUBLANG_ENGLISH_TRINIDAD;		Win32LocalePeer::countryIDs["en_PH"] = SUBLANG_ENGLISH_PHILIPPINES;		Win32LocalePeer::countryIDs["en_ZW"] = SUBLANG_ENGLISH_ZIMBABWE;		Win32LocalePeer::countryIDs["fr_FR"] = SUBLANG_FRENCH;		Win32LocalePeer::countryIDs["fr_BE"] = SUBLANG_FRENCH_BELGIAN;		Win32LocalePeer::countryIDs["fr_CA"] = SUBLANG_FRENCH_CANADIAN;		Win32LocalePeer::countryIDs["fr_CH"] = SUBLANG_FRENCH_SWISS;		Win32LocalePeer::countryIDs["fr_LU"] = SUBLANG_FRENCH_LUXEMBOURG;		Win32LocalePeer::countryIDs["fr_MC"] = SUBLANG_FRENCH_MONACO;		Win32LocalePeer::countryIDs["de_DE"] = SUBLANG_GERMAN;		Win32LocalePeer::countryIDs["de_CH"] = SUBLANG_GERMAN_SWISS;		Win32LocalePeer::countryIDs["de_AT"] = SUBLANG_GERMAN_AUSTRIAN;		Win32LocalePeer::countryIDs["de_LU"] = SUBLANG_GERMAN_LUXEMBOURG;		Win32LocalePeer::countryIDs["de_LI"] = SUBLANG_GERMAN_LIECHTENSTEIN;		Win32LocalePeer::countryIDs["it_IT"] = SUBLANG_ITALIAN;		Win32LocalePeer::countryIDs["it_CH"] = SUBLANG_ITALIAN_SWISS;		Win32LocalePeer::countryIDs["ks_IN"] = SUBLANG_KASHMIRI_INDIA;		Win32LocalePeer::countryIDs["ko_KR"] = SUBLANG_KOREAN;		Win32LocalePeer::countryIDs["lt_LT"] = SUBLANG_LITHUANIAN;		Win32LocalePeer::countryIDs["ms_BN"] = SUBLANG_MALAY_BRUNEI_DARUSSALAM;		Win32LocalePeer::countryIDs["ne_IN"] = SUBLANG_NEPALI_INDIA;		Win32LocalePeer::countryIDs["no_BK"] = SUBLANG_NORWEGIAN_BOKMAL;		Win32LocalePeer::countryIDs["no_NO"] = SUBLANG_NORWEGIAN_NYNORSK;		Win32LocalePeer::countryIDs["pt_PT"] = SUBLANG_PORTUGUESE;		Win32LocalePeer::countryIDs["pt_BR"] = SUBLANG_PORTUGUESE_BRAZILIAN;		Win32LocalePeer::countryIDs["sr_CS"] = SUBLANG_SERBIAN_LATIN;		Win32LocalePeer::countryIDs["sr_CS"] = SUBLANG_SERBIAN_CYRILLIC;		Win32LocalePeer::countryIDs["es_ES"] = SUBLANG_SPANISH;		Win32LocalePeer::countryIDs["es_MX"] = SUBLANG_SPANISH_MEXICAN;		Win32LocalePeer::countryIDs["es_GT"] = SUBLANG_SPANISH_GUATEMALA;		Win32LocalePeer::countryIDs["es_CR"] = SUBLANG_SPANISH_COSTA_RICA;		Win32LocalePeer::countryIDs["es_PA"] = SUBLANG_SPANISH_PANAMA;		Win32LocalePeer::countryIDs["es_DO"] = SUBLANG_SPANISH_DOMINICAN_REPUBLIC;		Win32LocalePeer::countryIDs["es_VE"] = SUBLANG_SPANISH_VENEZUELA;		Win32LocalePeer::countryIDs["es_CO"] = SUBLANG_SPANISH_COLOMBIA;		Win32LocalePeer::countryIDs["es_PE"] = SUBLANG_SPANISH_PERU;		Win32LocalePeer::countryIDs["es_AR"] = SUBLANG_SPANISH_ARGENTINA;		Win32LocalePeer::countryIDs["es_EC"] = SUBLANG_SPANISH_ECUADOR;		Win32LocalePeer::countryIDs["es_CL"] = SUBLANG_SPANISH_CHILE;		Win32LocalePeer::countryIDs["es_UY"] = SUBLANG_SPANISH_URUGUAY;		Win32LocalePeer::countryIDs["es_PY"] = SUBLANG_SPANISH_PARAGUAY;		Win32LocalePeer::countryIDs["es_BO"] = SUBLANG_SPANISH_BOLIVIA;		Win32LocalePeer::countryIDs["es_SV"] = SUBLANG_SPANISH_EL_SALVADOR;		Win32LocalePeer::countryIDs["es_HN"] = SUBLANG_SPANISH_HONDURAS;		Win32LocalePeer::countryIDs["es_NI"] = SUBLANG_SPANISH_NICARAGUA;		Win32LocalePeer::countryIDs["es_PR"] = SUBLANG_SPANISH_PUERTO_RICO;		Win32LocalePeer::countryIDs["sv_SE"] = SUBLANG_SWEDISH;		Win32LocalePeer::countryIDs["sv_FI"] = SUBLANG_SWEDISH_FINLAND;		Win32LocalePeer::countryIDs["ur_IN"] = SUBLANG_URDU_INDIA;		Win32LocalePeer::countryIDs["ur_PK"] = SUBLANG_URDU_PAKISTAN;		Win32LocalePeer::countryIDs["uz_UZ"] = SUBLANG_UZBEK_CYRILLIC;	}}void Win32LocalePeer::setLocale( const UnicodeString& language, const UnicodeString& country, const UnicodeString& variant ){	if ( language.empty() && country.empty() ) {		lcid_ = GetThreadLocale();		crtLocaleStr_ = setlocale( LC_ALL, NULL );	}	else {		WORD langID = 0;		USHORT primaryLanguage = 0;		USHORT subLanguage = 0;		std::map<String,int>::iterator found = Win32LocalePeer::langIDs.find( language );		if ( found != Win32LocalePeer::langIDs.end() ) {			primaryLanguage = found->second;		}		else {			primaryLanguage = LANG_NEUTRAL;		}		found = Win32LocalePeer::countryIDs.find( language + "_" + country );		if ( found != Win32LocalePeer::countryIDs.end() ) {			subLanguage = found->second;		}		else {			subLanguage = SUBLANG_DEFAULT;		}		lcid_ = MAKELCID( MAKELANGID(primaryLanguage,subLanguage), SORT_DEFAULT );		crtLocaleStr_ = "";		std::map<String,String>::iterator found2 = languageToWin32Language.find( language + "_" + country );		if ( found2 != languageToWin32Language.end() ) {			crtLocaleStr_ = found2->second;		}		found2 = countryToWin32Country.find( country );		if ( found2 != countryToWin32Country.end() ) {			crtLocaleStr_ += "_" + found2->second;		}	}}int Win32LocalePeer::collate( const UnicodeString& s1, const UnicodeString& s2 ){	int result = 0;	int cmpRes = CSTR_EQUAL;	if ( System::isUnicodeEnabled() ) {		cmpRes = ::CompareStringW( lcid_, 0, s1.c_str(), s1.size(), s2.c_str(), s2.size() );	}	else {		AnsiString tmp1 = s1;		AnsiString tmp2 = s2;		cmpRes = ::CompareStringA( lcid_, 0, tmp1.c_str(), tmp1.size(), tmp2.c_str(), tmp2.size() );	}	switch ( cmpRes ) {		case CSTR_LESS_THAN : {			result = -1;		}		break;				case CSTR_EQUAL : {			result = 0;		}		break;				case CSTR_GREATER_THAN : {			result = 1;		}		break;	}	return result;}int Win32LocalePeer::collateCaseInsensitive( const UnicodeString& s1, const UnicodeString& s2 ){	int result = 0;	if ( System::isUnicodeEnabled() ) {		result = ::CompareStringW( lcid_, NORM_IGNORECASE, s1.c_str(), s1.size(), s2.c_str(), s2.size() );	}	else {		AnsiString tmp1 = s1;		AnsiString tmp2 = s2;		result = ::CompareStringA( lcid_, NORM_IGNORECASE, tmp1.c_str(), tmp1.size(), tmp2.c_str(), tmp2.size() );	}	return result;}void Win32LocalePeer::initNumberFormatForIntW( NUMBERFMTW& fmt ){	VCFChar tmp[256];	GetLocaleInfoW( lcid_, LOCALE_IDIGITS, tmp, 255 );	fmt.NumDigits = 0;//atoi( tmp );	fmt.LeadingZero = 0;	fmt.lpDecimalSep = new VCFChar[255];	GetLocaleInfoW( lcid_, LOCALE_SDECIMAL, fmt.lpDecimalSep, 255 );	fmt.lpThousandSep = new VCFChar[255];	GetLocaleInfoW( lcid_, LOCALE_STHOUSAND, fmt.lpThousandSep, 255 );	GetLocaleInfoW( lcid_, LOCALE_INEGNUMBER, tmp, 255 );	fmt.NegativeOrder = _wtoi( tmp );	GetLocaleInfoW( lcid_, LOCALE_SGROUPING, tmp, 255 );	UnicodeString s = tmp;	int pos = s.find( ";" );	if ( pos != UnicodeString::npos ) {		//take the first group number		UnicodeString num = s.substr( 0, pos );		fmt.Grouping = _wtoi( num.c_str() );	}}void Win32LocalePeer::initNumberFormatForIntA( NUMBERFMTA& fmt ){	char tmp[256];	GetLocaleInfoA( lcid_, LOCALE_IDIGITS, tmp, 255 );	fmt.NumDigits = 0;//atoi( tmp );	fmt.LeadingZero = 0;	fmt.lpDecimalSep = new char[255];	GetLocaleInfoA( lcid_, LOCALE_SDECIMAL, fmt.lpDecimalSep, 255 );	fmt.lpThousandSep = new char[255];	GetLocaleInfoA( lcid_, LOCALE_STHOUSAND, fmt.lpThousandSep, 255 );	GetLocaleInfoA( lcid_, LOCALE_INEGNUMBER, tmp, 255 );	fmt.NegativeOrder = atoi( tmp );	GetLocaleInfoA( lcid_, LOCALE_SGROUPING, tmp, 255 );	AnsiString s = tmp;	int pos = s.find( ";" );	if ( pos != AnsiString::npos ) {		//take the first group number		AnsiString num = s.substr( 0, pos );		fmt.Grouping = atoi( num.c_str() );	}}void Win32LocalePeer::initNumberFormatForFloatW( NUMBERFMTW& fmt ){	VCFChar tmp[256];	GetLocaleInfoW( lcid_, LOCALE_IDIGITS, tmp, 255 );	fmt.NumDigits = _wtoi( tmp );	GetLocaleInfoW( lcid_, LOCALE_ILZERO, tmp, 255 );	fmt.LeadingZero = _wtoi( tmp );	fmt.lpDecimalSep = new VCFChar[255];	GetLocaleInfoW( lcid_, LOCALE_SDECIMAL, fmt.lpDecimalSep, 255 );	fmt.lpThousandSep = new VCFChar[255];	GetLocaleInfoW( lcid_, LOCALE_STHOUSAND, fmt.lpThousandSep, 255 );	GetLocaleInfoW( lcid_, LOCALE_INEGNUMBER, tmp, 255 );	fmt.NegativeOrder = _wtoi( tmp );	GetLocaleInfoW( lcid_, LOCALE_SGROUPING, tmp, 255 );	UnicodeString s = tmp;	int pos = s.find( L";" );	if ( pos != UnicodeString::npos ) {		//take the first group number		UnicodeString num = s.substr( 0, pos );		fmt.Grouping = _wtoi( num.c_str() );	}}void Win32LocalePeer::initNumberFormatForFloatA( NUMBERFMTA& fmt ){	char tmp[256];	GetLocaleInfoA( lcid_, LOCALE_IDIGITS, tmp, 255 );	fmt.NumDigits = atoi( tmp );	GetLocaleInfoA( lcid_, LOCALE_ILZERO, tmp, 255 );	fmt.LeadingZero = atoi( tmp );	fmt.lpDecimalSep = new char[255];	GetLocaleInfoA( lcid_, LOCALE_SDECIMAL, fmt.lpDecimalSep, 255 );	fmt.lpThousandSep = new char[255];	GetLocaleInfoA( lcid_, LOCALE_STHOUSAND, fmt.lpThousandSep, 255 );	GetLocaleInfoA( lcid_, LOCALE_INEGNUMBER, tmp, 255 );	fmt.NegativeOrder = atoi( tmp );	GetLocaleInfoA( lcid_, LOCALE_SGROUPING, tmp, 255 );	AnsiString s = tmp;	int pos = s.find( ";" );	if ( pos != AnsiString::npos ) {		//take the first group number		AnsiString num = s.substr( 0, pos );		fmt.Grouping = atoi( num.c_str() );	}}UnicodeString Win32LocalePeer::toString( const int& val ){	UnicodeString result;	if ( System::isUnicodeEnabled() ) {		VCFChar tmp[256];		memset(tmp,0,sizeof(tmp));	#if defined(VCF_CW) || defined(VCF_DMC)		swprintf( tmp, sizeof(tmp)-1, L"%d", val);	#else		swprintf( tmp, L"%d", val );	#endif		NUMBERFMTW fmt = {0};		initNumberFormatForIntW( fmt );		int size = ::GetNumberFormatW( lcid_, 0, tmp, &fmt, NULL, 0 );		VCFChar* numStr = new VCFChar[size+1];		memset(numStr,0,(size+1)*sizeof(VCFChar));		::GetNumberFormatW( lcid_, 0, tmp, &fmt, numStr, size );		delete [] fmt.lpDecimalSep;		delete [] fmt.lpThousandSep;		result = numStr;		delete [] numStr;	}	else {		char tmp[256];		memset(tmp,0,sizeof(tmp));		sprintf( tmp, "%d", val );		NUMBERFMTA fmt = {0};		initNumberFormatForIntA( fmt );		int size = ::GetNumberFormatA( lcid_, 0, tmp, &fmt, NULL, 0 );		char* numStr = new char[size+1];		memset(numStr,0,(size+1)*sizeof(char));		::GetNumberFormatA( lcid_, 0, tmp, &fmt, numStr, size );		delete [] fmt.lpDecimalSep;		delete [] fmt.lpThousandSep;		result = numStr;		delete [] numStr;	}	return result;}UnicodeString Win32LocalePeer::toString( const unsigned int& val ){	UnicodeString result;	if ( System::isUnicodeEnabled() ) {		VCFChar tmp[256];		memset(tmp,0,sizeof(tmp));	#if defined(VCF_CW) || defined(VCF_DMC)		swprintf( tmp, sizeof(tmp)-1, L"%d", val);	#else		swprintf( tmp, L"%d", val );	#endif		NUMBERFMTW fmt = {0};		initNumberFormatForIntW( fmt );		int size = ::GetNumberFormatW( lcid_, 0, tmp, &fmt, NULL, 0 );		VCFChar* numStr = new VCFChar[size+1];		memset(numStr,0,(size+1)*sizeof(VCFChar));		::GetNumberFormatW( lcid_, 0, tmp, &fmt, numStr, size );

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?