source: icXML/icXML-devel/src/icxercesc/util/XMLChTranscoder.cpp @ 2721

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

Fix imports in icXML modified Xerces files

File size: 4.7 KB
Line 
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements.  See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License.  You may obtain a copy of the License at
8 *
9 *      http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18
19// ---------------------------------------------------------------------------
20//  Includes
21// ---------------------------------------------------------------------------
22#include <xercesc/util/BitOps.hpp>
23#include <icxercesc/util/XMLChTranscoder.hpp>
24#include <string.h>
25
26XERCES_CPP_NAMESPACE_BEGIN
27
28// ---------------------------------------------------------------------------
29//  XMLChTranscoder: Constructors and Destructor
30// ---------------------------------------------------------------------------
31XMLChTranscoder::XMLChTranscoder(const  XMLCh* const   encodingName
32                                , const XMLSize_t      blockSize
33                                , MemoryManager* const manager) :
34
35    XMLTranscoder(encodingName, blockSize, manager)
36{
37}
38
39
40XMLChTranscoder::~XMLChTranscoder()
41{
42}
43
44
45// ---------------------------------------------------------------------------
46//  XMLChTranscoder: Implementation of the transcoder API
47// ---------------------------------------------------------------------------
48XMLSize_t
49XMLChTranscoder::transcodeFrom( const   XMLByte* const          srcData
50                                , const XMLSize_t               srcCount
51                                ,       XMLCh* const            toFill
52                                , const XMLSize_t               maxChars
53                                ,       XMLSize_t&              bytesEaten
54                                ,       unsigned char* const    charSizes)
55{
56    //
57    //  Calculate the max chars we can do here. Its the lesser of the
58    //  max output chars and the number of chars in the source.
59    //
60    const XMLSize_t srcChars = srcCount / sizeof(XMLCh);
61    const XMLSize_t countToDo = srcChars < maxChars ? srcChars : maxChars;
62
63    //
64    //  Copy over the count of chars that we precalculated. Notice we
65    //  convert char count to byte count here!!!
66    //
67    memcpy(toFill, srcData, countToDo * sizeof(XMLCh));
68
69    // Set the bytes eaten
70    bytesEaten = countToDo * sizeof(XMLCh);
71
72    // Set the character sizes to the fixed size
73    memset(charSizes, sizeof(XMLCh), countToDo);
74
75    // Return the chars we transcoded
76    return countToDo;
77}
78
79XMLSize_t XMLChTranscoder::transcodeFrom
80(
81      const XMLByte* const          srcData
82    , const XMLSize_t               srcCount
83    ,       XMLBuffer &             toFill
84)
85{
86    toFill.reset();
87
88    const XMLSize_t srcChars = srcCount / sizeof(XMLCh);
89
90    toFill.ensureCapacity(srcChars);
91
92    //
93    //  Copy over the count of chars that we precalculated. Notice we
94    //  convert char count to byte count here!!!
95    //
96    memcpy(toFill.getRawBuffer(), srcData, srcCount);
97
98    toFill.setLen(srcCount);
99
100    // Return the chars we transcoded
101    return srcChars;
102}
103
104
105XMLSize_t
106XMLChTranscoder::transcodeTo(const  XMLCh* const    srcData
107                            , const XMLSize_t       srcCount
108                            ,       XMLByte* const  toFill
109                            , const XMLSize_t       maxBytes
110                            ,       XMLSize_t&      charsEaten
111                                , const UnRepOpts)
112{
113    //
114    //  Calculate the max chars we can do here. Its the lesser of the
115    //  max chars we can store in the output byte buffer, and the number
116    //  of chars in the source.
117    //
118    const XMLSize_t maxOutChars  = maxBytes / sizeof(XMLCh);
119    const XMLSize_t countToDo    = maxOutChars < srcCount
120                                    ? maxOutChars : srcCount;
121
122    //
123    //  Copy over the number of chars we calculated. Note that we have
124    //  to convert the char count to a byte count!!
125    //
126    memcpy(toFill, srcData, countToDo * sizeof(XMLCh));
127
128    // Set the chars eaten
129    charsEaten = countToDo;
130
131    // Return the bytes we transcoded
132    return countToDo * sizeof(XMLCh);
133}
134
135
136bool XMLChTranscoder::canTranscodeTo(const unsigned int)
137{
138    // We can handle anything
139    return true;
140}
141
142XERCES_CPP_NAMESPACE_END
Note: See TracBrowser for help on using the repository browser.