|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 /* |
|
18 * Licensed to the Apache Software Foundation (ASF) under one or more |
|
19 * contributor license agreements. See the NOTICE file distributed with |
|
20 * this work for additional information regarding copyright ownership. |
|
21 * The ASF licenses this file to You under the Apache License, Version 2.0 |
|
22 * (the "License"); you may not use this file except in compliance with |
|
23 * the License. You may obtain a copy of the License at |
|
24 * |
|
25 * http://www.apache.org/licenses/LICENSE-2.0 |
|
26 * |
|
27 * Unless required by applicable law or agreed to in writing, software |
|
28 * distributed under the License is distributed on an "AS IS" BASIS, |
|
29 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
30 * See the License for the specific language governing permissions and |
|
31 * limitations under the License. |
|
32 */ |
|
33 |
|
34 /* |
|
35 * $Id: HexBin.hpp 568078 2007-08-21 11:43:25Z amassari $ |
|
36 */ |
|
37 |
|
38 #ifndef HEXBIN_HPP |
|
39 #define HEXBIN_HPP |
|
40 |
|
41 #include <xercesc/util/PlatformUtils.hpp> |
|
42 |
|
43 XERCES_CPP_NAMESPACE_BEGIN |
|
44 |
|
45 class XMLUTIL_EXPORT HexBin |
|
46 { |
|
47 public : |
|
48 //@{ |
|
49 |
|
50 /** |
|
51 * return the length of hexData in terms of HexBinary. |
|
52 * |
|
53 * @param hexData A string containing the HexBinary |
|
54 * |
|
55 * return: -1 if it contains any invalid HexBinary |
|
56 * the length of the HexNumber otherwise. |
|
57 */ |
|
58 |
|
59 static int getDataLength(const XMLCh* const hexData); |
|
60 |
|
61 /** |
|
62 * check an array of data against the Hex table. |
|
63 * |
|
64 * @param hexData A string containing the HexBinary |
|
65 * |
|
66 * return: false if it contains any invalid HexBinary |
|
67 * true otherwise. |
|
68 */ |
|
69 |
|
70 static bool isArrayByteHex(const XMLCh* const hexData); |
|
71 |
|
72 /** |
|
73 * get canonical representation |
|
74 * |
|
75 * Caller is responsible for the proper deallcation |
|
76 * of the string returned. |
|
77 * |
|
78 * @param hexData A string containing the HexBinary |
|
79 * @param manager The MemoryManager to use to allocate the string |
|
80 * |
|
81 * return: the canonical representation of the HexBinary |
|
82 * if it is a valid HexBinary, |
|
83 * 0 otherwise |
|
84 */ |
|
85 |
|
86 static XMLCh* getCanonicalRepresentation |
|
87 ( |
|
88 const XMLCh* const hexData |
|
89 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager |
|
90 ); |
|
91 |
|
92 /** |
|
93 * Decodes HexBinary data into XMLCh |
|
94 * |
|
95 * NOTE: The returned buffer is dynamically allocated and is the |
|
96 * responsibility of the caller to delete it when not longer needed. |
|
97 * You can call XMLString::release to release this returned buffer. |
|
98 * |
|
99 * If a memory manager is provided, ask the memory manager to de-allocate |
|
100 * the returned buffer. |
|
101 * |
|
102 * @param hexData HexBinary data in XMLCh stream. |
|
103 * @param manager client provided memory manager |
|
104 * @return Decoded binary data in XMLCh stream, |
|
105 * or NULL if input data can not be decoded. |
|
106 * @see XMLString::release(XMLCh**) |
|
107 * @deprecated use decodeToXMLByte instead. |
|
108 */ |
|
109 |
|
110 static XMLCh* decode( |
|
111 const XMLCh* const hexData |
|
112 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager |
|
113 ); |
|
114 |
|
115 /** |
|
116 * Decodes HexBinary data into XMLByte |
|
117 * |
|
118 * NOTE: The returned buffer is dynamically allocated and is the |
|
119 * responsibility of the caller to delete it when not longer needed. |
|
120 * You can call XMLString::release to release this returned buffer. |
|
121 * |
|
122 * If a memory manager is provided, ask the memory manager to de-allocate |
|
123 * the returned buffer. |
|
124 * |
|
125 * @param hexData HexBinary data in XMLCh stream. |
|
126 * @param manager client provided memory manager |
|
127 * @return Decoded binary data in XMLByte stream, |
|
128 * or NULL if input data can not be decoded. |
|
129 * @see XMLString::release(XMLByte**) |
|
130 */ |
|
131 static XMLByte* decodeToXMLByte( |
|
132 const XMLCh* const hexData |
|
133 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager |
|
134 ); |
|
135 |
|
136 |
|
137 //@} |
|
138 |
|
139 private : |
|
140 |
|
141 // ----------------------------------------------------------------------- |
|
142 // Helper methods |
|
143 // ----------------------------------------------------------------------- |
|
144 |
|
145 static void init(); |
|
146 |
|
147 static bool isHex(const XMLCh& octect); |
|
148 |
|
149 // ----------------------------------------------------------------------- |
|
150 // Unimplemented constructors and operators |
|
151 // ----------------------------------------------------------------------- |
|
152 HexBin(); |
|
153 HexBin(const HexBin&); |
|
154 HexBin& operator=(const HexBin&); |
|
155 |
|
156 // ----------------------------------------------------------------------- |
|
157 // Private data members |
|
158 // |
|
159 // isInitialized |
|
160 // |
|
161 // set once hexNumberTable is initalized. |
|
162 // |
|
163 // hexNumberTable |
|
164 // |
|
165 // arrany holding valid hexNumber character. |
|
166 // |
|
167 // ----------------------------------------------------------------------- |
|
168 static bool isInitialized; |
|
169 static XMLByte hexNumberTable[]; |
|
170 }; |
|
171 |
|
172 XERCES_CPP_NAMESPACE_END |
|
173 |
|
174 #endif |