Changeset 650 for trunk/src/unicode.cpp

Show
Ignore:
Timestamp:
02/18/08 16:40:34 (3 years ago)
Author:
artem
Message:

added Unicode support based on ICU

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/unicode.cpp

    r621 r650  
    7777#endif 
    7878 
    79  
     79/* 
    8080    inline std::wstring to_unicode(std::string const& text) 
    8181    { 
     
    160160   } 
    161161    
    162  
     162*/ 
    163163   transcoder::transcoder (std::string const& encoding) 
     164      : ok_(false), 
     165        conv_(0) 
    164166   { 
    165167#ifdef MAPNIK_DEBUG 
     
    167169#endif 
    168170       
    169 #ifndef WORDS_BIGENDIAN 
    170       desc_ = iconv_open("UCS-4LE",encoding.c_str()); 
    171 #else 
    172       desc_ = iconv_open("UCS-4BE",encoding.c_str()); 
    173 #endif 
    174    } 
    175     
    176    std::wstring transcoder::transcode(std::string const& input) const 
    177    { 
     171//#ifndef WORDS_BIGENDIAN 
     172         //     desc_ = iconv_open("UCS-4LE",encoding.c_str()); 
     173//#else 
     174         //     desc_ = iconv_open("UCS-4BE",encoding.c_str()); 
     175//#endif 
     176       
     177      UErrorCode err = U_ZERO_ERROR; 
     178      conv_ = ucnv_open(encoding.c_str(),&err); 
     179      if (U_SUCCESS(err)) ok_ = true; 
     180      // TODO 
     181   } 
     182    
     183   UnicodeString transcoder::transcode(const char* data) const 
     184   { 
     185 
     186      UErrorCode err = U_ZERO_ERROR; 
     187       
     188      UnicodeString ustr(data,-1,conv_,err);  
     189      if (ustr.isBogus()) 
     190      { 
     191         ustr.remove(); 
     192      } 
     193      return ustr; 
     194/* 
    178195      if (desc_ == iconv_t(-1)) return to_unicode(input);  
    179196      size_t inleft = input.size(); 
     
    197214#endif 
    198215      return output; 
     216*/ 
    199217   } 
    200218    
    201219   transcoder::~transcoder() 
    202220   { 
    203       if (desc_ != iconv_t(-1)) iconv_close(desc_); 
     221      // if (desc_ != iconv_t(-1)) iconv_close(desc_); 
     222      if (conv_) 
     223         ucnv_close(conv_); 
    204224   }    
    205225}