[518] | 1 | #include "stdafx.h"
|
---|
[465] | 2 |
|
---|
| 3 | bool Jenga::Common::IsExistString( const Jenga::Common::Strings &strings, const std::string &findStr )
|
---|
| 4 | {
|
---|
| 5 | BOOST_FOREACH( const std::string &str, strings )
|
---|
| 6 | {
|
---|
| 7 | if( str == findStr )
|
---|
| 8 | {
|
---|
| 9 | return true;
|
---|
| 10 | }
|
---|
| 11 | }
|
---|
| 12 | return false;
|
---|
| 13 | }
|
---|
[472] | 14 |
|
---|
| 15 | std::string& Jenga::Common::StringReplace( std::string& str, const std::string sb, const std::string sa )
|
---|
| 16 | {
|
---|
| 17 | std::string::size_type n, nb = 0;
|
---|
| 18 |
|
---|
| 19 | while ((n = str.find(sb,nb)) != std::string::npos)
|
---|
| 20 | {
|
---|
| 21 | str.replace(n,sb.size(),sa);
|
---|
| 22 | nb = n + sa.size();
|
---|
| 23 | }
|
---|
| 24 |
|
---|
| 25 | return str;
|
---|
| 26 | }
|
---|
[590] | 27 |
|
---|
[607] | 28 | std::string Jenga::Common::ToString( int n )
|
---|
| 29 | {
|
---|
| 30 | char temp[255];
|
---|
| 31 | wsprintf( temp, "%d", n );
|
---|
| 32 | return temp;
|
---|
| 33 | }
|
---|
| 34 |
|
---|
[747] | 35 | std::string Jenga::Common::ToString( const std::wstring &wstr )
|
---|
| 36 | {
|
---|
[748] | 37 | int needSize = WideCharToMultiByte(
|
---|
| 38 | CP_THREAD_ACP,
|
---|
| 39 | 0,
|
---|
| 40 | wstr.c_str(), -1,
|
---|
| 41 | NULL, NULL,
|
---|
| 42 | NULL, NULL );
|
---|
[747] | 43 |
|
---|
[748] | 44 | char *pstr = (char *)calloc( needSize + 1, 1 );
|
---|
[747] | 45 | WideCharToMultiByte(
|
---|
[748] | 46 | CP_THREAD_ACP,
|
---|
[747] | 47 | 0,
|
---|
| 48 | wstr.c_str(), -1,
|
---|
[748] | 49 | pstr, needSize,
|
---|
[747] | 50 | NULL, NULL );
|
---|
| 51 |
|
---|
| 52 | std::string result = pstr;
|
---|
| 53 |
|
---|
| 54 | free( pstr );
|
---|
| 55 |
|
---|
| 56 | return result;
|
---|
| 57 | }
|
---|
| 58 |
|
---|
[590] | 59 | std::wstring Jenga::Common::ToWString( const std::string &str )
|
---|
| 60 | {
|
---|
| 61 | int size = MultiByteToWideChar(
|
---|
| 62 | CP_ACP,
|
---|
| 63 | 0,
|
---|
| 64 | str.c_str(), static_cast<int>(str.size()) + 1,
|
---|
[745] | 65 | NULL, 0 ) * 4;
|
---|
[590] | 66 |
|
---|
[747] | 67 | LPWSTR pwstr = (LPWSTR)calloc( size, 1 );
|
---|
[590] | 68 |
|
---|
| 69 | MultiByteToWideChar(
|
---|
| 70 | CP_ACP,
|
---|
| 71 | 0,
|
---|
| 72 | str.c_str(), static_cast<int>(str.size()) + 1,
|
---|
| 73 | pwstr, static_cast<int>(str.size()) + 1 );
|
---|
| 74 |
|
---|
| 75 | std::wstring wstr( pwstr, str.size() );
|
---|
| 76 |
|
---|
| 77 | free( pwstr );
|
---|
| 78 |
|
---|
| 79 | return wstr;
|
---|
| 80 | }
|
---|
[622] | 81 |
|
---|
| 82 | bool Jenga::Common::IsIdentifierTopChar( char c )
|
---|
| 83 | {
|
---|
| 84 | return ( isalpha( c ) || c == '_' );
|
---|
| 85 | }
|
---|
| 86 |
|
---|
| 87 | bool Jenga::Common::IsIdentifierChar( char c )
|
---|
| 88 | {
|
---|
| 89 | return ( IsIdentifierTopChar( c ) || isdigit( c ) );
|
---|
| 90 | }
|
---|