forked from YAYA-shiori/yaya-shiori
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmisc.h
144 lines (112 loc) · 4.49 KB
/
misc.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
//
// AYA version 5
//
// 雑用関数
// written by umeici. 2004
//
#ifndef MISCH
#define MISCH
//----
#if defined(WIN32) || defined(_WIN32_WCE)
# include "stdafx.h"
#endif
#include <vector>
#include "globaldef.h"
aya::string_t::size_type Find_IgnoreDQ(const aya::string_t &str, const aya::char_t *findstr);
aya::string_t::size_type Find_IgnoreDQ(const aya::string_t &str, const aya::string_t &findstr);
aya::string_t::size_type find_last_str(const aya::string_t &str, const aya::char_t *findstr);
aya::string_t::size_type find_last_str(const aya::string_t &str, const aya::string_t &findstr);
bool Split(const aya::string_t &str, aya::string_t &dstr0, aya::string_t &dstr1, const aya::char_t *sepstr);
bool Split(const aya::string_t &str, aya::string_t &dstr0, aya::string_t &dstr1, const aya::string_t &sepstr);
char SplitOnly(const aya::string_t &str, aya::string_t &dstr0, aya::string_t &dstr1, aya::char_t *sepstr);
bool Split_IgnoreDQ(const aya::string_t &str, aya::string_t &dstr0, aya::string_t &dstr1, const aya::char_t *sepstr);
char Split_IgnoreDQ(const aya::string_t &str, aya::string_t &dstr0, aya::string_t &dstr1, const aya::string_t &sepstr);
size_t SplitToMultiString(const aya::string_t &str, std::vector<aya::string_t> *array, const aya::string_t &delimiter);
void CutSpace(aya::string_t &str);
void CutStartSpace(aya::string_t &str);
void CutEndSpace(aya::string_t &str);
void CutDoubleQuote(aya::string_t &str);
void CutSingleQuote(aya::string_t &str);
void EscapingInsideDoubleDoubleQuote(aya::string_t &str);
void EscapingInsideDoubleSingleQuote(aya::string_t &str);
void UnescapeSpecialString(aya::string_t &str);
void AddDoubleQuote(aya::string_t &str);
void CutCrLf(aya::string_t &str);
aya::string_t GetDateString(void);
aya::time_t GetEpochTime();
struct tm EpochTimeToLocalTime(aya::time_t tv);
aya::time_t LocalTimeToEpochTime(struct tm &tm);
extern const aya::string_t::size_type IsInDQ_notindq;
extern const aya::string_t::size_type IsInDQ_runaway;
extern const aya::string_t::size_type IsInDQ_npos;
aya::string_t::size_type IsInDQ(const aya::string_t &str, aya::string_t::size_type startpoint, aya::string_t::size_type checkpoint);
bool IsDoubleButNotIntString(const aya::string_t &str);
bool IsIntString(const aya::string_t &str);
bool IsIntBinString(const aya::string_t &str, bool header);
bool IsIntHexString(const aya::string_t &str, bool header);
char IsLegalFunctionName(const aya::string_t &str);
char IsLegalVariableName(const aya::string_t &str);
char IsLegalStrLiteral(const aya::string_t &str);
char IsLegalPlainStrLiteral(const aya::string_t &str);
bool IsUnicodeAware(void);
void EscapeString(aya::string_t &wstr);
void UnescapeString(aya::string_t &wstr);
void EncodeBase64(aya::string_t &out,const char *in,size_t in_len);
void DecodeBase64(std::string &out,const aya::char_t *in,size_t in_len);
void EncodeURL(aya::string_t &out,const char *in,size_t in_len,bool isPlusPercent);
void DecodeURL(std::string &out,const aya::char_t *in,size_t in_len,bool isPlusPercent);
inline bool IsSpace(const aya::char_t &c) {
#if !defined(POSIX) && !defined(__MINGW32__)
return c == L' ' || c == L'\t' || c == L' ';
#else
return c == L' ' || c == L'\t' || c == L'\u3000';
#endif
}
//----
// 関数呼び出しの限界を検査するためのクラス
#define CCALLLIMIT_CALLDEPTH_MAX 32 //呼び出し限界デフォルト
#define CCALLLIMIT_LOOP_MAX 10000 //ループ処理限界デフォルト
class CCallLimit
{
protected:
size_t depth;
size_t maxdepth;
size_t maxloop;
std::vector<aya::string_t> stack;
public:
CCallLimit(void) { depth = 0; maxdepth = CCALLLIMIT_CALLDEPTH_MAX; maxloop = CCALLLIMIT_LOOP_MAX; }
void SetMaxDepth(size_t value) { maxdepth = value; }
size_t GetMaxDepth(void) { return maxdepth; }
void SetMaxLoop(size_t value) { maxloop = value; }
size_t GetMaxLoop(void) { return maxloop; }
void InitCall(void) { depth = 0; stack.clear(); }
char AddCall(const aya::string_t &str) {
depth++;
stack.emplace_back(str);
if (maxdepth && depth > maxdepth)
return 0;
else
return 1;
}
void DeleteCall(void) {
if ( depth ) {
depth--;
stack.erase(stack.end()-1);
}
}
std::vector<aya::string_t> &StackCall(void) {
return stack;
}
int temp_unlock() {
size_t aret=0;
using std::swap;
swap(aret, maxdepth);
return aret;
}
void reset_lock(size_t lock) {
using std::swap;
swap(lock, maxdepth);
}
};
//----
#endif