source: dev/trunk/ab5.0/jenga/src/common/String.cpp@ 804

Last change on this file since 804 was 763, checked in by イグトランス (egtra), 16 years ago

#228試行

File size: 1.7 KB
RevLine 
[518]1#include "stdafx.h"
[763]2#include <algorithm>
[465]3
4bool Jenga::Common::IsExistString( const Jenga::Common::Strings &strings, const std::string &findStr )
5{
[763]6 return std::find( strings.begin(), strings.end(), findStr ) != strings.end();
[465]7}
[472]8
[763]9std::string& Jenga::Common::StringReplace( std::string& str, const std::string &sb, const std::string &sa )
[472]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}
[590]21
[607]22std::string Jenga::Common::ToString( int n )
23{
24 char temp[255];
25 wsprintf( temp, "%d", n );
26 return temp;
27}
28
[747]29std::string Jenga::Common::ToString( const std::wstring &wstr )
30{
[748]31 int needSize = WideCharToMultiByte(
32 CP_THREAD_ACP,
33 0,
[763]34 wstr.data(), static_cast<int>(wstr.size()),
[748]35 NULL, NULL,
36 NULL, NULL );
[747]37
[763]38 char *pstr = (char *)calloc( needSize, 1 );
[747]39 WideCharToMultiByte(
[748]40 CP_THREAD_ACP,
[747]41 0,
[763]42 wstr.data(), static_cast<int>(wstr.size()),
[748]43 pstr, needSize,
[747]44 NULL, NULL );
45
[763]46 std::string result(pstr, needSize);
[747]47
48 free( pstr );
49
50 return result;
51}
52
[590]53std::wstring Jenga::Common::ToWString( const std::string &str )
54{
55 int size = MultiByteToWideChar(
56 CP_ACP,
57 0,
[763]58 str.data(), static_cast<int>(str.size()),
59 NULL, 0 );
[590]60
[763]61 LPWSTR pwstr = (LPWSTR)calloc( size, sizeof (wchar_t) );
[590]62
63 MultiByteToWideChar(
64 CP_ACP,
65 0,
[763]66 str.data(), static_cast<int>(str.size()),
67 pwstr, size );
[590]68
[763]69 std::wstring wstr( pwstr, size );
[590]70
71 free( pwstr );
72
73 return wstr;
74}
[622]75
76bool Jenga::Common::IsIdentifierTopChar( char c )
77{
78 return ( isalpha( c ) || c == '_' );
79}
80
81bool Jenga::Common::IsIdentifierChar( char c )
82{
83 return ( IsIdentifierTopChar( c ) || isdigit( c ) );
84}
Note: See TracBrowser for help on using the repository browser.