generate-tlds.sh 912 B

123456789101112131415161718192021222324252627282930313233343536
  1. #!/bin/sh -e
  2. create_header_file() {
  3. echo "#pragma once
  4. #include <string>
  5. // This file was automatically generated with generate-tld.sh, do not edit manually!
  6. namespace QuickMedia {
  7. bool is_tld(const std::string &str);
  8. }
  9. "
  10. }
  11. create_source_file() {
  12. echo "#include \"Tlds.hpp\"
  13. #include <unordered_set>
  14. // This file was automatically generated with generate-tld.sh, do not edit manually!
  15. namespace QuickMedia {
  16. // Source: https://data.iana.org/TLD/tlds-alpha-by-domain.txt
  17. static const std::unordered_set<std::string> TLDS = {"
  18. curl -sfL https://data.iana.org/TLD/tlds-alpha-by-domain.txt | grep -v '^#' | tr '[:upper:]' '[:lower:]' | awk '{ printf " \"%s\",\n", $1 }'
  19. echo " };
  20. "
  21. echo " bool is_tld(const std::string &str) {
  22. return TLDS.find(str) != TLDS.end();
  23. }
  24. }"
  25. }
  26. create_header_file > generated/Tlds.hpp
  27. create_source_file > generated/Tlds.cpp