Diff for /parser3/src/main/pa_charset.C between versions 1.33.2.19.2.1 and 1.33.2.19.2.6

version 1.33.2.19.2.1, 2003/03/18 15:14:18 version 1.33.2.19.2.6, 2003/03/24 13:43:41
Line 68  static void element2case(unsigned char f Line 68  static void element2case(unsigned char f
 // methods  // methods
   
 extern "C" unsigned char pcre_default_tables[]; // pcre/chartables.c  extern "C" unsigned char pcre_default_tables[]; // pcre/chartables.c
 Charset::Charset(const String& aname, const String& afile_spec):   Charset::Charset(const String& aname, const String* afile_spec): 
         fname(aname),          fname(aname),
         fname_cstr(aname->cstr()) {          fname_cstr(aname.cstrm()) {
   
         for(char *c=fname_cstr; *c; c++)          for(char *c=fname_cstr; *c; c++)
         *c = toupper(*c);                  *c = toupper(*c);
   
         if(afile_spec) {          if(afile_spec) {
                 fisUTF8=false;                  fisUTF8=false;
                 load_definition(afile_spec);                  load_definition(*afile_spec);
 #ifdef XML  #ifdef XML
                 addEncoding(fname_cstr);                  addEncoding(fname_cstr);
 #endif  #endif
Line 117  void Charset::load_definition(const Stri Line 117  void Charset::load_definition(const Stri
         tables.toTableSize++;          tables.toTableSize++;
   
         // loading text          // loading text
         Pool pool_for_load_only;          char *data=file_read_text(UTF8_charset, afile_spec);
         char *data=file_read_text(pool_for_load_only, *UTF8_charset, afile_spec);  
   
         // ignore header          // ignore header
         getrow(&data);          getrow(&data);
Line 148  void Charset::load_definition(const Stri Line 147  void Charset::load_definition(const Stri
                                 // charset                                  // charset
                                 if(tables.toTableSize>MAX_CHARSET_UNI_CODES)                                  if(tables.toTableSize>MAX_CHARSET_UNI_CODES)
                                         throw Exception("parser.runtime",                                          throw Exception("parser.runtime",
                                                 afile_spec,                                                  &afile_spec,
                                                 "charset must contain not more then %d unicode values", MAX_CHARSET_UNI_CODES);                                                  "charset must contain not more then %d unicode values", MAX_CHARSET_UNI_CODES);
   
                                 XMLCh unicode=(XMLCh)to_wchar_code(cell);                                  XMLCh unicode=(XMLCh)to_wchar_code(cell);
Line 220  void Charset::transcode( Line 219  void Charset::transcode(
   
         switch((source_charset.isUTF8()?0x10:0x00)|(dest_charset.isUTF8()?0x01:0x00)) {          switch((source_charset.isUTF8()?0x10:0x00)|(dest_charset.isUTF8()?0x01:0x00)) {
                 default: // 0x00                  default: // 0x00
                         source_charset.transcodeToCharset(pool, dest_charset,                          source_charset.transcodeToCharset(dest_charset,
                                 source_body, source_content_length,                                  source_body, source_content_length,
                                 dest_body, dest_content_length);                                  dest_body, dest_content_length);
                         break;                          break;
                 case 0x01:                  case 0x01:
                         source_charset.transcodeToUTF8(pool,                          source_charset.transcodeToUTF8(
                                 source_body, source_content_length,                                  source_body, source_content_length,
                                 dest_body, dest_content_length);                                  dest_body, dest_content_length);
                         break;                          break;
                 case 0x10:                  case 0x10:
                         dest_charset.transcodeFromUTF8(pool,                          dest_charset.transcodeFromUTF8(
                                 source_body, source_content_length,                                  source_body, source_content_length,
                                 dest_body, dest_content_length);                                  dest_body, dest_content_length);
                         break;                          break;
                 case 0x11:                  case 0x11:
                         dest_body=pool.copy((char*)source_body, dest_content_length=source_content_length);                          dest_body=source_body;
                           dest_content_length=source_content_length;
                         break;                          break;
         }          }
 }  }
Line 408  static int transcodeFromUTF8( Line 408  static int transcodeFromUTF8(
   
             default:              default:
                 throw Exception(0,                  throw Exception(0,
                                         Exception::undefined_source,                                          0,
                                         "transcodeFromUTF8 error: wrong trailingBytes value(%d)", trailingBytes);                                          "transcodeFromUTF8 error: wrong trailingBytes value(%d)", trailingBytes);
         }          }
         tmpVal-=gUTFOffsets[trailingBytes];          tmpVal-=gUTFOffsets[trailingBytes];
Line 423  static int transcodeFromUTF8( Line 423  static int transcodeFromUTF8(
                                 outPtr+=sprintf((char *)outPtr, "&#%d;", tmpVal); // &#decimal;                                  outPtr+=sprintf((char *)outPtr, "&#%d;", tmpVal); // &#decimal;
                 } else                  } else
                         throw Exception(0,                          throw Exception(0,
                                 Exception::undefined_source,                                  0,
                                 "transcodeFromUTF8 error: too big tmpVal(0x%08X)", tmpVal);                                  "transcodeFromUTF8 error: too big tmpVal(0x%08X)", tmpVal);
         }          }
   
Line 486  void Charset::transcodeToCharset( Line 486  void Charset::transcodeToCharset(
                                                                            const void* source_body, size_t source_content_length,                                                                             const void* source_body, size_t source_content_length,
                                                                            const void *& adest_body, size_t& adest_content_length) const {                                                                             const void *& adest_body, size_t& adest_content_length) const {
         if(&dest_charset==this) {          if(&dest_charset==this) {
                 adest_body=pool.copy((char*)source_body, adest_content_length=source_content_length);                  adest_body=source_body;
                   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=new unsigned char[dest_content_length];                  unsigned char *dest_body=new unsigned char[dest_content_length];
Line 565  const char* Charset::transcode_cstrxmlCh Line 566  const char* Charset::transcode_cstrxmlCh
   
         int inlen=strlen((const char* )s);          int inlen=strlen((const char* )s);
         int outlen=inlen+1; // max          int outlen=inlen+1; // max
         char *out=new char[outlen];          char *out=new(PointerFreeGC) char[outlen];
                   
         int error;          int error;
         if(xmlCharEncodingOutputFunc output=transcoder(Exception::undefined_source).output) {          if(xmlCharEncodingOutputFunc output=transcoder(0).output) {
                 error=output(                  error=output(
                         (unsigned char*)out, &outlen,                          (unsigned char*)out, &outlen,
                         (const unsigned char*)s, &inlen,                          (const unsigned char*)s, &inlen,
                         transcoder(Exception::undefined_source).outputInfo);                          transcoder(0).outputInfo);
         } else {          } else {
                 memcpy(out, s, outlen=inlen);                  memcpy(out, s, outlen=inlen);
                 error=0;                  error=0;
         }          }
         if(error<0)          if(error<0)
                 throw Exception(Exception::undefined_type,                  throw Exception(0,
                         Exception::undefined_source,                          0,
                         "transcode_cstr failed (%d)", error);                          "transcode_cstr failed (%d)", error);
   
         out[outlen/*surely would be less then on input*/]=0;          out[outlen/*surely would be less then on input*/]=0;
Line 592  const String& Charset::transcodexmlChar* Line 593  const String& Charset::transcodexmlChar*
                                                    ) {                                                      ) { 
         const String& result(new String());          const String& result(new String());
         result->APPEND_CLEAN(          result->APPEND_CLEAN(
                 transcode_cstr(pool, s), 0/*auto-size*/,                   transcode_cstr(s), 0/*auto-size*/, 
                 origin->origin().file, origin->origin().line);                  origin->origin().file, origin->origin().line);
         return result;           return result; 
 }  }
 const char* Charset::transcode_cstrGdomeDOMString* s) {   const char* Charset::transcode_cstrGdomeDOMString* s) { 
         return s?transcode_cstr(pool, BAD_CAST s->str):"";          return s?transcode_cstr(BAD_CAST s->str):"";
 }  }
 const String& Charset::transcodeGdomeDOMString* s  const String& Charset::transcodeGdomeDOMString* s
 #ifndef NO_STRING_ORIGIN  #ifndef NO_STRING_ORIGIN
Line 605  const String& Charset::transcodeGdomeDOM Line 606  const String& Charset::transcodeGdomeDOM
 #endif  #endif
                                                    ) {                                                      ) { 
         const String& result(new String());          const String& result(new String());
         result->APPEND_CLEAN(transcode_cstr(pool, s), 0/*auto-size*/, origin->origin().file, origin->origin().line);          result->APPEND_CLEAN(transcode_cstr(s), 0/*auto-size*/, origin->origin().file, origin->origin().line);
         return result;           return result; 
 }  }
   
Line 615  void* Charset::transcode_buf2mchar(trans Line 616  void* Charset::transcode_buf2mchar(trans
         unsigned char* out;          unsigned char* out;
         int outlen;          int outlen;
         int error;          int error;
         if(xmlCharEncodingInputFunc input=transcoder(Exception::undefined_source).input) {          if(xmlCharEncodingInputFunc input=transcoder(0).input) {
                 outlen=buf_size*6/*max*/;                  outlen=buf_size*6/*max*/;
                 out=(unsigned char*)malloc_func(outlen+1);                  out=(unsigned char*)malloc_func(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(Exception::undefined_source).inputInfo);                          transcoder(0).inputInfo);
         } else {          } else {
                 outlen=buf_size;                  outlen=buf_size;
                 out=(unsigned char*)malloc_func(outlen+1);                  out=(unsigned char*)malloc_func(outlen+1);
Line 630  void* Charset::transcode_buf2mchar(trans Line 631  void* Charset::transcode_buf2mchar(trans
         }          }
                   
         if(error<0)          if(error<0)
                 throw Exception(Exception::undefined_type,                  throw Exception(0,
                         Exception::undefined_source,                          0,
                         "transcode_buf failed (%d)", error);                          "transcode_buf failed (%d)", error);
   
         out[outlen/*surely would be less then on input*/]=0;          out[outlen/*surely would be less then on input*/]=0;
Line 651  GdomeDOMString_auto_ptr Charset::transco Line 652  GdomeDOMString_auto_ptr Charset::transco
         return GdomeDOMString_auto_ptr(transcode_buf2gchar(buf, buf_size));          return GdomeDOMString_auto_ptr(transcode_buf2gchar(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);          const char* cstr=s->cstr(String::L_UNSPECIFIED);
   
         return transcode_buf2dom(cstr, strlen(cstr));           return transcode_buf2dom(cstr, strlen(cstr)); 
 }  }

Removed from v.1.33.2.19.2.1  
changed lines
  Added in v.1.33.2.19.2.6


E-mail: