add is link checker
This commit is contained in:
parent
97b30f32f2
commit
dc28f6b6db
11
bin/main.cpp
11
bin/main.cpp
@ -19,6 +19,7 @@
|
|||||||
#include "security/validate_email.hpp"
|
#include "security/validate_email.hpp"
|
||||||
#include "security/uuid.hpp"
|
#include "security/uuid.hpp"
|
||||||
#include "security/is_string.hpp"
|
#include "security/is_string.hpp"
|
||||||
|
#include "security/is_link.hpp"
|
||||||
|
|
||||||
// for example
|
// for example
|
||||||
int f(int a)
|
int f(int a)
|
||||||
@ -298,4 +299,14 @@ int main(int argc, char *argv[])
|
|||||||
query = hack::utils::make_query("super_function", 1, 123.3f, js);
|
query = hack::utils::make_query("super_function", 1, 123.3f, js);
|
||||||
hack::log()("query", query);
|
hack::log()("query", query);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{// ex: is link
|
||||||
|
std::string link { "https://google.com" };
|
||||||
|
if (hack::security::is_link(link))
|
||||||
|
hack::log()("is link");
|
||||||
|
|
||||||
|
link = "https//google.com";
|
||||||
|
if (!hack::security::is_link(link))
|
||||||
|
hack::error()("no link");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
14
src/security/is_link.hpp
Normal file
14
src/security/is_link.hpp
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <uuid/uuid.h>
|
||||||
|
#include <regex>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace hack::security
|
||||||
|
{
|
||||||
|
inline bool is_link(const std::string& s)
|
||||||
|
{
|
||||||
|
static const std::regex e("^(https?:\\/\\/)?([\\da-z\\.-]+)\\.([a-z\\.]{2,6})([\\/\\w \\.-]*)*\\/?$", std::regex_constants::icase);
|
||||||
|
return std::regex_match (s, e);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user