win32localepeer.cpp

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

CPP
2,890
字号
		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 long& 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 long& 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 double& 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"%.08f", val );	#else		swprintf( tmp, L"%.08f", val );	#endif		NUMBERFMTW fmt = {0};		initNumberFormatForFloatW( fmt );		int size = ::GetNumberFormatW( lcid_, 0, tmp, NULL, NULL, 0 );		VCFChar* numStr = new VCFChar[size+1];		memset(numStr,0,(size+1)*sizeof(VCFChar));		::GetNumberFormatW( lcid_, 0, tmp, NULL, numStr, size );		delete [] fmt.lpDecimalSep;		delete [] fmt.lpThousandSep;		result = numStr;		delete [] numStr;	}	else {		char tmp[256];		memset(tmp,0,sizeof(tmp));		sprintf( tmp, "%.08f", val );		NUMBERFMTA fmt = {0};		initNumberFormatForFloatA( fmt );		int size = ::GetNumberFormatA( lcid_, 0, tmp, NULL, NULL, 0 );		char* numStr = new char[size+1];		memset(numStr,0,(size+1)*sizeof(char));		::GetNumberFormatA( lcid_, 0, tmp, NULL, numStr, size );		delete [] fmt.lpDecimalSep;		delete [] fmt.lpThousandSep;		result = numStr;		delete [] numStr;	}	return result;}UnicodeString Win32LocalePeer::toString( const float& 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"%.08f", val );	#else		swprintf( tmp, L"%.08f", val );	#endif		NUMBERFMTW fmt = {0};		initNumberFormatForFloatW( fmt );		int size = ::GetNumberFormatW( lcid_, 0, tmp, NULL, NULL, 0 );		VCFChar* numStr = new VCFChar[size+1];		memset(numStr,0,(size+1)*sizeof(VCFChar));		::GetNumberFormatW( lcid_, 0, tmp, NULL, numStr, size );		delete [] fmt.lpDecimalSep;		delete [] fmt.lpThousandSep;		result = numStr;		delete [] numStr;	}	else {		char tmp[256];		memset(tmp,0,sizeof(tmp));		sprintf( tmp, "%.08f", val );		NUMBERFMTA fmt = {0};		initNumberFormatForFloatA( fmt );		int size = ::GetNumberFormatA( lcid_, 0, tmp, NULL, NULL, 0 );		char* numStr = new char[size+1];		memset(numStr,0,(size+1)*sizeof(char));		::GetNumberFormatA( lcid_, 0, tmp, NULL, numStr, size );		delete [] fmt.lpDecimalSep;		delete [] fmt.lpThousandSep;		result = numStr;		delete [] numStr;	}	return result;}UnicodeString Win32LocalePeer::toStringFromCurrency( const double& 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"%.08f", val );	#else		swprintf( tmp, L"%.08f", val );	#endif		int size = ::GetCurrencyFormatW( lcid_, 0, tmp, NULL, NULL, 0 );		VCFChar* numStr = new VCFChar[size+1];		memset(numStr,0,(size+1)*sizeof(VCFChar));		::GetCurrencyFormatW( lcid_, 0, tmp, NULL, numStr, size );		result = numStr;		delete [] numStr;	}	else {		char tmp[256];		memset(tmp,0,sizeof(tmp));		sprintf( tmp, "%.08f", val );		int size = ::GetCurrencyFormatA( lcid_, 0, tmp, NULL, NULL, 0 );		char* numStr = new char[size+1];		memset(numStr,0,(size+1)*sizeof(char));		::GetCurrencyFormatA( lcid_, 0, tmp, NULL, numStr, size );		result = numStr;		delete [] numStr;	}	return result;}UnicodeString Win32LocalePeer::changeToGenericNumberString( const UnicodeString& str ){	UnicodeString result = str;	if ( System::isUnicodeEnabled() ) {		VCFChar tmp[256];		int err = GetLocaleInfoW( lcid_, LOCALE_SDECIMAL, tmp, 255 );		UnicodeString s = tmp;		int pos = result.find( s );		if ( pos != UnicodeString::npos ) {			result.erase( pos, s.size() );			result.insert( pos, L"." );		}		err = GetLocaleInfoW( lcid_, LOCALE_STHOUSAND, tmp, 255 );		if ( 0 == err ) {			err = GetLastError();		}		s = tmp;		pos = result.find( s );		while ( pos != UnicodeString::npos ) {			result.erase( pos, s.size() );			pos = result.find( s );		}	}	else {		char tmp[256];		int err = GetLocaleInfoA( lcid_, LOCALE_SDECIMAL, tmp, 255 );		AnsiString s = tmp;		AnsiString tmpRes = result;		int pos = tmpRes.find( s );		if ( pos != AnsiString::npos ) {			tmpRes.erase( pos, s.size() );			tmpRes.insert( pos, "." );		}		err = GetLocaleInfoA( lcid_, LOCALE_STHOUSAND, tmp, 255 );		if ( 0 == err ) {			err = GetLastError();		}		s = tmp;		pos = tmpRes.find( s );		while ( pos != AnsiString::npos ) {			tmpRes.erase( pos, s.size() );			pos = tmpRes.find( s );		}		result = tmpRes;	}	return result;}int Win32LocalePeer::toInt( const UnicodeString& str ){	int result;	if ( System::isUnicodeEnabled() ) {		float f = 0.0f;		swscanf( changeToGenericNumberString(str).c_str(), L"%f", &f );		result = f;	}	else {		double tmpRes = 0.0;		tmpRes = atof( changeToGenericNumberString(str).ansi_c_str() );		result = tmpRes;	}	return result;}unsigned int Win32LocalePeer::toUInt( const UnicodeString& str ){	unsigned int result;	if ( System::isUnicodeEnabled() ) {		float f = 0.0f;		swscanf( changeToGenericNumberString(str).c_str(), L"%f", &f );		result = f;	}	else {		double tmpRes = 0.0;		tmpRes = atof( changeToGenericNumberString(str).ansi_c_str() );		result = tmpRes;	}	return result;}double Win32LocalePeer::toDouble( const UnicodeString& str ){	double result;	if ( System::isUnicodeEnabled() ) {		float f = 0.0f;		swscanf( changeToGenericNumberString(str).c_str(), L"%f", &f );		result = f;	}	else {		result = atof( changeToGenericNumberString(str).ansi_c_str() );	}	return result;}float Win32LocalePeer::toFloat( const UnicodeString& str ){	float result;	if ( System::isUnicodeEnabled() ) {		swscanf( changeToGenericNumberString(str).c_str(), L"%f", &result );	}	else {		result = atof( changeToGenericNumberString(str).ansi_c_str() );	}	return result;}double Win32LocalePeer::toDoubleAsCurrency( const UnicodeString& str ){	double result;	if ( System::isUnicodeEnabled() ) {		VCFChar tmp[256];		GetLocaleInfoW( lcid_, LOCALE_SMONDECIMALSEP, tmp, 255 );		UnicodeString s = tmp;		UnicodeString s2 = str;		int pos = s2.find( s );		if ( pos != UnicodeString::npos ) {			s2.erase( pos, s.size() );			s2.insert( pos, L"." );		}		GetLocaleInfoW( lcid_, LOCALE_SMONTHOUSANDSEP, tmp, 255 );		s = tmp;		pos = s2.find( s );		while ( pos != UnicodeString::npos ) {			s2.erase( pos, s.size() );			pos = s2.find( s );		}		GetLocaleInfoW( lcid_, LOCALE_SCURRENCY, tmp, 255 );		s = tmp;		pos = s2.find( s );		while ( pos != UnicodeString::npos ) {			s2.erase( pos, s.size() );			pos = s2.find( s );		}		float f = 0.0f;		swscanf( s2.c_str(), L"%f", &f );		result = f;	}	else {		char tmp[256];		GetLocaleInfoA( lcid_, LOCALE_SMONDECIMALSEP, tmp, 255 );		AnsiString s = tmp;		AnsiString s2 = str;		int pos = s2.find( s );		if ( pos != AnsiString::npos ) {			s2.erase( pos, s.size() );			s2.insert( pos, "." );		}		GetLocaleInfoA( lcid_, LOCALE_SMONTHOUSANDSEP, tmp, 255 );		s = tmp;		pos = s2.find( s );		while ( pos != AnsiString::npos ) {			s2.erase( pos, s.size() );			pos = s2.find( s );		}		GetLocaleInfoA( lcid_, LOCALE_SCURRENCY, tmp, 255 );		s = tmp;		pos = s2.find( s );		while ( pos != AnsiString::npos ) {			s2.erase( pos, s.size() );			pos = s2.find( s );		}		result = atof( s2.c_str() );	}	return result;}UnicodeString Win32LocalePeer::toLowerCase( const UnicodeString& s ){	UnicodeString result;	if ( System::isUnicodeEnabled() ) {		int size = LCMapStringW( lcid_, LCMAP_LOWERCASE, s.c_str(), s.size(), NULL, 0 );		VCFChar* tmp = new VCFChar[size+1];		memset( tmp, 0, (size+1) * sizeof(VCFChar));		LCMapStringW( lcid_, LCMAP_LOWERCASE, s.c_str(), s.size(), tmp, size );		result = tmp;		delete [] tmp;	}	else {		const char* ansiStr = s.ansi_c_str();		int ansiSize = strlen(ansiStr);		int size = LCMapStringA( lcid_, LCMAP_LOWERCASE, ansiStr, ansiSize, NULL, 0 );		char* tmp = new char[size+1];		memset( tmp, 0, (size+1)*sizeof(char));		LCMapStringA( lcid_, LCMAP_LOWERCASE, ansiStr, ansiSize, tmp, size );		result = tmp;		delete [] tmp;	}	return result;}UnicodeString Win32LocalePeer::toUpperCase( const UnicodeString& s ){	UnicodeString result;	if ( System::isUnicodeEnabled() ) {		int size = LCMapStringW( lcid_, LCMAP_UPPERCASE, s.c_str(), s.size(), NULL, 0 );		VCFChar* tmp = new VCFChar[size+1];		memset( tmp, 0, (size+1) * sizeof(VCFChar));		LCMapStringW( lcid_, LCMAP_UPPERCASE, s.c_str(), s.size(), tmp, size );		result = tmp;		delete [] tmp;	}	else {		const char* ansiStr = s.ansi_c_str();		int ansiSize = strlen(ansiStr);		int size = LCMapStringA( lcid_, LCMAP_UPPERCASE, ansiStr, ansiSize, NULL, 0 );		char* tmp = new char[size+1];		memset( tmp, 0, (size+1)*sizeof(char));		LCMapStringA( lcid_, LCMAP_UPPERCASE, ansiStr, ansiSize, tmp, size );		result = tmp;		delete [] tmp;	}	return result;}UnicodeString Win32LocalePeer::getNumberThousandsSeparator(){	UnicodeString result;	if ( System::isUnicodeEnabled() ) {		VCFChar tmp[256];		GetLocaleInfoW( lcid_, LOCALE_STHOUSAND, tmp, 255 );		result = tmp;	}	else {		char tmp[256];		GetLocaleInfoA( lcid_, LOCALE_STHOUSAND, tmp, 255 );		result = tmp;	}

⌨️ 快捷键说明

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