--- parser3/src/main/pa_charset.C 2002/08/01 11:26:49 1.27 +++ parser3/src/main/pa_charset.C 2002/12/23 08:03:03 1.32 @@ -5,7 +5,7 @@ Author: Alexander Petrosyan(http://paf.design.ru) */ -static const char* IDENT_CHARSET_C="$Id: pa_charset.C,v 1.27 2002/08/01 11:26:49 paf Exp $"; +static const char* IDENT_CHARSET_C="$Date: 2002/12/23 08:03:03 $"; #include "pa_charset.h" @@ -361,10 +361,18 @@ static int transcodeToUTF8( // Return the characters read toFillLen = outPtr - toFill; - return srcPtr==srcEnd?(int)toFillLen:-1; + //return srcPtr==srcEnd?(int)toFillLen:-1; +/* +xmlCharEncodingInputFunc +Returns : +the number of byte written, or -1 by lack of space, or -2 if the transcoding failed. The value of inlen after return is the +number of octets consumed as the return value is positive, else unpredictiable. The value of outlen after return is the number +of ocetes consumed. +*/ + return 0; } /// @todo digital entites only when xml/html output [at output in html/xml mode, in html part of a letter] -static size_t transcodeFromUTF8( +static int transcodeFromUTF8( const XMLByte *srcData, size_t& srcLen, XMLByte* toFill, size_t& toFillLen, const Charset::Tables& tables) { @@ -432,7 +440,15 @@ static size_t transcodeFromUTF8( // Return the characters read toFillLen = outPtr - toFill; - return srcPtr==srcEnd?(int)toFillLen:-1; + //return srcPtr==srcEnd?(int)toFillLen:-1; +/* +xmlCharEncodingOutputFunc +Returns : +the number of byte written, or -1 by lack of space, or -2 if the transcoding failed. The value of inlen after return is the +number of octets consumed as the return value is positive, else unpredictiable. The value of outlen after return is the number +of ocetes consumed. +*/ + return 0; } /// @todo not so memory-hungry with prescan @@ -558,52 +574,71 @@ const char *Charset::transcode_cstr(xmlC int outlen=inlen+1; // max char *out=(char *)malloc(outlen*sizeof(char)); - int size; + int error; if(xmlCharEncodingOutputFunc output=transcoder(0)->output) { - size=output( + error=output( (unsigned char*)out, &outlen, (const unsigned char*)s, &inlen, transcoder(0)->outputInfo); - } else - memcpy(out, s, size=inlen); - if(size<0) + } else { + memcpy(out, s, outlen=inlen); + error=0; + } + if(error<0) throw Exception(0, 0, - "transcode_cstr failed (%d)", size); + "transcode_cstr failed (%d)", error); - out[size]=0; + out[outlen/*surely would be less then on input*/]=0; return out; } -String& Charset::transcode(xmlChar *s) { - return *NEW String(pool(), transcode_cstr(s)); +String& Charset::transcode(xmlChar *s +#ifndef NO_STRING_ORIGIN + , const String *origin +#endif + ) { + String& result=*NEW String(pool()); + result.APPEND_CLEAN(transcode_cstr(s), 0/*auto-size*/, origin->origin().file, origin->origin().line); + return result; } 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)); +String& Charset::transcode(GdomeDOMString *s +#ifndef NO_STRING_ORIGIN + , const String *origin +#endif + ) { + String& result=*NEW String(pool()); + result.APPEND_CLEAN(transcode_cstr(s), 0/*auto-size*/, origin->origin().file, origin->origin().line); + return result; } /// @test less memory using -maybe- xmlParserInputBufferCreateMem 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; + unsigned char *out; + int outlen; + int error; if(xmlCharEncodingInputFunc input=transcoder(0)->input) { - size=input( + outlen=buf_size*6/*max*/; + out=(unsigned char*)malloc((outlen+1)*sizeof(unsigned char)); + error=input( out, &outlen, (const unsigned char *)buf, (int *)&buf_size, transcoder(0)->inputInfo); - } else - memcpy(out, buf, size=buf_size); + } else { + outlen=buf_size; + out=(unsigned char*)malloc((outlen+1)*sizeof(unsigned char)); + memcpy(out, buf, outlen); + error=0; + } - if(size<0) + if(error<0) throw Exception(0, 0, - "transcode_buf failed (%d)", size); + "transcode_buf failed (%d)", error); - out[size]=0; + out[outlen/*surely would be less then on input*/]=0; return (xmlChar *)out; } GdomeDOMString_auto_ptr Charset::transcode_buf2dom(const char *buf, size_t buf_size) {