Changeset 3667


Ignore:
Timestamp:
2003-01-13T20:12:09+13:00 (21 years ago)
Author:
jrm21
Message:

added a utf16 output converter class.

Location:
trunk/gsdl/lib
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl/lib/gsdlunicode.cpp

    r1927 r3667  
    9090
    9191
     92// this works for all unicode values < 65536...
     93void utf16outconvertclass::convert (char *out, size_t maxlen, size_t &len, status_t &status) {
     94  // we should already have text_t* input set...
     95  if (input == NULL || out == NULL)
     96  {
     97    status = finished;
     98    return;
     99  }
     100  unsigned char *output = (unsigned char *)out;
     101  text_t::iterator textend = input->end();
     102  len = 0;
     103  if (maxlen % 2) maxlen--; // we need an even number of output bytes...
     104  while ((len < maxlen) && (texthere != textend)) {
     105    unsigned short int uni_char=(unsigned short int) *texthere;
     106    // big endian utf-16...
     107    if (uni_char < 256) {
     108      out[len]=0;   
     109      out[len+1]=uni_char;
     110    } else {
     111      out[len]=uni_char >> 8;
     112      out[len+1]=uni_char & 255;
     113    }
     114    len+=2;
     115    ++texthere;
     116  }
     117  if (texthere==textend)
     118    status=finished;
     119  else
     120    status=unfinished;
     121}
     122
    92123
    93124utf8inconvertclass::utf8inconvertclass () {
  • trunk/gsdl/lib/gsdlunicode.h

    r1927 r3667  
    3939// encoded text_t string
    4040text_t to_uni (const text_t &in);
    41 
    42 
    4341
    4442#define MAXUTF8CHARLEN 3
     
    7876};
    7977
     78// utf16 is almost the same as unicode, except for unicode values > 65535.
     79class utf16outconvertclass : public rzwsoutconvertclass {
     80public:
     81  utf16outconvertclass () {};
     82  void convert (char *out, size_t maxlen, size_t &len, status_t &status);
     83};
     84
    8085
    8186// Convert from a text_t class to a utf-8 char stream
Note: See TracChangeset for help on using the changeset viewer.