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::string Jenga::Common::ToString( const std::wstring &wstr )
|
---|
36 | {
|
---|
37 | char *pstr = (char *)malloc( wstr.length() + 1 );
|
---|
38 |
|
---|
39 | WideCharToMultiByte(
|
---|
40 | CP_ACP,
|
---|
41 | 0,
|
---|
42 | wstr.c_str(), -1,
|
---|
43 | pstr, static_cast<int>(wstr.length()) + 1,
|
---|
44 | NULL, NULL );
|
---|
45 |
|
---|
46 | std::string result = pstr;
|
---|
47 |
|
---|
48 | free( pstr );
|
---|
49 |
|
---|
50 | return result;
|
---|
51 | }
|
---|
52 |
|
---|
53 | std::wstring Jenga::Common::ToWString( const std::string &str )
|
---|
54 | {
|
---|
55 | int size = MultiByteToWideChar(
|
---|
56 | CP_ACP,
|
---|
57 | 0,
|
---|
58 | str.c_str(), static_cast<int>(str.size()) + 1,
|
---|
59 | NULL, 0 ) * 4;
|
---|
60 |
|
---|
61 | LPWSTR pwstr = (LPWSTR)calloc( size, 1 );
|
---|
62 |
|
---|
63 | MultiByteToWideChar(
|
---|
64 | CP_ACP,
|
---|
65 | 0,
|
---|
66 | str.c_str(), static_cast<int>(str.size()) + 1,
|
---|
67 | pwstr, static_cast<int>(str.size()) + 1 );
|
---|
68 |
|
---|
69 | std::wstring wstr( pwstr, str.size() );
|
---|
70 |
|
---|
71 | free( pwstr );
|
---|
72 |
|
---|
73 | return wstr;
|
---|
74 | }
|
---|
75 |
|
---|
76 | bool Jenga::Common::IsIdentifierTopChar( char c )
|
---|
77 | {
|
---|
78 | return ( isalpha( c ) || c == '_' );
|
---|
79 | }
|
---|
80 |
|
---|
81 | bool Jenga::Common::IsIdentifierChar( char c )
|
---|
82 | {
|
---|
83 | return ( IsIdentifierTopChar( c ) || isdigit( c ) );
|
---|
84 | }
|
---|