Skip to content

Commit 39f6d61

Browse files
committed
Fixed #7 #8
1 parent 5572724 commit 39f6d61

14 files changed

+679
-81
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Classes for data validation
1414
- `new WSJCppValidatorJWT()` - validate format of JWT
1515
- `new WSJCppValidatorDate()` - validate format date like 'YYYY-MM-DD'
1616
- `new WSJCppValidatorTimeH24()` - validate format date like 'HH:mm:ss' (24 hours)
17+
- `new WSJCppValidatorDateTime()` - validate format date like 'YYYY-MM-DD\THH:mm:ss'
1718
- `new WSJCppValidatorBase64()` - validate format of base64
1819
- `new WSJCppValidatorNumber()` - validate format of number
1920
- `new WSJCppValidatorHex()` - validate hex value
@@ -22,6 +23,8 @@ Classes for data validation
2223

2324
Just include this files:
2425

26+
- src/wsjcpp_core/wsjcpp_core.h
27+
- src/wsjcpp_core/wsjcpp_core.cpp
2528
- src/wsjcpp_validators.h
2629
- src/wsjcpp_validators.cpp
2730

src.wsjcpp/wsjcpp_core/wsjcpp_core.cpp

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -421,44 +421,6 @@ std::string WSJCppCore::createUuid() {
421421

422422
// ---------------------------------------------------------------------
423423

424-
bool WSJCppCore::isIPv4(const std::string& str) {
425-
int n = 0;
426-
std::string s[4] = {"", "", "", ""};
427-
for (int i = 0; i < str.length(); i++) {
428-
char c = str[i];
429-
if (n > 3) {
430-
return false;
431-
}
432-
if (c >= '0' && c <= '9') {
433-
s[n] += c;
434-
} else if (c == '.') {
435-
n++;
436-
} else {
437-
return false;
438-
}
439-
}
440-
for (int i = 0; i < 4; i++) {
441-
if (s[i].length() > 3) {
442-
return false;
443-
}
444-
int p = std::stoi(s[i]);
445-
if (p > 255 || p < 0) {
446-
return false;
447-
}
448-
}
449-
return true;
450-
}
451-
452-
// ---------------------------------------------------------------------
453-
454-
bool WSJCppCore::isIPv6(const std::string& str) {
455-
unsigned char buf[sizeof(struct in6_addr)];
456-
bool isValid = inet_pton(AF_INET6, str.c_str(), buf);
457-
return isValid;
458-
}
459-
460-
// ---------------------------------------------------------------------
461-
462424
unsigned long WSJCppCore::convertVoidToULong(void *p) {
463425
unsigned long ret = *(unsigned long *)p;
464426
return ret;

src.wsjcpp/wsjcpp_core/wsjcpp_core.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ class WSJCppCore {
4949

5050
static void initRandom();
5151
static std::string createUuid();
52-
static bool isIPv4(const std::string& str);
53-
static bool isIPv6(const std::string& str);
5452

5553
static unsigned long convertVoidToULong(void *p);
5654
static std::string getPointerAsHex(void *p);

src/main.cpp

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ int main(int argc, char* argv[]) {
1717
WSJCppLog::setPrefixLogFile("wsjcpp_validators");
1818
WSJCppLog::setLogDirectory(".wsjcpp/logs");
1919

20-
WSJCppLog::info(TAG, "Hello");
20+
// WSJCppLog::info(TAG, "Hello");
2121
WSJCppCore::init(
2222
argc, argv,
2323
std::string(WSJCPP_NAME),
@@ -32,28 +32,36 @@ int main(int argc, char* argv[]) {
3232
std::string sArg1(argv[1]);
3333

3434
std::vector<WSJCppValidatorStringBase *> vValidators;
35-
vValidators.push_back(new WSJCppValidatorStringLength(5, 100));
36-
vValidators.push_back(new WSJCppValidatorStringLength(1, 5));
35+
// vValidators.push_back(new WSJCppValidatorStringLength(5, 100));
36+
// vValidators.push_back(new WSJCppValidatorStringLength(1, 5));
3737
vValidators.push_back(new WSJCppValidatorEmail());
3838
vValidators.push_back(new WSJCppValidatorUUID());
3939
vValidators.push_back(new WSJCppValidatorStringListBase("lang", {"en", "de", "ru"}));
4040
vValidators.push_back(new WSJCppValidatorStringRegexpBase("testre", "^[a-zA-Z]+$"));
4141
vValidators.push_back(new WSJCppValidatorJWT());
4242
vValidators.push_back(new WSJCppValidatorDate());
4343
vValidators.push_back(new WSJCppValidatorTimeH24());
44+
vValidators.push_back(new WSJCppValidatorDateTime());
45+
// vValidators.push_back(new WSJCppValidatorURL());
4446
vValidators.push_back(new WSJCppValidatorBase64());
4547
vValidators.push_back(new WSJCppValidatorNumber());
4648
vValidators.push_back(new WSJCppValidatorHex());
4749

50+
std::string sResult = "";
4851
for (int i = 0; i < vValidators.size(); i++) {
4952
WSJCppValidatorStringBase *pValidator = vValidators[i];
5053
std::string sError;
54+
if (sResult.size() > 0) {
55+
sResult += ",";
56+
}
5157
if (pValidator->isValid(sArg1, sError)) {
52-
WSJCppLog::ok(TAG, "ok -> [" + pValidator->getTypeName() + "]: '" + sArg1 + "'");
58+
sResult += " +" + pValidator->getTypeName();
59+
// WSJCppLog::ok(TAG, "ok -> [" + pValidator->getTypeName() + "]: '" + sArg1 + "'");
5360
} else {
54-
WSJCppLog::err(TAG, "fail -> [" + pValidator->getTypeName() + "]: '" + sArg1 + "' - " + sError);
61+
sResult += " -" + pValidator->getTypeName();
62+
// WSJCppLog::err(TAG, "fail -> [" + pValidator->getTypeName() + "]: '" + sArg1 + "' - " + sError);
5563
}
5664
}
57-
65+
std::cout << sResult << std::endl;
5866
return 0;
5967
}

0 commit comments

Comments
 (0)