forked from WohlSoft/PGE-File-Library-STL
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsmbx64.cpp
More file actions
177 lines (162 loc) · 4.61 KB
/
smbx64.cpp
File metadata and controls
177 lines (162 loc) · 4.61 KB
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
/*
* Platformer Game Engine by Wohlstand, a free platform for game making
* Copyright (c) 2014-2020 Vitaly Novichkov <admin@wohlnet.ru>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "smbx64.h"
namespace smbx64Format
{
//const char *uint_vc = "0123456789";
//const int uint_vc_len = 10;
bool isDegit(PGEChar c)
{
return ((c >= '0') && (c <= '9'));
}
bool isValid(PGESTRING &s, const char *valid_chars, const pge_size_t &valid_chars_len)
{
if(IsEmpty(s)) return false;
pge_size_t i, j;
for(i = 0; i < s.size(); i++)
{
bool found = false;
for(j = 0; j < valid_chars_len; j++)
{
if(PGEGetChar(s[i]) == valid_chars[j])
{
found = true;
break;
}
}
if(!found) return false;
}
return true;
}
}
// /////////////Validators///////////////
//returns FALSE on wrong data
bool SMBX64::IsUInt(PGESTRING in) // UNSIGNED INT
{
using namespace smbx64Format;
#ifdef PGE_FILES_QT
PGEChar *data = in.data();
#else
PGEChar *data = const_cast<char *>(in.data());
#endif
pge_size_t strSize = in.size();
for(pge_size_t i = 0; i < strSize; i++)
{
PGEChar c = *data++;
if((c < '0') || (c > '9'))
return false;
}
return true;
}
bool SMBX64::IsSInt(PGESTRING in) // SIGNED INT
{
using namespace smbx64Format;
if(IsEmpty(in)) return false;
if((in.size() == 1) && (!isDegit(in[0])))
return false;
if((!isDegit(in[0])) && (PGEGetChar(in[0]) != '-'))
return false;
#ifdef PGE_FILES_QT
PGEChar *data = in.data() + 1;
#else
PGEChar *data = &in[0] + 1;
#endif
pge_size_t strSize = in.size();
for(pge_size_t i = 1; i < strSize; i++)
{
PGEChar c = *data++;
if((c < '0') || (c > '9'))
return false;
}
return true;
}
bool SMBX64::IsFloat(PGESTRING &in) // SIGNED FLOAT
{
using namespace smbx64Format;
if(IsEmpty(in)) return true;
if((in.size() == 1) && (!isDegit(in[0]))) return false;
if((!isDegit(in[0])) && (PGEGetChar(in[0]) != '-') && (PGEGetChar(in[0]) != '.') && (PGEGetChar(in[0]) != ',')) return false;
bool decimal = false;
bool pow10 = false;
bool sign = false;
for(pge_size_t i = ((PGEGetChar(in[0]) == '-') ? 1 : 0); i < in.size(); i++)
{
if((!decimal) && (!pow10))
{
if((PGEGetChar(in[i]) == '.') || (PGEGetChar(in[i]) == ','))
{
in[i] = '.'; //replace comma with a dot
decimal = true;
if(i == (in.size() - 1)) return false;
continue;
}
}
if(!pow10)
{
if((PGEGetChar(in[i]) == 'E') || (PGEGetChar(in[i]) == 'e'))
{
pow10 = true;
if(i == (in.size() - 1)) return false;
continue;
}
}
else
{
if(!sign)
{
sign = true;
if((PGEGetChar(in[i]) == '+') || (PGEGetChar(in[i]) == '-'))
{
if(i == (in.size() - 1)) return false;
continue;
}
}
}
if(!isDegit(in[i])) return false;
}
return true;
}
bool SMBX64::IsQuotedString(PGESTRING in)
{
//This is INVERTED validator. If false - good, true - bad.
#define QStrGOOD true
#define QStrBAD false
pge_size_t i = 0;
for(i = 0; i < in.size(); i++)
{
if(i == 0)
{
if(in[i] != '"')
return QStrBAD;
}
else if(i == in.size() - 1)
{
if(in[i] != '"')
return QStrBAD;
}
else if(in[i] == '"')
return QStrBAD;
else if(in[i] == '"')
return QStrBAD;
}
if(i == 0)
return QStrBAD; //This is INVERTED validator. If false - good, true - bad.
return QStrGOOD;
#undef QStrGOOD
#undef QStrBAD
}