/src/libe-book/src/lib/FictionBook2Token.cpp
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* |
3 | | * This file is part of the libe-book 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 <cstring> |
11 | | |
12 | | #include "FictionBook2Token.h" |
13 | | |
14 | | using std::strlen; |
15 | | |
16 | | namespace libebook |
17 | | { |
18 | | namespace |
19 | | { |
20 | | |
21 | | #include "FictionBook2Token.inc" |
22 | | |
23 | | } |
24 | | } |
25 | | |
26 | | namespace libebook |
27 | | { |
28 | | |
29 | | const FictionBook2TokenData *getFictionBook2Token(const char *const str, const unsigned length) |
30 | 7.41M | { |
31 | 7.41M | if (!str) |
32 | 0 | return nullptr; |
33 | 7.41M | return reinterpret_cast<const FictionBook2TokenData *>(Perfect_Hash::in_word_set(str, length)); |
34 | 7.41M | } |
35 | | |
36 | | const FictionBook2TokenData *getFictionBook2Token(const char *const str) |
37 | 7.38M | { |
38 | 7.38M | if (!str) |
39 | 0 | return nullptr; |
40 | 7.38M | return getFictionBook2Token(str, (unsigned) strlen(str)); |
41 | 7.38M | } |
42 | | |
43 | | const FictionBook2TokenData *getFictionBook2Token(const unsigned char *const str) |
44 | 7.38M | { |
45 | 7.38M | if (!str) |
46 | 0 | return nullptr; |
47 | 7.38M | return getFictionBook2Token(reinterpret_cast<const char *>(str)); |
48 | 7.38M | } |
49 | | |
50 | | int getFictionBook2TokenID(const FictionBook2TokenData &token) |
51 | 3.28M | { |
52 | 3.28M | return getFictionBook2TokenID(&token); |
53 | 3.28M | } |
54 | | |
55 | | int getFictionBook2TokenID(const FictionBook2TokenData *const token) |
56 | 3.65M | { |
57 | 3.65M | return token ? token->id : INVALID_TOKEN; |
58 | 3.65M | } |
59 | | |
60 | | int getFictionBook2TokenID(const char *str, const unsigned length) |
61 | 39.4k | { |
62 | 39.4k | return getFictionBook2TokenID(getFictionBook2Token(str, length)); |
63 | 39.4k | } |
64 | | |
65 | | int getFictionBook2TokenID(const char *str) |
66 | 39.4k | { |
67 | 39.4k | if (!str) |
68 | 1 | return 0; |
69 | 39.4k | return getFictionBook2TokenID(str, (unsigned) strlen(str)); |
70 | 39.4k | } |
71 | | |
72 | | int getFictionBook2TokenID(const unsigned char *str) |
73 | 0 | { |
74 | 0 | return getFictionBook2TokenID(reinterpret_cast<const char *>(str)); |
75 | 0 | } |
76 | | |
77 | | const char *getFictionBook2TokenName(const FictionBook2TokenData &token) |
78 | 0 | { |
79 | 0 | return getFictionBook2TokenName(&token); |
80 | 0 | } |
81 | | |
82 | | const char *getFictionBook2TokenName(const FictionBook2TokenData *const token) |
83 | 0 | { |
84 | 0 | return token ? token->name : nullptr; |
85 | 0 | } |
86 | | |
87 | | const char *getFictionBook2TokenName(const char *str, const unsigned length) |
88 | 0 | { |
89 | 0 | return getFictionBook2TokenName(getFictionBook2Token(str, length)); |
90 | 0 | } |
91 | | |
92 | | const char *getFictionBook2TokenName(const char *str) |
93 | 0 | { |
94 | 0 | return getFictionBook2TokenName(str, (unsigned) strlen(str)); |
95 | 0 | } |
96 | | |
97 | | const char *getFictionBook2TokenName(const unsigned char *str) |
98 | 0 | { |
99 | 0 | return getFictionBook2TokenName(reinterpret_cast<const char *>(str)); |
100 | 0 | } |
101 | | |
102 | | } |
103 | | |
104 | | /* vim:set shiftwidth=2 softtabstop=2 expandtab: */ |