|
|
| version 1.33.2.7, 2003/02/04 12:08:56 | version 1.33.2.11, 2003/02/21 08:50:02 |
|---|---|
| Line 20 static const char* IDENT_CHARSET_C="$Dat | Line 20 static const char* IDENT_CHARSET_C="$Dat |
| CharsetPtr UTF8_charset(new Charset(StringPtr(new String(CHARSET_UTF8_NAME)), | CharsetPtr UTF8_charset(new Charset(StringPtr(new String(CHARSET_UTF8_NAME)), |
| StringPtr(0)/*no file=system*/)); | StringPtr(0)/*no file=system*/)); |
| // consts | |
| #define MAX_CHARSET_UNI_CODES 500 | |
| // helpers | // helpers |
| inline void prepare_case_tables(unsigned char *tables) { | inline void prepare_case_tables(unsigned char *tables) { |
| Line 87 Charset::Charset(StringPtr aname, String | Line 83 Charset::Charset(StringPtr aname, String |
| if(afile_spec) { | if(afile_spec) { |
| fisUTF8=false; | fisUTF8=false; |
| load_definition(fname); | load_definition(afile_spec); |
| #ifdef XML | #ifdef XML |
| addEncoding(fname_cstr); | addEncoding(fname_cstr); |
| #endif | #endif |
| Line 121 void Charset::load_definition(StringPtr | Line 117 void Charset::load_definition(StringPtr |
| // charset | // charset |
| memset(tables.fromTable, 0, sizeof(tables.fromTable)); | memset(tables.fromTable, 0, sizeof(tables.fromTable)); |
| tables.toTable=(Charset_TransRec *)pool_for_load.calloc(sizeof(Charset_TransRec)*MAX_CHARSET_UNI_CODES); | memset(tables.toTable, 0, sizeof(tables.toTable)); |
| tables.toTableSize=0; | tables.toTableSize=0; |
| // strangly vital | // strangly vital |
| tables.toTable[tables.toTableSize].intCh=0; | tables.toTable[tables.toTableSize].intCh=0; |
| Line 129 void Charset::load_definition(StringPtr | Line 125 void Charset::load_definition(StringPtr |
| tables.toTableSize++; | tables.toTableSize++; |
| // loading text | // loading text |
| char *data=file_read_text(pool_for_load, *UTF8_charset, afile_spec); | Pool pool_for_load_only; |
| char *data=file_read_text(pool_for_load_only, *UTF8_charset, afile_spec); | |
| // ignore header | // ignore header |
| getrow(&data); | getrow(&data); |
| Line 461 void Charset::transcodeToUTF8(Pool& pool | Line 458 void Charset::transcodeToUTF8(Pool& pool |
| const void *source_body, size_t source_content_length, | const void *source_body, size_t source_content_length, |
| const void *& adest_body, size_t& dest_content_length) const { | const void *& adest_body, size_t& dest_content_length) const { |
| dest_content_length=source_content_length*6/*so that surly enough, max utf8 seq len=6*/; | dest_content_length=source_content_length*6/*so that surly enough, max utf8 seq len=6*/; |
| XMLByte *dest_body=(XMLByte*)pool.malloc(dest_content_length); | XMLByte *dest_body=new(pool) XMLByte[dest_content_length]; |
| if(::transcodeToUTF8( | if(::transcodeToUTF8( |
| (XMLByte *)source_body, source_content_length, | (XMLByte *)source_body, source_content_length, |
| Line 478 void Charset::transcodeFromUTF8(Pool& po | Line 475 void Charset::transcodeFromUTF8(Pool& po |
| const void *source_body, size_t source_content_length, | const void *source_body, size_t source_content_length, |
| const void *& adest_body, size_t& dest_content_length) const { | const void *& adest_body, size_t& dest_content_length) const { |
| dest_content_length=source_content_length*6/*so that surly enough, "ÿ" has max ratio */; | dest_content_length=source_content_length*6/*so that surly enough, "ÿ" has max ratio */; |
| XMLByte *dest_body=(XMLByte*)pool.malloc(dest_content_length); | XMLByte *dest_body=new(pool) XMLByte[dest_content_length]; |
| if(::transcodeFromUTF8( | if(::transcodeFromUTF8( |
| (XMLByte *)source_body, source_content_length, | (XMLByte *)source_body, source_content_length, |
| Line 502 void Charset::transcodeToCharset(Pool& p | Line 499 void Charset::transcodeToCharset(Pool& p |
| adest_content_length=source_content_length; | adest_content_length=source_content_length; |
| } else { | } else { |
| size_t dest_content_length=source_content_length; | size_t dest_content_length=source_content_length; |
| unsigned char *dest_body=(unsigned char *)pool.malloc(dest_content_length); | unsigned char *dest_body=new(pool) unsigned char[dest_content_length]; |
| const XMLByte* srcPtr=(XMLByte *)source_body; | const XMLByte* srcPtr=(XMLByte *)source_body; |
| const XMLByte* srcEnd=(XMLByte *)source_body+source_content_length; | const XMLByte* srcEnd=(XMLByte *)source_body+source_content_length; |
| Line 550 static int xml256CharEncodingOut | Line 547 static int xml256CharEncodingOut |
| void Charset::addEncoding(char *name_cstr) { | void Charset::addEncoding(char *name_cstr) { |
| xmlCharEncodingHandler *handler= | xmlCharEncodingHandler *handler= |
| (xmlCharEncodingHandler *)malloc(sizeof(xmlCharEncodingHandler)); | (xmlCharEncodingHandler *)[ADD to local array of autoptrs to autofree]new ...(sizeof(xmlCharEncodingHandler)); |
| handler->name=name_cstr; | handler->name=name_cstr; |
| handler->input=xml256CharEncodingInputFunc; handler->inputInfo=&tables; | handler->input=xml256CharEncodingInputFunc; handler->inputInfo=&tables; |
| handler->output=xml256CharEncodingOutputFunc; handler->outputInfo=&tables; | handler->output=xml256CharEncodingOutputFunc; handler->outputInfo=&tables; |
| Line 571 xmlCharEncodingHandler *Charset::transco | Line 568 xmlCharEncodingHandler *Charset::transco |
| return ftranscoder; | return ftranscoder; |
| } | } |
| const char* Charset::transcode_cstr(xmlChar *s) { | CharPtr Charset::transcode_cstr(xmlChar *s) { |
| if(!s) | if(!s) |
| return ""; | return ""; |
| int inlen=strlen((const char* )s); | int inlen=strlen((const char* )s); |
| int outlen=inlen+1; // max | int outlen=inlen+1; // max |
| char *out=(char *)malloc(outlen*sizeof(char)); | char *out=new char[outlen]; |
| int error; | int error; |
| if(xmlCharEncodingOutputFunc output=transcoder(0)->output) { | if(xmlCharEncodingOutputFunc output=transcoder(0)->output) { |
| Line 620 String& Charset::transcode(GdomeDOMStrin | Line 617 String& Charset::transcode(GdomeDOMStrin |
| } | } |
| /// @test less memory using -maybe- xmlParserInputBufferCreateMem | /// @test less memory using -maybe- xmlParserInputBufferCreateMem |
| xmlChar *Charset::transcode_buf2xchar(const char* buf, size_t buf_size) { | xmlChar *Charset::transcode_buf2xchar(Pool& pool, const char* buf, size_t buf_size) { |
| unsigned char *out; | unsigned char *out; |
| int outlen; | int outlen; |
| int error; | int error; |
| if(xmlCharEncodingInputFunc input=transcoder(0)->input) { | if(xmlCharEncodingInputFunc input=transcoder(0)->input) { |
| outlen=buf_size*6/*max*/; | outlen=buf_size*6/*max*/; |
| out=(unsigned char*)malloc((outlen+1)*sizeof(unsigned char)); | out=new(pool) unsigned char[outlen+1]; |
| error=input( | error=input( |
| out, &outlen, | out, &outlen, |
| (const unsigned char *)buf, (int *)&buf_size, | (const unsigned char *)buf, (int *)&buf_size, |
| transcoder(0)->inputInfo); | transcoder(0)->inputInfo); |
| } else { | } else { |
| outlen=buf_size; | outlen=buf_size; |
| out=(unsigned char*)malloc((outlen+1)*sizeof(unsigned char)); | out=new(pool) unsigned char[outlen+1]; |
| memcpy(out, buf, outlen); | memcpy(out, buf, outlen); |
| error=0; | error=0; |
| } | } |
| Line 650 GdomeDOMString_auto_ptr Charset::transco | Line 647 GdomeDOMString_auto_ptr Charset::transco |
| return GdomeDOMString_auto_ptr((gchar*)transcode_buf2xchar(buf, buf_size)); | return GdomeDOMString_auto_ptr((gchar*)transcode_buf2xchar(buf, buf_size)); |
| } | } |
| GdomeDOMString_auto_ptr Charset::transcode(const String& s) { | GdomeDOMString_auto_ptr Charset::transcode(const String& s) { |
| const char* cstr=s.cstr(String::UL_UNSPECIFIED); | CharPtr cstr=s.cstr(String::UL_UNSPECIFIED); |
| return transcode_buf2dom(cstr, strlen(cstr)); | return transcode_buf2dom(cstr, strlen(cstr)); |
| } | } |