--- parser3/src/main/pa_charset.C 2002/01/14 17:48:57 1.14 +++ parser3/src/main/pa_charset.C 2002/08/01 11:41:18 1.28 @@ -1,12 +1,12 @@ /** @file Parser: Charset connection implementation. - Copyright(c) 2001 ArtLebedev Group(http://www.artlebedev.com) + Copyright(c) 2001, 2002 ArtLebedev Group (http://www.artlebedev.com) Author: Alexander Petrosyan(http://paf.design.ru) - - $Id: pa_charset.C,v 1.14 2002/01/14 17:48:57 paf Exp $ */ +static const char* IDENT_CHARSET_C="$Date: 2002/08/01 11:41:18 $"; + #include "pa_charset.h" #ifdef XML @@ -153,7 +153,7 @@ void Charset::loadDefinition(const Strin case 8: // charset if(tables.toTableSize>MAX_CHARSET_UNI_CODES) - throw Exception(0, 0, + throw Exception("parser.runtime", &request_file_spec, "charset must contain not more then %d unicode values", MAX_CHARSET_UNI_CODES); @@ -191,7 +191,8 @@ void Charset::sort_ToTable() { } static XMLByte xlatOneTo(const XMLCh toXlat, - const Charset::Tables& tables) { + const Charset::Tables& tables, + XMLByte not_found) { unsigned int lowOfs = 0; unsigned int hiOfs = tables.toTableSize - 1; XMLByte curByte = 0; @@ -210,7 +211,7 @@ static XMLByte xlatOneTo(const XMLCh toX return tables.toTable[midOfs].extCh; } while(lowOfs+1output( - (unsigned char*)out, &outlen, - (const unsigned char*)s, &inlen, - transcoder->outputInfo); + int size; + if(xmlCharEncodingOutputFunc output=transcoder(0)->output) { + size=output( + (unsigned char*)out, &outlen, + (const unsigned char*)s, &inlen, + transcoder(0)->outputInfo); + } else + memcpy(out, s, size=inlen); if(size<0) - throw Exception(0, 0, + throw Exception(0, 0, "transcode_cstr failed (%d)", size); @@ -576,29 +585,33 @@ String& Charset::transcode(GdomeDOMStrin } /// @test less memory using -maybe- xmlParserInputBufferCreateMem -GdomeDOMString_auto_ptr Charset::transcode_buf(const char *buf, size_t buf_size) { - if(!transcoder) - throw Exception(0, 0, - 0, - "transcode_buf no transcoder"); - +xmlChar *Charset::transcode_buf2xchar(const char *buf, size_t buf_size) { int outlen=buf_size*6/*max*/+1; unsigned char *out=(unsigned char*)malloc(outlen*sizeof(unsigned char)); - int size=transcoder->input( - out, &outlen, - (const unsigned char *)buf, (int *)&buf_size, - transcoder->inputInfo); + + int size; + if(xmlCharEncodingInputFunc input=transcoder(0)->input) { + size=input( + out, &outlen, + (const unsigned char *)buf, (int *)&buf_size, + transcoder(0)->inputInfo); + } else + memcpy(out, buf, size=buf_size); + if(size<0) - throw Exception(0, 0, + throw Exception(0, 0, "transcode_buf failed (%d)", size); out[size]=0; - return (gchar*)out; + return (xmlChar *)out; +} +GdomeDOMString_auto_ptr Charset::transcode_buf2dom(const char *buf, size_t buf_size) { + return GdomeDOMString_auto_ptr((gchar*)transcode_buf2xchar(buf, buf_size)); } GdomeDOMString_auto_ptr Charset::transcode(const String& s) { const char *cstr=s.cstr(String::UL_UNSPECIFIED); - return transcode_buf(cstr, strlen(cstr)); + return transcode_buf2dom(cstr, strlen(cstr)); } #endif