Coverage Report

Created: 2025-06-13 07:02

/src/xerces-c/src/xercesc/util/XMLChTranscoder.cpp
Line
Count
Source (jump to first uncovered 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 <xercesc/util/XMLChTranscoder.hpp>
24
#include <string.h>
25
26
XERCES_CPP_NAMESPACE_BEGIN
27
28
// ---------------------------------------------------------------------------
29
//  XMLChTranscoder: Constructors and Destructor
30
// ---------------------------------------------------------------------------
31
XMLChTranscoder::XMLChTranscoder(const  XMLCh* const   encodingName
32
                                , const XMLSize_t      blockSize
33
                                , MemoryManager* const manager) :
34
35
365k
    XMLTranscoder(encodingName, blockSize, manager)
36
365k
{
37
365k
}
38
39
40
XMLChTranscoder::~XMLChTranscoder()
41
365k
{
42
365k
}
43
44
45
// ---------------------------------------------------------------------------
46
//  XMLChTranscoder: Implementation of the transcoder API
47
// ---------------------------------------------------------------------------
48
XMLSize_t
49
XMLChTranscoder::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
381k
{
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
381k
    const XMLSize_t srcChars = srcCount / sizeof(XMLCh);
61
381k
    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
381k
    memcpy(toFill, srcData, countToDo * sizeof(XMLCh));
68
69
    // Set the bytes eaten
70
381k
    bytesEaten = countToDo * sizeof(XMLCh);
71
72
    // Set the character sizes to the fixed size
73
381k
    memset(charSizes, sizeof(XMLCh), countToDo);
74
75
    // Return the chars we transcoded
76
381k
    return countToDo;
77
381k
}
78
79
80
XMLSize_t
81
XMLChTranscoder::transcodeTo(const  XMLCh* const    srcData
82
                            , const XMLSize_t       srcCount
83
                            ,       XMLByte* const  toFill
84
                            , const XMLSize_t       maxBytes
85
                            ,       XMLSize_t&      charsEaten
86
                                , const UnRepOpts)
87
0
{
88
    //
89
    //  Calculate the max chars we can do here. Its the lesser of the
90
    //  max chars we can store in the output byte buffer, and the number
91
    //  of chars in the source.
92
    //
93
0
    const XMLSize_t maxOutChars  = maxBytes / sizeof(XMLCh);
94
0
    const XMLSize_t countToDo    = maxOutChars < srcCount
95
0
                                    ? maxOutChars : srcCount;
96
97
    //
98
    //  Copy over the number of chars we calculated. Note that we have
99
    //  to convert the char count to a byte count!!
100
    //
101
0
    memcpy(toFill, srcData, countToDo * sizeof(XMLCh));
102
103
    // Set the chars eaten
104
0
    charsEaten = countToDo;
105
106
    // Return the bytes we transcoded
107
0
    return countToDo * sizeof(XMLCh);
108
0
}
109
110
111
bool XMLChTranscoder::canTranscodeTo(const unsigned int)
112
0
{
113
    // We can handle anything
114
0
    return true;
115
0
}
116
117
XERCES_CPP_NAMESPACE_END