-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcsaori_util.h
96 lines (75 loc) · 2.41 KB
/
csaori_util.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*
* csaori_util.h
*/
#pragma once
#pragma warning(disable : 4786)
#define SAORIAPI extern "C" __declspec(dllexport)
#define SAORICDECL __cdecl
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <string>
#include <vector>
#include <map>
#include <sstream>
//charset hack
#ifdef CP_UTF8
#undef CP_UTF8
#endif
typedef wchar_t char_t;
typedef std::basic_string<char_t> string_t;
typedef enum {
CP_SJIS=932,
CP_EUCJP=20932,
CP_ISO2022JP=50220,
CP_UTF8=65001
} CODEPAGE;
//global functions
namespace SAORI_FUNC {
template<typename _Type> string_t numToString(_Type num){
char_t buf[32];
swprintf(buf,L"%d",num);
return buf;
}
template<> string_t numToString<unsigned char>(unsigned char num);
template<> string_t numToString<unsigned int>(unsigned int num);
template<> string_t numToString<unsigned long>(unsigned long num);
string_t inline intToString(int num){return numToString(num);}
string_t::size_type getLine(string_t &, const string_t &, string_t::size_type);
string_t getResultString(int);
string_t replaceAll(string_t string, const string_t &find, const string_t &replace);
std::string replaceAll(std::string string, const std::string &find, const std::string &replace);
std::string UnicodeToMultiByte(const wchar_t *Source, unsigned int CodePage=CP_OEMCP, DWORD Flags=0);
inline std::string UnicodeToMultiByte(const string_t& Source, unsigned int CodePage=CP_OEMCP, DWORD Flags=0) {
return UnicodeToMultiByte(Source.c_str(),CodePage,Flags);
}
string_t MultiByteToUnicode(const char *Source, unsigned int CodePage=CP_OEMCP, DWORD Flags=0);
inline string_t MultiByteToUnicode(const std::string& Source, unsigned int CodePage=CP_OEMCP, DWORD Flags=0) {
return MultiByteToUnicode(Source.c_str(),CodePage,Flags);
}
string_t CodePagetoString(unsigned int cp);
unsigned int StringtoCodePage(const char *str);
void AsyncMessageBox(void *hwnd,char_t *message,char_t *title,unsigned int flags);
//CriticalSection
class CCriticalSection {
private:
CRITICAL_SECTION c;
bool init;
public:
CCriticalSection(void);
~CCriticalSection();
void Enter(void);
void Leave(void);
};
//CriticalSectionŠJ•úƒ‰ƒbƒp[
class CCriticalSectionLock {
private:
CCriticalSection &c;
public:
CCriticalSectionLock(CCriticalSection &pc) : c(pc) {
c.Enter();
}
~CCriticalSectionLock() {
c.Leave();
}
};
}