Ignore:
Timestamp:
1999-01-04T16:32:21+13:00 (25 years ago)
Author:
rjmcnab
Message:

Wrote general map file based in and out converters. Fixed bugs related
to Chinese charater searching. text_t now has a encoding attribute. Added
an encoding option to the preferences.

File:
1 edited

Legend:

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

    r12 r94  
    2424/*
    2525   $Log$
     26   Revision 1.2  1999/01/04 03:32:17  rjmcnab
     27
     28   Wrote general map file based in and out converters. Fixed bugs related
     29   to Chinese charater searching. text_t now has a encoding attribute. Added
     30   an encoding option to the preferences.
     31
    2632   Revision 1.1  1998/11/17 09:11:29  rjmcnab
    2733
     
    7076
    7177#include "text_t.h"
     78#include "unitool.h"
    7279
    7380////////////////////////////////////
     
    7784text_t::text_t ()
    7885{
     86  setencoding(0);
    7987  clear ();
    8088}
     
    8290text_t::text_t (int i)
    8391{
     92  setencoding(0);
    8493  clear ();
    8594  appendint (i);
     
    8796
    8897text_t::text_t (char *s)
    89 {
     98{
     99  setencoding(0);
    90100  clear ();
    91101  appendcstr (s);
     
    223233  while (ithere != itend)
    224234    {
    225       if (*ithere >= 256) cstr[len] = ' ';
    226       else cstr[len] = (*ithere);
     235      if (*ithere < 256) cstr[len] = (unsigned char)(*ithere);
     236      else {
     237    // put a space or a question mark depending on what
     238    // the character is. Question marks tell the user that
     239    // they are missing some information.
     240    if (is_unicode_space (*ithere)) cstr[len] = ' ';
     241    else cstr[len] = '?';
     242      }
    227243      len++;
    228244      ithere++;
     
    241257  while (ithere != itend)
    242258    {
    243       if (*ithere >= 256) cstr[len] = ' ';
    244       else cstr[len] = (*ithere);
     259      if (*ithere < 256) cstr[len] = (unsigned char)(*ithere);
     260      else {
     261    // put a space or a question mark depending on what
     262    // the character is. Question marks tell the user that
     263    // they are missing some information.
     264    if (is_unicode_space (*ithere)) cstr[len] = ' ';
     265    else cstr[len] = '?';
     266      }
    245267      len++;
    246268      ithere++;
     
    425447void inconvertclass::convert (text_t &output, status_t &status)
    426448{
     449  output.clear();
     450
    427451  if (start == NULL || len == 0)
    428452    {
     
    442466  start = (char *)here; // save current position
    443467  status = finished;
     468}
     469
     470// will treat the text_t as a 8-bit string and convert
     471// it to a 16-bit string using the about convert method.
     472text_t inconvertclass::convert (const text_t &t) {
     473  text_t out;
     474  text_t tmpout;
     475  status_t status;
     476  text_t::const_iterator here = t.begin();
     477  text_t::const_iterator end = t.end();
     478  unsigned char cbuf[256];
     479  size_t cbuflen = 0;
     480 
     481  while (here != end) {
     482    while (here != end && cbuflen < 256) {
     483      cbuf[cbuflen++] = (unsigned char)(*here & 0xff);
     484      here++;
     485    }
     486
     487    if (cbuflen > 0) {
     488      setinput ((char *)cbuf, cbuflen);
     489      status = unfinished;
     490      while (status == unfinished) {
     491    convert (tmpout, status);
     492    out += tmpout;
     493      }
     494      cbuflen = 0;
     495    }
     496  }
     497
     498  out.setencoding (0); // unicode
     499
     500  return out;
    444501}
    445502
     
    498555    {
    499556      if (*texthere < 256) *uoutput = (unsigned char)(*texthere);
    500       else *uoutput = 32; // put a space where a char >= 256 exists
     557      else {
     558    // put a space or a question mark depending on what
     559    // the character is. Question marks tell the user that
     560    // they are missing some information.
     561    if (is_unicode_space (*texthere)) *uoutput = ' ';
     562    else *uoutput = '?';
     563      }
    501564      ++uoutput;
    502565      ++len;
     
    508571}
    509572
     573// will convert the 16-bit string to a 8-bit stream
     574// and place the result in a text_t. This method uses
     575// the above convert function.
     576text_t outconvertclass::convert (const text_t &t) {
     577  text_t out;
     578  unsigned char cbuf[256];
     579  size_t cbuflen = 0;
     580  status_t status = unfinished;
     581
     582  setinput ((text_t *)&t); // discard constant
     583  while (status == unfinished) {
     584    convert ((char *)cbuf, 256, cbuflen, status);
     585    out.appendcarr ((char *)cbuf, cbuflen);
     586  }
     587
     588  out.setencoding (1); // other encoding
     589 
     590  return out;
     591}
     592
     593
    510594void outconvertclass::setostream (ostream *theouts)
    511595{
Note: See TracChangeset for help on using the changeset viewer.