diff options
author | dec05eba <dec05eba@protonmail.com> | 2021-06-04 19:59:56 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2021-06-04 19:59:56 +0200 |
commit | 2acab72c413dadfe58b7b2e5ddcb304e6a9f1843 (patch) | |
tree | 363fd4991664b663539997b0d64ce7858e3a7a64 /generate-tlds.sh | |
parent | 59e4ce5c35e7e5a73d61e7111e8d4f07d63b7056 (diff) |
Move tld code to generated directory (and automatically generate it with a script)
Diffstat (limited to 'generate-tlds.sh')
-rwxr-xr-x | generate-tlds.sh | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/generate-tlds.sh b/generate-tlds.sh new file mode 100755 index 0000000..3304a38 --- /dev/null +++ b/generate-tlds.sh @@ -0,0 +1,36 @@ +#!/bin/sh -e + +create_header_file() { + echo "#pragma once + +#include <string> + +// This file was automatically generated with generate-tld.sh, do not edit manually! + +namespace QuickMedia { + bool is_tld(const std::string &str); +} +" +} + +create_source_file() { + echo "#include \"Tlds.hpp\" +#include <unordered_set> + +// This file was automatically generated with generate-tld.sh, do not edit manually! + +namespace QuickMedia { + // Source: https://data.iana.org/TLD/tlds-alpha-by-domain.txt + static const std::unordered_set<std::string> TLDS = {" + curl -sfL https://data.iana.org/TLD/tlds-alpha-by-domain.txt | grep -v '^#' | tr '[:upper:]' '[:lower:]' | awk '{ printf " \"%s\",\n", $1 }' + echo " }; +" + + echo " bool is_tld(const std::string &str) { + return TLDS.find(str) != TLDS.end(); + } +}" +} + +create_header_file > generated/Tlds.hpp +create_source_file > generated/Tlds.cpp
\ No newline at end of file |