1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /*
3  * This file is part of the libetonyek project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  */
9 
10 #include "KEY1Token.h"
11 
12 #include <cassert>
13 #include <cstring>
14 #include <memory>
15 
16 #include "IWORKTokenizerBase.h"
17 
18 using std::strlen;
19 
20 namespace libetonyek
21 {
22 namespace
23 {
24 
25 #include "KEY1Token.inc"
26 
27 }
28 }
29 
30 namespace libetonyek
31 {
32 
33 namespace
34 {
35 
36 class Tokenizer : public IWORKTokenizerBase
37 {
38   int queryId(const char *name) const override;
39 };
40 
queryId(const char * const name) const41 int Tokenizer::queryId(const char *const name) const
42 {
43   assert(name);
44 
45   const size_t length = strlen(name);
46   assert(0 < length);
47 
48   const Token *const token = Perfect_Hash::in_word_set(name, (unsigned) length);
49   return token ? token->id : 0;
50 }
51 
52 }
53 
54 namespace KEY1Token
55 {
56 
getTokenizer()57 const IWORKTokenizer &getTokenizer()
58 {
59   static Tokenizer tokenizer;
60   return tokenizer;
61 }
62 
63 }
64 
65 }
66 
67 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */
68