source: icXML/icXML-devel/src/icxmlc/XMLSymbolTable.cpp @ 2774

Last change on this file since 2774 was 2774, checked in by cameron, 6 years ago

Various fixes

File size: 4.5 KB
Line 
1/*
2 *  Copyright © 2012 International Characters.
3 *  This software is licensed to the public under the Open Software License 3.0.
4 *  icXML is a trademark of International Characters.
5 */
6
7/*
8 * @author Nigel Medforth, nigelm -at- interational-characters.com
9 * @version $Id: XMLSymbolTable.cpp 224 2012-12-12 03:31:56Z nigelm $
10 *
11 */
12
13#include <icxmlc/XMLSymbolTable.hpp>
14#include <icxmlc/XMLNameChars.hpp>
15#include <icxmlc/XMLNamespaceResolver.hpp>
16#include <icxmlc/XMLReferenceTable.c>
17#include <icxercesc/internal/XMLScanner.hpp>
18#include <icxercesc/framework/XMLBuffer.hpp>
19// #include <icxercesc/internal/XMLReader.hpp>
20#include <icxercesc/validators/schema/SchemaSymbols.hpp>
21#include <icxmlc/XMLConfig.hpp>
22
23XERCES_CPP_NAMESPACE_BEGIN
24
25gid_t XMLSymbolTable::add
26(
27    const XMLByte                       * const key
28    , const XMLSize_t                           length
29)
30{
31    XMLSymbol entry;
32    entry.fFlags = 0;
33    entry.fRawLength = length;
34    entry.fRawSymbol = fSymbolPool.insert(key, length);
35
36    DEBUG_SYMBOL_MESSAGE("XMLSymbolTable::add(" << entry.fRawSymbol << ',' << length << ')')
37
38    XMLBuffer symbol(length, fMemoryManager);
39    fTranscoder->transcodeFrom(key, length, symbol);
40    const XMLCh * symbolName = symbol.getRawBuffer();
41
42    /// VERIFY THAT THE CHARACTERS IN THE SYMBOL ARE LEGAL ACCORDING TO XML SPECIFICATIONS
43    if (unlikely(!XMLNameChar().test(symbolName, symbol.getLen())))
44    {
45        fScanner->emitError(XMLErrs::ExpectedElementName);
46    }
47
48
49    entry.fQName = new QName(symbolName, XMLNamespaceResolver::fEmptyUriId, fMemoryManager);
50
51    entry.fName = entry.fQName->getRawName();
52
53    if (fScanner->getDoNamespaces())
54    {
55        const XMLSize_t length = symbol.getLen();
56        int colon;
57        entry.fPrefixId = fNamespaceResolver->resolvePrefixId(symbolName, length, colon);
58        if (entry.fPrefixId < XMLNamespaceResolver::fPredefinedCount)
59        {
60            switch (entry.fPrefixId)
61            {
62                case XMLNamespaceResolver::fEmptyUriId:
63                    if (unlikely(XMLStringU::isXMLNS(symbolName)))
64                    {
65                        entry.fFlags |= XMLSymbol::XMLNS;
66                    }
67                    break;
68                case XMLNamespaceResolver::fXMLUriId:
69                    entry.fFlags |= XMLSymbol::XML;
70                    break;
71                case XMLNamespaceResolver::fXMLNSUriId:
72                    entry.fFlags |= XMLSymbol::XMLNS;
73                    ++colon;
74                    entry.fPrefixId = fNamespaceResolver->resolvePrefixId(&symbolName[colon], length - colon);
75                    if (unlikely(entry.fPrefixId == XMLNamespaceResolver::fXMLNSUriId))
76                    {
77                        fScanner->emitError(XMLErrs::NoUseOfxmlnsAsPrefix);
78                    }
79                    break;
80            }
81        }
82    }
83
84    return fSymbolTable.add(entry);
85}
86
87gid_t
88XMLSymbolTable::addInternal
89(
90    const XMLCh                         * const key
91    , const XMLSize_t                           length
92    , const XMLByte         * const unencodedKey
93    , const XMLSize_t               unencodedLength
94)
95{
96    XMLSymbol entry;
97    entry.fFlags = 0;
98    entry.fRawLength = unencodedLength;
99    entry.fRawSymbol = fSymbolPool.insert(unencodedKey, unencodedLength);
100
101    /// VERIFY THAT THE CHARACTERS IN THE SYMBOL ARE LEGAL ACCORDING TO XML SPECIFICATIONS
102    if (unlikely(!XMLNameChar().test(key, length)))
103    {
104        fScanner->emitError(XMLErrs::ExpectedElementName);
105    }
106
107    XMLCh * symbolName = XMLString::replicate(key, length, fMemoryManager);
108    symbolName[length] = 0;
109
110    entry.fQName = new QName(symbolName, XMLNamespaceResolver::fEmptyUriId, fMemoryManager);
111
112    entry.fName = entry.fQName->getRawName();
113
114    int colon;
115    entry.fPrefixId = fNamespaceResolver->resolvePrefixId(symbolName, length, colon);
116    if (entry.fPrefixId < XMLNamespaceResolver::fPredefinedCount)
117    {
118        switch (entry.fPrefixId)
119        {
120            case XMLNamespaceResolver::fEmptyUriId:
121                if (unlikely(XMLStringU::isXMLNS(symbolName)))
122                {
123                    entry.fFlags |= XMLSymbol::XMLNS;
124                }
125                break;
126            case XMLNamespaceResolver::fXMLUriId:
127                entry.fFlags |= XMLSymbol::XML;
128                break;
129            case XMLNamespaceResolver::fXMLNSUriId:
130                entry.fFlags |= XMLSymbol::XMLNS;
131                ++colon;
132                entry.fPrefixId = fNamespaceResolver->resolvePrefixId(&symbolName[colon], length - colon);
133                break;
134        }
135    }
136
137    return fSymbolTable.add(entry);
138}
139
140
141XERCES_CPP_NAMESPACE_END
Note: See TracBrowser for help on using the repository browser.