Annotation of parser3/src/main/pa_pool.C, revision 1.22

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.22    ! parser      8: static const char *RCSId="$Id: pa_pool.C,v 1.21 2001/09/15 13:20:22 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),
        !            19:        charset("UTF-8"), transcoder(0) {
        !            20:        register_cleanup(Pool_cleanup, this);
        !            21: }
        !            22: 
        !            23: void Pool_cleanup(void *pool) {
        !            24:        //_asm int 3;
        !            25:        static_cast<Pool *>(pool)->cleanup();
        !            26: }
1.1       paf        27: 
1.21      parser     28: void Pool::fail_alloc(size_t size) const {
1.8       paf        29:        fexception->_throw(0, 0,
1.7       paf        30:                0,
1.9       paf        31:                "failed to allocate %u bytes", size);
1.7       paf        32: }
1.21      parser     33: 
                     34: void Pool::fail_register_cleanup() const {
                     35:        fexception->_throw(0, 0,
                     36:                0,
                     37:                "failed to register cleanup");
1.22    ! parser     38: }
        !            39: 
        !            40: void Pool::set_charset(const String &new_charset) {
        !            41:        set_charset(new_charset.cstr());
        !            42: }
        !            43: void Pool::set_charset(const char *new_charset) {
        !            44:        if(charset && strcasecmp(new_charset, charset)!=0) {
        !            45:                delete transcoder;  transcoder=0;
        !            46:                charset=new_charset;
        !            47:        }
        !            48: }
        !            49: 
        !            50: void Pool::update_transcoder() {
        !            51:        if(transcoder)
        !            52:                return;
        !            53: 
        !            54:        XMLTransService::Codes resValue;
        !            55:        transcoder=XMLPlatformUtils::fgTransService->makeNewTranscoderFor(charset, resValue, 100);
        !            56: }
        !            57: 
        !            58: 
        !            59: const char *Pool::transcode(const XalanDOMString& s) { 
        !            60:        update_transcoder();
        !            61: 
        !            62:        const unsigned int len=s.size(); // multibyte-char languages not supported for now
        !            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(),
        !            70:                                dest,
        !            71:                                len-1,
        !            72:                                charsEaten,
        !            73:                                XMLTranscoder::UnRep_Throw
        !            74:                        );
        !            75:                        dest[size]=0;
        !            76:                        error=false;
        !            77:                }
        !            78:        } catch(...) {
        !            79:        }
        !            80:        if(error) {
        !            81:                memset(dest, '?', len-1);
        !            82:                ((char *)dest)[len]=0;
        !            83:        }
        !            84:        return (const char *)dest;
        !            85: }
        !            86: 
        !            87: void Pool::_throw(const String *source, const XSLException& e) {
        !            88:        if(e.getURI().empty())
        !            89:                THROW(0, 0,
        !            90:                        source,
        !            91:                        "%s (%s)",
        !            92:                                transcode(e.getMessage()),  // message for exception
        !            93:                                transcode(e.getType()) // type of exception
        !            94:                );
        !            95:        else
        !            96:                THROW(0, 0,
        !            97:                        source,
        !            98:                        "%s (%s) %s(%d:%d)'", 
        !            99:                                transcode(e.getMessage()),  // message for exception
        !           100:                                transcode(e.getType()), // type of exception
        !           101:                                
        !           102:                                transcode(e.getURI()),  // URI for the associated document, if any
        !           103:                                e.getLineNumber(),  // line number, or -1 if unknown
        !           104:                                e.getColumnNumber() // column number, or -1 if unknown
        !           105:                );
        !           106: }

E-mail: