--- parser3/src/main/pa_charset.C 2001/12/28 18:12:30 1.10 +++ parser3/src/main/pa_charset.C 2002/06/28 09:59:01 1.24 @@ -1,10 +1,10 @@ /** @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.10 2001/12/28 18:12:30 paf Exp $ + $Id: pa_charset.C,v 1.24 2002/06/28 09:59:01 paf Exp $ */ #include "pa_charset.h" @@ -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); @@ -287,14 +287,14 @@ static const XMLByte gFirstByteMark[7] = 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC }; -static size_t transcodeToUTF8( - const void *source_body, size_t source_content_length, - XMLByte *dest_body, size_t dest_buf_length, +static int transcodeToUTF8( + const XMLByte* srcData, size_t& srcLen, + XMLByte *toFill, size_t& toFillLen, const Charset::Tables& tables) { - const XMLByte* srcPtr=(const XMLByte*)source_body; - const XMLByte* srcEnd=(const XMLByte*)source_body+source_content_length; - XMLByte* outPtr=dest_body; - XMLByte* outEnd=dest_body+dest_buf_length; + const XMLByte* srcPtr=srcData; + const XMLByte* srcEnd=srcData+srcLen; + XMLByte* outPtr=toFill; + XMLByte* outEnd=toFill+toFillLen; while(srcPtroutput( - (unsigned char*)out, &outlen, - (const unsigned char*)s->str, &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); out[size]=0; return out; } +String& Charset::transcode(xmlChar *s) { + return *NEW String(pool(), transcode_cstr(s)); +} +const char *Charset::transcode_cstr(GdomeDOMString *s) { + return s?transcode_cstr(BAD_CAST s->str):""; +} String& Charset::transcode(GdomeDOMString *s) { return *NEW String(pool(), transcode_cstr(s)); } /// @test less memory using -maybe- xmlParserInputBufferCreateMem -GdomeDOMString *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 gdome_str_mkref_own((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 *Charset::transcode(const String& s) { +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