aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/tld/tld.cpp
blob: dbfd9d5332123c2c6ef85e8d0b20fe9fbf023b9a (plain) (blame)
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
37
38
39
40
41
42
43
44
45
46
47
48
#include "tld.h"

#include <library/cpp/digest/lower_case/hash_ops.h>
 
#include <util/generic/hash_set.h>
#include <util/generic/singleton.h> 

namespace NTld {
    namespace { 
#include <library/cpp/tld/tld.inc>

        using TCiHash = THashSet<TStringBuf, TCIOps, TCIOps>; 
 
        struct TTLDHash: public TCiHash { 
            TTLDHash() { 
                for (auto tld = GetTlds(); *tld; ++tld) { 
                    insert(*tld); 
                } 
            } 
        }; 

        struct TVeryGoodTld: public TCiHash { 
            TVeryGoodTld() { 
                auto domains = { 
                    "am", "az", "biz", "by", "com", "cz", "de", "ec", "fr", "ge", "gov", 
                    "gr", "il", "info", "kg", "kz", "mobi", "net", "nu", "org", "lt", "lv", 
                    "md", "ru", "su", "tr", "ua", "uk", "uz", "ws", "xn--p1ai", "рф"}; 

                for (auto d : domains) { 
                    insert(d); 
                } 
            }
        }; 
    } 
 
    const char* const* GetTlds() { 
        return TopLevelDomains; 
    } 

    bool IsTld(const TStringBuf& s) { 
        return Default<TTLDHash>().contains(s);
    } 

    bool IsVeryGoodTld(const TStringBuf& s) { 
        return Default<TVeryGoodTld>().contains(s);
    } 
 
}