Line data Source code
1 : /*************************************************************************
2 : *
3 : * Copyright (c) 2010 Kohei Yoshida
4 : *
5 : * Permission is hereby granted, free of charge, to any person
6 : * obtaining a copy of this software and associated documentation
7 : * files (the "Software"), to deal in the Software without
8 : * restriction, including without limitation the rights to use,
9 : * copy, modify, merge, publish, distribute, sublicense, and/or sell
10 : * copies of the Software, and to permit persons to whom the
11 : * Software is furnished to do so, subject to the following
12 : * conditions:
13 : *
14 : * The above copyright notice and this permission notice shall be
15 : * included in all copies or substantial portions of the Software.
16 : *
17 : * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 : * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
19 : * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 : * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
21 : * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22 : * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 : * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24 : * OTHER DEALINGS IN THE SOFTWARE.
25 : *
26 : ************************************************************************/
27 :
28 : #include "orcus/tokens.hpp"
29 : #include "orcus/pstring.hpp"
30 :
31 : using namespace std;
32 :
33 : namespace orcus {
34 :
35 8 : tokens::tokens(const char** token_names, size_t token_name_count, const char** nstoken_names, size_t nstoken_name_count) :
36 : m_token_names(token_names),
37 : m_nstoken_names(nstoken_names),
38 : m_token_name_count(token_name_count),
39 8 : m_nstoken_name_count(nstoken_name_count)
40 : {
41 2064 : for (size_t i = 0; i < m_token_name_count; ++i)
42 : {
43 : m_tokens.insert(
44 : token_map_type::value_type(
45 6168 : pstring(m_token_names[i]), static_cast<xml_token_t>(i)));
46 : }
47 :
48 32 : for (size_t i = 0; i < m_nstoken_name_count; ++i)
49 : {
50 : m_nstokens.insert(
51 : nstoken_map_type::value_type(
52 96 : pstring(m_nstoken_names[i]), static_cast<xmlns_token_t>(i)));
53 : }
54 8 : }
55 :
56 0 : bool tokens::is_valid_token(xml_token_t token) const
57 : {
58 0 : return token != XML_UNKNOWN_TOKEN;
59 : }
60 :
61 0 : xml_token_t tokens::get_token(const pstring& name) const
62 : {
63 0 : token_map_type::const_iterator itr = m_tokens.find(name);
64 0 : if (itr == m_tokens.end())
65 : return XML_UNKNOWN_TOKEN;
66 0 : return itr->second;
67 : }
68 :
69 0 : const char* tokens::get_token_name(xml_token_t token) const
70 : {
71 0 : if (static_cast<size_t>(token) >= m_token_name_count)
72 : return "";
73 :
74 0 : return m_token_names[token];
75 : }
76 :
77 0 : bool tokens::is_valid_nstoken(xmlns_token_t token) const
78 : {
79 0 : return token != XMLNS_UNKNOWN_TOKEN;
80 : }
81 :
82 0 : xmlns_token_t tokens::get_nstoken(const pstring& name) const
83 : {
84 0 : nstoken_map_type::const_iterator itr = m_nstokens.find(name);
85 0 : if (itr == m_nstokens.end())
86 : return XMLNS_UNKNOWN_TOKEN;
87 0 : return itr->second;
88 : }
89 :
90 0 : const char* tokens::get_nstoken_name(xmlns_token_t token) const
91 : {
92 0 : if (static_cast<size_t>(token) >= m_nstoken_name_count)
93 : return "";
94 :
95 0 : return m_nstoken_names[token];
96 : }
97 :
98 11160 : }
|