(file) Return to CharSet.h CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / Common

 1 karl  1.4 //%2006////////////////////////////////////////////////////////////////////////
 2 mike  1.2 //
 3           // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
 4           // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
 5           // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
 6           // IBM Corp.; EMC Corporation, The Open Group.
 7           // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
 8           // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
 9           // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
10           // EMC Corporation; VERITAS Software Corporation; The Open Group.
11 karl  1.4 // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
12           // EMC Corporation; Symantec Corporation; The Open Group.
13 mike  1.2 //
14           // Permission is hereby granted, free of charge, to any person obtaining a copy
15           // of this software and associated documentation files (the "Software"), to
16           // deal in the Software without restriction, including without limitation the
17           // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
18           // sell copies of the Software, and to permit persons to whom the Software is
19           // furnished to do so, subject to the following conditions:
20 karl  1.4 // 
21 mike  1.2 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
22           // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
23           // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
24           // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
25           // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
26           // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
27           // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28           // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29           //
30           //==============================================================================
31           //
32           //%/////////////////////////////////////////////////////////////////////////////
33           
34           #ifndef Pegasus_CharSet_h
35           #define Pegasus_CharSet_h
36           
37           #include <Pegasus/Common/Config.h>
38           #include <Pegasus/Common/Linkage.h>
39           
40           PEGASUS_NAMESPACE_BEGIN
41           
42 kumpf 1.6 /*  This class provides fast methods for checking whether a character is a
43               member of a given character set (e.g., isAlpha()) and for translating
44               characters (e.g., toUpper()). These functions are faster than their system
45               library counterparts since they restrict their arguments to Uint8. For
46               example, the system isupper() takes an int argument and must check to see
47               if the int is between 0 and 128 before using it as an index into a table.
48               Also, nearly all system implementation require an extra AND operation since
49 mike  1.2     a single table is used to implement all of the ctype functions (one bit
50               per function).
51           
52 kumpf 1.6     This class also implements additional functions not supported by the
53 mike  1.2     system library, like isAlphaUnder(), and isAlNumUnder(). Expression like
54               this:
55           
56 kumpf 1.6         if (isalpha(c) || c == '_')
57                       ...
58 mike  1.2 
59               Become this:
60           
61 kumpf 1.6         if (CharSet::isAlphaUnder(c))
62                       ...
63 mike  1.2 
64               The optimization is even faster than it looks. Recall that isalpha() incurs
65               an extra branch and an extra AND operation, as explained above.
66           */
67 mike  1.5 class CharSet
68 mike  1.2 {
69           public:
70           
71               static Uint8 isAlphaUnder(Uint8 c) { return _isAlphaUnder[c]; }
72               static Uint8 isAlNumUnder(Uint8 c) { return _isAlNumUnder[c]; }
73               static Uint8 isSpace(Uint8 c) { return _isSpace[c]; }
74 kumpf 1.3     /**
75                   According to the XML specification, the space (0x20), carriage
76                   return (0x09), line feed (0x0D), and tab (0x0A) characters are
77                   considered white space.
78                */
79               static Uint8 isXmlWhiteSpace(Uint8 c) { return _isXmlWhiteSpace[c]; }
80 mike  1.2     static Uint8 toUpper(Uint8 c) { return _toUpper[c]; }
81               static Uint8 toLower(Uint8 c) { return _toLower[c]; }
82               static Uint8 isNotSpaceNorTerm(Uint8 c) { return _isNotSpaceNorTerm[c]; }
83           
84           private:
85               static const Uint8 _isAlphaUnder[256];
86               static const Uint8 _isAlNumUnder[256];
87               static const Uint8 _toUpper[256];
88               static const Uint8 _toLower[256];
89               static const Uint8 _isSpace[256];
90 kumpf 1.3     static const Uint8 _isXmlWhiteSpace[256];
91 mike  1.2     static const Uint8 _isNotSpaceNorTerm[256];
92           };
93           
94           PEGASUS_NAMESPACE_END
95           
96           #endif /* Pegasus_CharSet_h */

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2