Annotation of parser3/src/main/pa_pool.C, revision 1.24
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.24 ! parser 8: static const char *RCSId="$Id: pa_pool.C,v 1.23 2001/09/20 14:34:42 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.24 ! parser 19: scharset(0), charset("UTF-8"), transcoder(0) {
1.22 parser 20: }
21:
1.24 ! parser 22: Pool::~Pool() {
! 23: delete transcoder;
1.22 parser 24: }
1.1 paf 25:
1.21 parser 26: void Pool::fail_alloc(size_t size) const {
1.8 paf 27: fexception->_throw(0, 0,
1.7 paf 28: 0,
1.9 paf 29: "failed to allocate %u bytes", size);
1.7 paf 30: }
1.21 parser 31:
32: void Pool::fail_register_cleanup() const {
33: fexception->_throw(0, 0,
34: 0,
35: "failed to register cleanup");
1.22 parser 36: }
37:
1.24 ! parser 38: void Pool::set_charset(const String &new_scharset) {
! 39: if(new_scharset!=charset) {
! 40: delete transcoder; transcoder=0; // flag "we need new transcoder"
! 41: scharset=&new_scharset; // for this charset
! 42: charset=new_scharset.cstr();
1.22 parser 43: }
44: }
45:
46: void Pool::update_transcoder() {
47: if(transcoder)
48: return;
49:
50: XMLTransService::Codes resValue;
1.24 ! parser 51: transcoder=XMLPlatformUtils::fgTransService->makeNewTranscoderFor(charset, resValue, 60);
! 52: if(!transcoder)
! 53: THROW(0, 0,
! 54: scharset,
! 55: "unsupported encoding");
1.22 parser 56: }
57:
58:
59: const char *Pool::transcode(const XalanDOMString& s) {
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;
84: }
85:
86: void Pool::_throw(const String *source, const XSLException& e) {
87: if(e.getURI().empty())
88: THROW(0, 0,
89: source,
90: "%s (%s)",
91: transcode(e.getMessage()), // message for exception
92: transcode(e.getType()) // type of exception
93: );
94: else
95: THROW(0, 0,
96: source,
97: "%s (%s) %s(%d:%d)'",
98: transcode(e.getMessage()), // message for exception
99: transcode(e.getType()), // type of exception
100:
101: transcode(e.getURI()), // URI for the associated document, if any
102: e.getLineNumber(), // line number, or -1 if unknown
103: e.getColumnNumber() // column number, or -1 if unknown
104: );
105: }
E-mail: