tld.h 851 B

12345678910111213141516171819202122232425262728
  1. #pragma once
  2. #include <util/generic/strbuf.h>
  3. namespace NTld {
  4. const char* const* GetTlds();
  5. // Note that FindTld() returns empty string when @host is single domain label (without '.').
  6. // If you need whole @host for such case, you can use GetZone() from library/cpp/string_utils/url/url.h
  7. inline TStringBuf FindTld(const TStringBuf& host) {
  8. size_t p = host.rfind('.');
  9. return p != TStringBuf::npos ? host.SubStr(p + 1) : TStringBuf();
  10. }
  11. bool IsTld(const TStringBuf& tld);
  12. inline bool InTld(const TStringBuf& host) {
  13. return IsTld(FindTld(host));
  14. }
  15. // check if @s belongs to a "good" subset of reliable TLDs, defined in tld.cpp
  16. bool IsVeryGoodTld(const TStringBuf& tld);
  17. inline bool InVeryGoodTld(const TStringBuf& host) {
  18. return IsVeryGoodTld(FindTld(host));
  19. }
  20. }