#include "stdafx.h" bool Jenga::Common::IsExistString( const Jenga::Common::Strings &strings, const std::string &findStr ) { BOOST_FOREACH( const std::string &str, strings ) { if( str == findStr ) { return true; } } return false; } std::string& Jenga::Common::StringReplace( std::string& str, const std::string sb, const std::string sa ) { std::string::size_type n, nb = 0; while ((n = str.find(sb,nb)) != std::string::npos) { str.replace(n,sb.size(),sa); nb = n + sa.size(); } return str; } std::string Jenga::Common::ToString( int n ) { char temp[255]; wsprintf( temp, "%d", n ); return temp; } std::string Jenga::Common::ToString( const std::wstring &wstr ) { int needSize = WideCharToMultiByte( CP_THREAD_ACP, 0, wstr.c_str(), -1, NULL, NULL, NULL, NULL ); char *pstr = (char *)calloc( needSize + 1, 1 ); WideCharToMultiByte( CP_THREAD_ACP, 0, wstr.c_str(), -1, pstr, needSize, NULL, NULL ); std::string result = pstr; free( pstr ); return result; } std::wstring Jenga::Common::ToWString( const std::string &str ) { int size = MultiByteToWideChar( CP_ACP, 0, str.c_str(), static_cast(str.size()) + 1, NULL, 0 ) * 4; LPWSTR pwstr = (LPWSTR)calloc( size, 1 ); MultiByteToWideChar( CP_ACP, 0, str.c_str(), static_cast(str.size()) + 1, pwstr, static_cast(str.size()) + 1 ); std::wstring wstr( pwstr, str.size() ); free( pwstr ); return wstr; } bool Jenga::Common::IsIdentifierTopChar( char c ) { return ( isalpha( c ) || c == '_' ); } bool Jenga::Common::IsIdentifierChar( char c ) { return ( IsIdentifierTopChar( c ) || isdigit( c ) ); }