1
/***************************************************************************
2
* (c) J�rgen Riegel (juergen.riegel@web.de) *
4
* This file is part of the FreeCAD CAx development system. *
6
* This program is free software; you can redistribute it and/or modify *
7
* it under the terms of the GNU Library General Public License (LGPL) *
8
* as published by the Free Software Foundation; either version 2 of *
9
* the License, or (at your option) any later version. *
10
* for detail see the LICENCE text file. *
12
* FreeCAD is distributed in the hope that it will be useful, *
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15
* GNU Library General Public License for more details. *
17
* You should have received a copy of the GNU Library General Public *
18
* License along with FreeCAD; if not, write to the Free Software *
19
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
22
* Juergen Riegel 2002 *
23
***************************************************************************/
26
#ifndef __XMLTOOLS_H__
27
#define __XMLTOOLS_H__
29
// Std. configurations
35
#include <xercesc/util/XercesDefs.hpp>
36
#include <xercesc/util/XercesVersion.hpp>
37
#include <xercesc/util/XMLString.hpp>
38
#include <xercesc/util/PlatformUtils.hpp>
39
#include <xercesc/util/TransService.hpp>
41
#include <Base/Exception.h>
43
XERCES_CPP_NAMESPACE_BEGIN
47
XERCES_CPP_NAMESPACE_END
50
//**************************************************************************
51
//**************************************************************************
53
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
58
StrX(const XMLCh* const toTranscode);
62
const char* c_str() const;
65
// This is the local code page form of the string.
69
inline std::ostream& operator<<(std::ostream& target, const StrX& toDump)
71
target << toDump.c_str();
75
inline StrX::StrX(const XMLCh* const toTranscode)
77
// Call the private transcoding method
78
fLocalForm = XERCES_CPP_NAMESPACE_QUALIFIER XMLString::transcode(toTranscode);
81
// WideCharToMultiByte(CP_UTF8,0,toTranscode,-1,fLocaleForm)
83
// fUnicodeForm = XERCES_CPP_NAMESPACE_QUALIFIER XMLString::transcode(toTranscode);
89
//delete [] fLocalForm; // dont work on VC7.1
90
XERCES_CPP_NAMESPACE_QUALIFIER XMLString::release(&fLocalForm);
94
// -----------------------------------------------------------------------
96
// -----------------------------------------------------------------------
97
inline const char* StrX::c_str() const
102
//**************************************************************************
103
//**************************************************************************
105
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
110
StrXUTF8(const XMLCh* const toTranscode);
113
const char* c_str() const;
114
/// string which holds the UTF-8 form
118
static std::auto_ptr<XERCES_CPP_NAMESPACE::XMLTranscoder> transcoder;
119
// This is the local code page form of the string.
122
inline std::ostream& operator<<(std::ostream& target, const StrXUTF8& toDump)
124
target << toDump.c_str();
128
inline StrXUTF8::StrXUTF8(const XMLCh* const toTranscode)
130
XERCES_CPP_NAMESPACE_USE;
131
if(!transcoder.get()){
132
XMLTransService::Codes res;
133
transcoder.reset(XERCES_CPP_NAMESPACE_QUALIFIER XMLPlatformUtils::fgTransService->makeNewTranscoderFor(XERCES_CPP_NAMESPACE_QUALIFIER XMLRecognizer::UTF_8, res, 4096, XERCES_CPP_NAMESPACE_QUALIFIER XMLPlatformUtils::fgMemoryManager));
134
if (res != XMLTransService::Ok)
135
throw Base::Exception("Cant create UTF-8 encoder in StrXUTF8::StrXUTF8()");
139
static XMLByte outBuff[128];
140
#if (XERCES_VERSION_MAJOR == 2)
141
unsigned int outputLength;
142
unsigned int eaten = 0;
143
unsigned int offset = 0;
144
unsigned int inputLength = XMLString::stringLen(toTranscode);
146
XMLSize_t outputLength;
148
XMLSize_t offset = 0;
149
XMLSize_t inputLength = XMLString::stringLen(toTranscode);
154
outputLength = transcoder->transcodeTo(toTranscode + offset, inputLength, outBuff, 128, eaten, XMLTranscoder::UnRep_RepChar);
155
str.append((const char*)outBuff, outputLength);
157
inputLength -= eaten;
161
// -----------------------------------------------------------------------
163
// -----------------------------------------------------------------------
164
inline const char* StrXUTF8::c_str() const
170
//**************************************************************************
171
//**************************************************************************
173
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
179
/// Constructors and Destructor
180
XStr(const char* const toTranscode);
186
const XMLCh* unicodeForm() const;
189
/// This is the Unicode XMLCh format of the string.
194
inline XStr::XStr(const char* const toTranscode)
196
// Call the private transcoding method
199
// WideCharToMultiByte()
201
fUnicodeForm = XERCES_CPP_NAMESPACE_QUALIFIER XMLString::transcode(toTranscode);
207
//delete [] fUnicodeForm;
208
XERCES_CPP_NAMESPACE_QUALIFIER XMLString::release(&fUnicodeForm);
212
// -----------------------------------------------------------------------
214
// -----------------------------------------------------------------------
215
inline const XMLCh* XStr::unicodeForm() const
220
#endif // __XMLTOOLS_H__