1
/***************************************************************************
2
* Copyright (c) 2011 Jürgen Riegel <juergen.riegel@web.de> *
4
* This file is part of the FreeCAD CAx development system. *
6
* This library is free software; you can redistribute it and/or *
7
* modify it under the terms of the GNU Library General Public *
8
* License as published by the Free Software Foundation; either *
9
* version 2 of the License, or (at your option) any later version. *
11
* This library is distributed in the hope that it will be useful, *
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14
* GNU Library General Public License for more details. *
16
* You should have received a copy of the GNU Library General Public *
17
* License along with this library; see the file COPYING.LIB. If not, *
18
* write to the Free Software Foundation, Inc., 59 Temple Place, *
19
* Suite 330, Boston, MA 02111-1307, USA *
21
***************************************************************************/
24
#include "PreCompiled.h"
29
XERCES_CPP_NAMESPACE_USE
31
std::unique_ptr<XMLTranscoder> XMLTools::transcoder; // NOLINT
33
void XMLTools::initialize()
36
XMLTransService::Codes res {};
37
transcoder.reset(XMLPlatformUtils::fgTransService->makeNewTranscoderFor(
41
XMLPlatformUtils::fgMemoryManager));
42
if (res != XMLTransService::Ok) {
43
throw Base::UnicodeError("Can't create transcoder");
48
std::string XMLTools::toStdString(const XMLCh* const toTranscode)
55
static XMLByte outBuff[128];
56
XMLSize_t outputLength = 0;
59
XMLSize_t inputLength = XMLString::stringLen(toTranscode);
62
outputLength = transcoder->transcodeTo(toTranscode + offset,
67
XMLTranscoder::UnRep_RepChar);
68
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
69
str.append(reinterpret_cast<const char*>(outBuff), outputLength);
73
// Bail out if nothing more was produced
74
if (outputLength == 0) {
82
std::basic_string<XMLCh> XMLTools::toXMLString(const char* const fromTranscode)
84
std::basic_string<XMLCh> str;
91
static XMLCh outBuff[128];
92
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
93
const XMLByte* xmlBytes = reinterpret_cast<const XMLByte*>(fromTranscode);
94
XMLSize_t outputLength = 0;
97
XMLSize_t inputLength = std::string(fromTranscode).size();
99
unsigned char* charSizes = new unsigned char[inputLength];
100
while (inputLength) {
101
outputLength = transcoder->transcodeFrom(xmlBytes + offset,
107
str.append(outBuff, outputLength);
109
inputLength -= eaten;
111
// Bail out if nothing more was produced
112
if (outputLength == 0) {
121
void XMLTools::terminate()