Added reload of levels on F7 (Update levelpack) to ease the test of changes.
[enigmagame.git] / src / XMLtoUtf8.cc
blobc09c8082ba338a083ab32f74864ec70159b63864
1 /*
2 * Copyright (C) 2005, 2006 Ronald Lamprecht
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 #include "XMLtoUtf8.hh"
21 #include "main.hh"
22 #include <xercesc/util/XMLString.hpp>
23 #include <xercesc/util/TransService.hpp>
25 XERCES_CPP_NAMESPACE_USE
27 namespace enigma
29 XMLtoUtf8::XMLtoUtf8(const XMLCh* const toTranscode) {
30 #if _XERCES_VERSION >= 30000
31 XMLSize_t srcLength = XMLString::stringLen(toTranscode) + 1;
32 // make safe assumptions on utf-8 size
33 XMLSize_t maxDestLength = 3 * srcLength;
34 XMLSize_t charsEaten;
35 XMLSize_t destLength;
36 #else
37 unsigned int srcLength = XMLString::stringLen(toTranscode) + 1;
38 // make safe assumptions on utf-8 size
39 unsigned int maxDestLength = 3 * srcLength;
40 unsigned int charsEaten;
41 unsigned int destLength;
42 #endif
43 // make a buffer - size does not matter - the object is temporary
44 utf8String = new char[maxDestLength];
45 // transcode to utf-8 -- there are no unrepresentable chars
46 destLength = app.xmlUtf8Transcoder->transcodeTo(toTranscode, srcLength,
47 (XMLByte *)utf8String, maxDestLength,
48 charsEaten, XMLTranscoder::UnRep_RepChar);
49 if (charsEaten < srcLength)
50 // an assert - should never occur
51 Log << "XMLtoUtf8: incomplete transcoding - only "<< charsEaten <<
52 " of " << srcLength << "characters were processed!" << std::endl;
55 XMLtoUtf8::~XMLtoUtf8() {
56 delete [] utf8String;
59 const char* XMLtoUtf8::c_str() const {
60 return utf8String;
62 } //namespace enigma