source: dev/branches/x64_compiler_on_32/jenga/src/common/String.cpp

Last change on this file was 748, checked in by dai, 16 years ago

WCHAR配列をUnicode文字列としてデバッグ窓に表示可能にした。

File size: 1.7 KB
Line 
1#include "stdafx.h"
2
3bool 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
15std::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
28std::string Jenga::Common::ToString( int n )
29{
30 char temp[255];
31 wsprintf( temp, "%d", n );
32 return temp;
33}
34
35std::string Jenga::Common::ToString( const std::wstring &wstr )
36{
37 int needSize = WideCharToMultiByte(
38 CP_THREAD_ACP,
39 0,
40 wstr.c_str(), -1,
41 NULL, NULL,
42 NULL, NULL );
43
44 char *pstr = (char *)calloc( needSize + 1, 1 );
45 WideCharToMultiByte(
46 CP_THREAD_ACP,
47 0,
48 wstr.c_str(), -1,
49 pstr, needSize,
50 NULL, NULL );
51
52 std::string result = pstr;
53
54 free( pstr );
55
56 return result;
57}
58
59std::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,
65 NULL, 0 ) * 4;
66
67 LPWSTR pwstr = (LPWSTR)calloc( size, 1 );
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}
81
82bool Jenga::Common::IsIdentifierTopChar( char c )
83{
84 return ( isalpha( c ) || c == '_' );
85}
86
87bool Jenga::Common::IsIdentifierChar( char c )
88{
89 return ( IsIdentifierTopChar( c ) || isdigit( c ) );
90}
Note: See TracBrowser for help on using the repository browser.