aboutsummaryrefslogtreecommitdiff
path: root/generate-tlds.sh
blob: 3304a38e057e0375930fb7e518f581442bf90532 (plain)
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
#!/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