source: NonGTP/Xerces/xercesc/util/XMLChar.hpp @ 188

Revision 188, 14.9 KB checked in by mattausch, 19 years ago (diff)

added xercesc to support

Line 
1/*
2 * The Apache Software License, Version 1.1
3 *
4 * Copyright (c) 2002 The Apache Software Foundation.  All rights
5 * reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * 1. Redistributions of source code must retain the above copyright
12 *    notice, this list of conditions and the following disclaimer.
13 *
14 * 2. Redistributions in binary form must reproduce the above copyright
15 *    notice, this list of conditions and the following disclaimer in
16 *    the documentation and/or other materials provided with the
17 *    distribution.
18 *
19 * 3. The end-user documentation included with the redistribution,
20 *    if any, must include the following acknowledgment:
21 *       "This product includes software developed by the
22 *        Apache Software Foundation (http://www.apache.org/)."
23 *    Alternately, this acknowledgment may appear in the software itself,
24 *    if and wherever such third-party acknowledgments normally appear.
25 *
26 * 4. The names "Xerces" and "Apache Software Foundation" must
27 *    not be used to endorse or promote products derived from this
28 *    software without prior written permission. For written
29 *    permission, please contact apache\@apache.org.
30 *
31 * 5. Products derived from this software may not be called "Apache",
32 *    nor may "Apache" appear in their name, without prior written
33 *    permission of the Apache Software Foundation.
34 *
35 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
36 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
37 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
38 * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
39 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
41 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
42 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
43 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
44 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
45 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
46 * SUCH DAMAGE.
47 * ====================================================================
48 *
49 * This software consists of voluntary contributions made by many
50 * individuals on behalf of the Apache Software Foundation, and was
51 * originally based on software copyright (c) 1999, International
52 * Business Machines, Inc., http://www.ibm.com .  For more information
53 * on the Apache Software Foundation, please see
54 * <http://www.apache.org/>.
55 */
56
57/*
58 * $Log: XMLChar.hpp,v $
59 * Revision 1.3  2004/01/29 11:48:47  cargilld
60 * Code cleanup changes to get rid of various compiler diagnostic messages.
61 *
62 * Revision 1.2  2003/08/14 02:57:27  knoaman
63 * Code refactoring to improve performance of validation.
64 *
65 * Revision 1.1  2002/12/20 22:10:21  tng
66 * XML 1.1
67 *
68 */
69
70#if !defined(XMLCHAR_HPP)
71#define XMLCHAR_HPP
72
73#include <xercesc/util/XMLUniDefs.hpp>
74
75XERCES_CPP_NAMESPACE_BEGIN
76
77// ---------------------------------------------------------------------------
78//  This file defines Char and utility that conforms to XML 1.0 and XML 1.1
79// ---------------------------------------------------------------------------
80// Masks for the fgCharCharsTable1_0 array
81const XMLByte   gLetterCharMask             = 0x1;
82const XMLByte   gFirstNameCharMask          = 0x2;
83const XMLByte   gNameCharMask               = 0x4;
84const XMLByte   gPlainContentCharMask       = 0x8;
85const XMLByte   gSpecialStartTagCharMask    = 0x10;
86const XMLByte   gControlCharMask            = 0x20;
87const XMLByte   gXMLCharMask                = 0x40;
88const XMLByte   gWhitespaceCharMask         = 0x80;
89
90// ---------------------------------------------------------------------------
91//  This class is for XML 1.0
92// ---------------------------------------------------------------------------
93class XMLUTIL_EXPORT XMLChar1_0
94{
95public:
96    // -----------------------------------------------------------------------
97    //  Public, static methods, check the string
98    // -----------------------------------------------------------------------
99    static bool isAllSpaces
100    (
101        const   XMLCh* const    toCheck
102        , const unsigned int    count
103    );
104
105    static bool containsWhiteSpace
106    (
107        const   XMLCh* const    toCheck
108        , const unsigned int    count
109    );
110
111    static bool isValidName
112    (
113        const   XMLCh* const    toCheck
114        , const unsigned int    count
115    );
116
117    static bool isValidNCName
118    (
119        const   XMLCh* const    toCheck
120        , const unsigned int    count
121    );
122
123    static bool isValidQName
124    (
125        const   XMLCh* const    toCheck
126        , const unsigned int    count
127    );
128
129    // -----------------------------------------------------------------------
130    //  Public, static methods, check the XMLCh
131    //  surrogate pair is assumed if second parameter is not null
132    // -----------------------------------------------------------------------
133    static bool isXMLLetter(const XMLCh toCheck, const XMLCh toCheck2 = 0);
134    static bool isFirstNameChar(const XMLCh toCheck, const XMLCh toCheck2 = 0);
135    static bool isNameChar(const XMLCh toCheck, const XMLCh toCheck2 = 0);
136    static bool isPlainContentChar(const XMLCh toCheck, const XMLCh toCheck2 = 0);
137    static bool isSpecialStartTagChar(const XMLCh toCheck, const XMLCh toCheck2 = 0);
138    static bool isXMLChar(const XMLCh toCheck, const XMLCh toCheck2 = 0);
139    static bool isWhitespace(const XMLCh toCheck);
140    static bool isWhitespace(const XMLCh toCheck, const XMLCh toCheck2);
141    static bool isControlChar(const XMLCh toCheck, const XMLCh toCheck2 = 0);
142
143    static bool isPublicIdChar(const XMLCh toCheck, const XMLCh toCheck2 = 0);
144
145    // -----------------------------------------------------------------------
146    //  Special Non-conformant Public, static methods
147    // -----------------------------------------------------------------------
148    /**
149      * Return true if NEL (0x85) and LSEP (0x2028) to be treated as white space char.
150      */
151    static bool isNELRecognized();
152
153    /**
154      * Method to enable NEL (0x85) and LSEP (0x2028) to be treated as white space char.
155      */
156    static void enableNELWS();
157
158private:
159    // -----------------------------------------------------------------------
160    //  Unimplemented constructors and operators
161    // -----------------------------------------------------------------------
162    XMLChar1_0();
163
164    // -----------------------------------------------------------------------
165    //  Static data members
166    //
167    //  fgCharCharsTable1_0
168    //      The character characteristics table. Bits in each byte, represent
169    //      the characteristics of each character. It is generated via some
170    //      code and then hard coded into the cpp file for speed.
171    //
172    //  fNEL
173    //      Flag to respresents whether NEL and LSEP newline recognition is enabled
174    //      or disabled
175    // -----------------------------------------------------------------------
176    static XMLByte  fgCharCharsTable1_0[0x10000];
177    static bool     enableNEL;
178
179    friend class XMLReader;
180};
181
182
183// ---------------------------------------------------------------------------
184//  XMLReader: Public, static methods
185// ---------------------------------------------------------------------------
186inline bool XMLChar1_0::isXMLLetter(const XMLCh toCheck, const XMLCh toCheck2)
187{
188    if (!toCheck2)
189        return ((fgCharCharsTable1_0[toCheck] & gLetterCharMask) != 0);
190    return false;
191}
192
193inline bool XMLChar1_0::isFirstNameChar(const XMLCh toCheck, const XMLCh toCheck2)
194{
195    if (!toCheck2)
196        return ((fgCharCharsTable1_0[toCheck] & gFirstNameCharMask) != 0);
197    return false;
198}
199
200inline bool XMLChar1_0::isNameChar(const XMLCh toCheck, const XMLCh toCheck2)
201{
202    if (!toCheck2)
203        return ((fgCharCharsTable1_0[toCheck] & gNameCharMask) != 0);
204    return false;
205}
206
207inline bool XMLChar1_0::isPlainContentChar(const XMLCh toCheck, const XMLCh toCheck2)
208{
209    if (!toCheck2)
210        return ((fgCharCharsTable1_0[toCheck] & gPlainContentCharMask) != 0);
211    else {
212        if ((toCheck >= 0xD800) && (toCheck <= 0xDBFF))
213           if ((toCheck2 >= 0xDC00) && (toCheck2 <= 0xDFFF))
214               return true;
215    }
216    return false;
217}
218
219
220inline bool XMLChar1_0::isSpecialStartTagChar(const XMLCh toCheck, const XMLCh toCheck2)
221{
222    if (!toCheck2)
223        return ((fgCharCharsTable1_0[toCheck] & gSpecialStartTagCharMask) != 0);
224    return false;
225}
226
227inline bool XMLChar1_0::isXMLChar(const XMLCh toCheck, const XMLCh toCheck2)
228{
229    if (!toCheck2)
230        return ((fgCharCharsTable1_0[toCheck] & gXMLCharMask) != 0);
231    else {
232        if ((toCheck >= 0xD800) && (toCheck <= 0xDBFF))
233           if ((toCheck2 >= 0xDC00) && (toCheck2 <= 0xDFFF))
234               return true;
235    }
236    return false;
237}
238
239inline bool XMLChar1_0::isWhitespace(const XMLCh toCheck)
240{
241    return ((fgCharCharsTable1_0[toCheck] & gWhitespaceCharMask) != 0);
242}
243
244inline bool XMLChar1_0::isWhitespace(const XMLCh toCheck, const XMLCh toCheck2)
245{
246    if (!toCheck2)
247        return ((fgCharCharsTable1_0[toCheck] & gWhitespaceCharMask) != 0);
248    return false;
249}
250
251inline bool XMLChar1_0::isControlChar(const XMLCh toCheck, const XMLCh toCheck2)
252{
253    if (!toCheck2)
254        return ((fgCharCharsTable1_0[toCheck] & gControlCharMask) != 0);
255    return false;
256}
257
258inline bool XMLChar1_0::isNELRecognized() {
259
260    return enableNEL;
261}
262
263
264// ---------------------------------------------------------------------------
265//  This class is for XML 1.1
266// ---------------------------------------------------------------------------
267class XMLUTIL_EXPORT XMLChar1_1
268{
269public:
270    // -----------------------------------------------------------------------
271    //  Public, static methods, check the string
272    // -----------------------------------------------------------------------
273    static bool isAllSpaces
274    (
275        const   XMLCh* const    toCheck
276        , const unsigned int    count
277    );
278
279    static bool containsWhiteSpace
280    (
281        const   XMLCh* const    toCheck
282        , const unsigned int    count
283    );
284
285    static bool isValidName
286    (
287        const   XMLCh* const    toCheck
288        , const unsigned int    count
289    );
290
291    static bool isValidNCName
292    (
293        const   XMLCh* const    toCheck
294        , const unsigned int    count
295    );
296
297    static bool isValidQName
298    (
299        const   XMLCh* const    toCheck
300        , const unsigned int    count
301    );
302
303    // -----------------------------------------------------------------------
304    //  Public, static methods, check the XMLCh
305    // -----------------------------------------------------------------------
306    static bool isXMLLetter(const XMLCh toCheck, const XMLCh toCheck2 = 0);
307    static bool isFirstNameChar(const XMLCh toCheck, const XMLCh toCheck2 = 0);
308    static bool isNameChar(const XMLCh toCheck, const XMLCh toCheck2 = 0);
309    static bool isPlainContentChar(const XMLCh toCheck, const XMLCh toCheck2 = 0);
310    static bool isSpecialStartTagChar(const XMLCh toCheck, const XMLCh toCheck2 = 0);
311    static bool isXMLChar(const XMLCh toCheck, const XMLCh toCheck2 = 0);
312    static bool isWhitespace(const XMLCh toCheck, const XMLCh toCheck2 = 0);
313    static bool isControlChar(const XMLCh toCheck, const XMLCh toCheck2 = 0);
314
315    static bool isPublicIdChar(const XMLCh toCheck, const XMLCh toCheck2 = 0);
316
317private:
318    // -----------------------------------------------------------------------
319    //  Unimplemented constructors and operators
320    // -----------------------------------------------------------------------
321    XMLChar1_1();
322
323    // -----------------------------------------------------------------------
324    //  Static data members
325    //
326    //  fgCharCharsTable1_1
327    //      The character characteristics table. Bits in each byte, represent
328    //      the characteristics of each character. It is generated via some
329    //      code and then hard coded into the cpp file for speed.
330    //
331    // -----------------------------------------------------------------------
332    static XMLByte  fgCharCharsTable1_1[0x10000];
333
334    friend class XMLReader;
335};
336
337
338// ---------------------------------------------------------------------------
339//  XMLReader: Public, static methods
340// ---------------------------------------------------------------------------
341inline bool XMLChar1_1::isXMLLetter(const XMLCh toCheck, const XMLCh toCheck2)
342{
343    if (!toCheck2)
344        return ((fgCharCharsTable1_1[toCheck] & gLetterCharMask) != 0);
345    return false;
346}
347
348inline bool XMLChar1_1::isFirstNameChar(const XMLCh toCheck, const XMLCh toCheck2)
349{
350    if (!toCheck2)
351        return ((fgCharCharsTable1_1[toCheck] & gFirstNameCharMask) != 0);
352    else {
353        if ((toCheck >= 0xD800) && (toCheck <= 0xDB7F))
354           if ((toCheck2 >= 0xDC00) && (toCheck2 <= 0xDFFF))
355               return true;
356    }
357    return false;
358}
359
360inline bool XMLChar1_1::isNameChar(const XMLCh toCheck, const XMLCh toCheck2)
361{
362    if (!toCheck2)
363        return ((fgCharCharsTable1_1[toCheck] & gNameCharMask) != 0);
364    else {
365        if ((toCheck >= 0xD800) && (toCheck <= 0xDB7F))
366           if ((toCheck2 >= 0xDC00) && (toCheck2 <= 0xDFFF))
367               return true;
368    }
369    return false;
370}
371
372inline bool XMLChar1_1::isPlainContentChar(const XMLCh toCheck, const XMLCh toCheck2)
373{
374    if (!toCheck2)
375        return ((fgCharCharsTable1_1[toCheck] & gPlainContentCharMask) != 0);
376    else {
377        if ((toCheck >= 0xD800) && (toCheck <= 0xDBFF))
378           if ((toCheck2 >= 0xDC00) && (toCheck2 <= 0xDFFF))
379               return true;
380    }
381    return false;
382}
383
384
385inline bool XMLChar1_1::isSpecialStartTagChar(const XMLCh toCheck, const XMLCh toCheck2)
386{
387    if (!toCheck2)
388        return ((fgCharCharsTable1_1[toCheck] & gSpecialStartTagCharMask) != 0);
389    return false;
390}
391
392inline bool XMLChar1_1::isXMLChar(const XMLCh toCheck, const XMLCh toCheck2)
393{
394    if (!toCheck2)
395        return ((fgCharCharsTable1_1[toCheck] & gXMLCharMask) != 0);
396    else {
397        if ((toCheck >= 0xD800) && (toCheck <= 0xDBFF))
398           if ((toCheck2 >= 0xDC00) && (toCheck2 <= 0xDFFF))
399               return true;
400    }
401    return false;
402}
403
404inline bool XMLChar1_1::isWhitespace(const XMLCh toCheck, const XMLCh toCheck2)
405{
406    if (!toCheck2)
407        return ((fgCharCharsTable1_1[toCheck] & gWhitespaceCharMask) != 0);
408    return false;
409}
410
411inline bool XMLChar1_1::isControlChar(const XMLCh toCheck, const XMLCh toCheck2)
412{
413    if (!toCheck2)
414        return ((fgCharCharsTable1_1[toCheck] & gControlCharMask) != 0);
415    return false;
416}
417
418
419XERCES_CPP_NAMESPACE_END
420
421#endif
Note: See TracBrowser for help on using the repository browser.