| 1 | #include "stdafx.h"
|
|---|
| 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 | }
|
|---|
| 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 | }
|
|---|
| 27 |
|
|---|
| 28 | std::string Jenga::Common::ToString( int n )
|
|---|
| 29 | {
|
|---|
| 30 | char temp[255];
|
|---|
| 31 | wsprintf( temp, "%d", n );
|
|---|
| 32 | return temp;
|
|---|
| 33 | }
|
|---|
| 34 |
|
|---|
| 35 | std::wstring Jenga::Common::ToWString( const std::string &str )
|
|---|
| 36 | {
|
|---|
| 37 | int size = MultiByteToWideChar(
|
|---|
| 38 | CP_ACP,
|
|---|
| 39 | 0,
|
|---|
| 40 | str.c_str(), static_cast<int>(str.size()) + 1,
|
|---|
| 41 | NULL, 0 ) * 2;
|
|---|
| 42 |
|
|---|
| 43 | LPWSTR pwstr = (LPWSTR)malloc( size );
|
|---|
| 44 |
|
|---|
| 45 | MultiByteToWideChar(
|
|---|
| 46 | CP_ACP,
|
|---|
| 47 | 0,
|
|---|
| 48 | str.c_str(), static_cast<int>(str.size()) + 1,
|
|---|
| 49 | pwstr, static_cast<int>(str.size()) + 1 );
|
|---|
| 50 |
|
|---|
| 51 | std::wstring wstr( pwstr, str.size() );
|
|---|
| 52 |
|
|---|
| 53 | free( pwstr );
|
|---|
| 54 |
|
|---|
| 55 | return wstr;
|
|---|
| 56 | }
|
|---|
| 57 |
|
|---|
| 58 | bool Jenga::Common::IsIdentifierTopChar( char c )
|
|---|
| 59 | {
|
|---|
| 60 | return ( isalpha( c ) || c == '_' );
|
|---|
| 61 | }
|
|---|
| 62 |
|
|---|
| 63 | bool Jenga::Common::IsIdentifierChar( char c )
|
|---|
| 64 | {
|
|---|
| 65 | return ( IsIdentifierTopChar( c ) || isdigit( c ) );
|
|---|
| 66 | }
|
|---|