Annotation of parser3/src/main/pa_pool.C, revision 1.25
1.13 paf 1: /** @file
1.14 paf 2: Parser: pool class.
3:
1.10 paf 4: Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com)
1.14 paf 5:
1.11 paf 6: Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf)
1.2 paf 7: */
1.25 ! parser 8: static const char *RCSId="$Id: pa_pool.C,v 1.24 2001/09/21 07:30:25 parser Exp $";
1.1 paf 9:
10: #include "pa_pool.h"
1.7 paf 11: #include "pa_exception.h"
1.22 parser 12: #include "pa_common.h"
13:
14: #include <PlatformSupport/DOMStringHelper.hpp>
15: #include <util/PlatformUtils.hpp>
16:
17: Pool::Pool(void *astorage) :
18: fstorage(astorage), fcontext(0), ftag(0), fexception(0),
1.25 ! parser 19: transcoder(0) {
! 20: charset=new(*this) String(*this, "UTF-8");
1.22 parser 21: }
22:
1.24 parser 23: Pool::~Pool() {
24: delete transcoder;
1.22 parser 25: }
1.1 paf 26:
1.21 parser 27: void Pool::fail_alloc(size_t size) const {
1.8 paf 28: fexception->_throw(0, 0,
1.7 paf 29: 0,
1.9 paf 30: "failed to allocate %u bytes", size);
1.7 paf 31: }
1.21 parser 32:
33: void Pool::fail_register_cleanup() const {
34: fexception->_throw(0, 0,
35: 0,
36: "failed to register cleanup");
1.22 parser 37: }
38:
1.25 ! parser 39: void Pool::set_charset(const String &new_charset) {
! 40: if(new_charset!=*charset) {
1.24 parser 41: delete transcoder; transcoder=0; // flag "we need new transcoder"
1.25 ! parser 42: charset=&new_charset; // for this charset
1.22 parser 43: }
44: }
45:
46: void Pool::update_transcoder() {
47: if(transcoder)
48: return;
49:
50: XMLTransService::Codes resValue;
1.25 ! parser 51: transcoder=XMLPlatformUtils::fgTransService->makeNewTranscoderFor(charset->cstr(), resValue, 60);
1.24 parser 52: if(!transcoder)
53: THROW(0, 0,
1.25 ! parser 54: charset,
1.24 parser 55: "unsupported encoding");
1.22 parser 56: }
57:
58:
1.25 ! parser 59: const char *Pool::transcode_cstr(const XalanDOMString& s) {
1.22 parser 60: update_transcoder();
61:
1.24 parser 62: const unsigned int len=s.size()*2;
1.22 parser 63: XMLByte* dest=(XMLByte *)malloc((len+1)*sizeof(XMLByte));
64: bool error=true;
65: try {
66: if(transcoder) {
67: unsigned int charsEaten;
68: unsigned int size=transcoder->transcodeTo(
69: s.c_str(), s.length(),
1.24 parser 70: dest, len,
1.22 parser 71: charsEaten,
1.24 parser 72: XMLTranscoder::UnRep_RepChar //UnRep_Throw
1.22 parser 73: );
74: dest[size]=0;
75: error=false;
76: }
77: } catch(...) {
78: }
79: if(error) {
1.24 parser 80: memset(dest, '?', s.size());
81: ((char *)dest)[s.size()]=0;
1.22 parser 82: }
83: return (const char *)dest;
1.25 ! parser 84: }
! 85: String& Pool::transcode(const XalanDOMString& s) {
! 86: return *new(*this) String(*this, transcode_cstr(s));
1.22 parser 87: }
88:
89: void Pool::_throw(const String *source, const XSLException& e) {
90: if(e.getURI().empty())
91: THROW(0, 0,
92: source,
93: "%s (%s)",
94: transcode(e.getMessage()), // message for exception
95: transcode(e.getType()) // type of exception
96: );
97: else
98: THROW(0, 0,
99: source,
100: "%s (%s) %s(%d:%d)'",
101: transcode(e.getMessage()), // message for exception
102: transcode(e.getType()), // type of exception
103:
104: transcode(e.getURI()), // URI for the associated document, if any
105: e.getLineNumber(), // line number, or -1 if unknown
106: e.getColumnNumber() // column number, or -1 if unknown
107: );
108: }
E-mail: