--- parser3/src/main/pa_pool.C 2001/10/11 14:57:53 1.31 +++ parser3/src/main/pa_pool.C 2001/10/19 14:15:23 1.35 @@ -4,7 +4,7 @@ Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com) Author: Alexander Petrosyan (http://design.ru/paf) - $Id: pa_pool.C,v 1.31 2001/10/11 14:57:53 parser Exp $ + $Id: pa_pool.C,v 1.35 2001/10/19 14:15:23 parser Exp $ */ #include "pa_pool.h" @@ -16,7 +16,7 @@ #endif Pool::Pool(void *astorage) : - fstorage(astorage), fcontext(0), ftag(0), fexception(0) + fstorage(astorage), fcontext(0), ftag(0) #ifdef XML , transcoder(0) #endif @@ -35,13 +35,13 @@ Pool::~Pool() { } void Pool::fail_alloc(size_t size) const { - fexception->_throw(0, 0, + throw Exception(0, 0, 0, "failed to allocate %u bytes", size); } void Pool::fail_register_cleanup() const { - fexception->_throw(0, 0, + throw Exception(0, 0, 0, "failed to register cleanup"); } @@ -63,7 +63,7 @@ void Pool::update_transcoder() { XMLTransService::Codes resValue; transcoder=XMLPlatformUtils::fgTransService->makeNewTranscoderFor(charset->cstr(), resValue, 60); if(!transcoder) - THROW(0, 0, + throw Exception(0, 0, charset, "unsupported encoding"); } @@ -86,11 +86,8 @@ const char *Pool::transcode_cstr(const X dest[size]=0; error=false; } - } catch(...) { - } - if(error) { - memset(dest, '?', s.size()); - ((char *)dest)[s.size()]=0; + } catch(XMLException& e) { + Exception::convert(*this, 0, e); } return (const char *)dest; } @@ -98,4 +95,36 @@ String& Pool::transcode(const XalanDOMSt return *new(*this) String(*this, transcode_cstr(s)); } +/// @test who would free up result? +XalanDOMString& Pool::transcode_buf(const char *buf, size_t buf_size) { + update_transcoder(); + + unsigned int dest_size=0; + XMLCh* dest=(XMLCh *)malloc((buf_size+1)*sizeof(XMLCh)); + unsigned char *charSizes=(unsigned char *)malloc(buf_size*sizeof(unsigned char)); + XalanDOMString *result; + try { + if(transcoder) { + unsigned int bytesEaten; + unsigned int dest_size=transcoder->transcodeFrom( + (unsigned char *)buf, + (const unsigned int)buf_size, + dest, (const unsigned int)buf_size, + bytesEaten, + charSizes + ); + result=new XalanDOMString(dest, dest_size); + } + } catch(XMLException& e) { + Exception::convert(*this, 0, e); + } + + return *result; +} +XalanDOMString& Pool::transcode(const String& s) { + const char *cstr=s.cstr(String::UL_XML); + + return transcode_buf(cstr, strlen(cstr)); +} + #endif