Skip to content

Commit 92e3320

Browse files
committed
Added main
1 parent 8f3011b commit 92e3320

File tree

7 files changed

+109
-2
lines changed

7 files changed

+109
-2
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
wsjcpp-validators
2+
tmp/*
3+
14
# Prerequisites
25
*.d
36

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ addons:
1616

1717
# Build steps
1818
script:
19+
- ./build_simple.sh
20+
- ./wsjcpp-validators [email protected]
1921
- cd unit-tests.wsjcpp
2022
- ./build_simple.sh
2123
- ./unit-tests

CMakeLists.txt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
cmake_minimum_required(VERSION 3.0)
2+
3+
project(wsjcpp-validators)
4+
5+
include(${CMAKE_CURRENT_SOURCE_DIR}/src.wsjcpp/CMakeLists.txt)
6+
7+
set(CMAKE_CXX_STANDARD 11)
8+
set(EXECUTABLE_OUTPUT_PATH ${wsjcpp-validators_SOURCE_DIR})
9+
10+
# Sources
11+
12+
# include header dirs
13+
list (APPEND WSJCPP_INCLUDE_DIRS "src")
14+
15+
list (APPEND WSJCPP_SOURCES "src/wsjcpp_validators.h")
16+
list (APPEND WSJCPP_SOURCES "src/wsjcpp_validators.cpp")
17+
list (APPEND WSJCPP_SOURCES "src/main.cpp")
18+
19+
include_directories(${WSJCPP_INCLUDE_DIRS})
20+
21+
add_executable ("wsjcpp-validators" ${WSJCPP_SOURCES})
22+
23+
target_link_libraries("wsjcpp-validators" -lpthread ${WSJCPP_LIBRARIES} )
24+
25+
install(
26+
TARGETS
27+
"wsjcpp-validators"
28+
RUNTIME DESTINATION
29+
/usr/bin
30+
)

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@
44

55
Classes for data validation
66

7+
## Completed classes
8+
9+
- `new WJSCppValidatorStringRegexpBase("testre", "^[a-zA-Z]+$")` - validate value by regular expression
10+
- `new WJSCppValidatorStringListBase("lang", {"en", "de", "ru"})` - validate value from a list
11+
- `new WJSCppValidatorEmail()` - validate format email
12+
- `new WJSCppValidatorUUID()` - validate format uuid
13+
- `new WJSCppValidatorStringLength(1,100)` - validate min length and max length
14+
715
## Integrate to your project
816

917
Just include this files:
@@ -20,6 +28,7 @@ $ wsjcpp install https://github.com/wsjcpp/wsjcpp-validators:master
2028
## Example usage
2129

2230
``` cpp
31+
2332
WJSCppValidatorUUID *pValidatorUUID = new WJSCppValidatorUUID();
2433
std::string sError = "";
2534
if (!pValidatorUUID->isValid("abcdef01-ABCD-EF23-1000-000000000001", sError)) {
@@ -29,7 +38,7 @@ if (!pValidatorUUID->isValid("abcdef01-ABCD-EF23-1000-000000000001", sError)) {
2938
3039
## Example for yuor implementations
3140
32-
```
41+
``` cpp
3342
class WJSCppValidatorUUID : public WJSCppValidatorStringRegexpBase {
3443
public:
3544
WJSCppValidatorUUID()

build_simple.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
3+
if [ ! -d tmp ]; then
4+
mkdir -p tmp
5+
fi
6+
7+
cd tmp
8+
cmake ..
9+
make
10+

src/main.cpp

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#include <string.h>
2+
#include <iostream>
3+
#include <algorithm>
4+
#include <wsjcpp_core.h>
5+
#include <wsjcpp_validators.h>
6+
7+
int main(int argc, char* argv[]) {
8+
std::string TAG = "MAIN";
9+
10+
if (!WSJCppCore::dirExists(".wsjcpp")) {
11+
WSJCppCore::makeDir(".wsjcpp");
12+
}
13+
std::string appLogPath = ".wsjcpp/logs";
14+
if (!WSJCppCore::dirExists(appLogPath)) {
15+
WSJCppCore::makeDir(appLogPath);
16+
}
17+
WSJCppLog::setPrefixLogFile("wsjcpp_validators");
18+
WSJCppLog::setLogDirectory(".wsjcpp/logs");
19+
20+
WSJCppLog::info(TAG, "Hello");
21+
WSJCppCore::init(
22+
argc, argv,
23+
std::string(WSJCPP_NAME),
24+
std::string(WSJCPP_VERSION),
25+
"Evgenii Sopov",
26+
""
27+
);
28+
if (argc != 2) {
29+
std::cout << "Usage " << argv[0] << " something" << std::endl;
30+
return -1;
31+
}
32+
std::string sArg1(argv[1]);
33+
34+
std::vector<WJSCppValidatorStringBase *> vValidators;
35+
vValidators.push_back(new WJSCppValidatorStringLength(5, 100));
36+
vValidators.push_back(new WJSCppValidatorStringLength(1, 5));
37+
vValidators.push_back(new WJSCppValidatorEmail());
38+
vValidators.push_back(new WJSCppValidatorUUID());
39+
vValidators.push_back(new WJSCppValidatorStringListBase("lang", {"en", "de", "ru"}));
40+
vValidators.push_back(new WJSCppValidatorStringRegexpBase("testre", "^[a-zA-Z]+$"));
41+
42+
for (int i = 0; i < vValidators.size(); i++) {
43+
WJSCppValidatorStringBase *pValidator = vValidators[i];
44+
std::string sError;
45+
if (pValidator->isValid(sArg1, sError)) {
46+
WSJCppLog::ok(TAG, "ok -> [" + pValidator->getTypeName() + "]: '" + sArg1 + "'");
47+
} else {
48+
WSJCppLog::err(TAG, "fail -> [" + pValidator->getTypeName() + "]: '" + sArg1 + "' - " + sError);
49+
}
50+
}
51+
52+
return 0;
53+
}

src/wsjcpp_validators.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ WJSCppValidatorStringRegexpBase::WJSCppValidatorStringRegexpBase(const std::stri
3434

3535
bool WJSCppValidatorStringRegexpBase::isValid(const std::string &sValue, std::string &sError) {
3636
if (!std::regex_match(sValue, m_rxValidator)) {
37-
sError = "Value must have " + getTypeName();
37+
sError = getTypeName() + " - Value must match regular expression " + m_sValidator;
3838
return false;
3939
}
4040
return true;

0 commit comments

Comments
 (0)