1 | #include "stdafx.h"
|
---|
2 | #include <algorithm>
|
---|
3 |
|
---|
4 | bool Jenga::Common::IsExistString( const Jenga::Common::Strings &strings, const std::string &findStr )
|
---|
5 | {
|
---|
6 | return std::find( strings.begin(), strings.end(), findStr ) != strings.end();
|
---|
7 | }
|
---|
8 |
|
---|
9 | std::string& Jenga::Common::StringReplace( std::string& str, const std::string &sb, const std::string &sa )
|
---|
10 | {
|
---|
11 | std::string::size_type n, nb = 0;
|
---|
12 |
|
---|
13 | while ((n = str.find(sb,nb)) != std::string::npos)
|
---|
14 | {
|
---|
15 | str.replace(n,sb.size(),sa);
|
---|
16 | nb = n + sa.size();
|
---|
17 | }
|
---|
18 |
|
---|
19 | return str;
|
---|
20 | }
|
---|
21 |
|
---|
22 | std::string Jenga::Common::ToString( int n )
|
---|
23 | {
|
---|
24 | char temp[255];
|
---|
25 | wsprintf( temp, "%d", n );
|
---|
26 | return temp;
|
---|
27 | }
|
---|
28 |
|
---|
29 | std::string Jenga::Common::ToString( const std::wstring &wstr )
|
---|
30 | {
|
---|
31 | int needSize = WideCharToMultiByte(
|
---|
32 | CP_THREAD_ACP,
|
---|
33 | 0,
|
---|
34 | wstr.data(), static_cast<int>(wstr.size()),
|
---|
35 | NULL, NULL,
|
---|
36 | NULL, NULL );
|
---|
37 |
|
---|
38 | char *pstr = (char *)calloc( needSize, 1 );
|
---|
39 | WideCharToMultiByte(
|
---|
40 | CP_THREAD_ACP,
|
---|
41 | 0,
|
---|
42 | wstr.data(), static_cast<int>(wstr.size()),
|
---|
43 | pstr, needSize,
|
---|
44 | NULL, NULL );
|
---|
45 |
|
---|
46 | std::string result(pstr, needSize);
|
---|
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.data(), static_cast<int>(str.size()),
|
---|
59 | NULL, 0 );
|
---|
60 |
|
---|
61 | LPWSTR pwstr = (LPWSTR)calloc( size, sizeof (wchar_t) );
|
---|
62 |
|
---|
63 | MultiByteToWideChar(
|
---|
64 | CP_ACP,
|
---|
65 | 0,
|
---|
66 | str.data(), static_cast<int>(str.size()),
|
---|
67 | pwstr, size );
|
---|
68 |
|
---|
69 | std::wstring wstr( pwstr, 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 | }
|
---|