Changeset 94 for trunk/gsdl/lib/text_t.cpp
- Timestamp:
- 1999-01-04T16:32:21+13:00 (25 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl/lib/text_t.cpp
r12 r94 24 24 /* 25 25 $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 26 32 Revision 1.1 1998/11/17 09:11:29 rjmcnab 27 33 … … 70 76 71 77 #include "text_t.h" 78 #include "unitool.h" 72 79 73 80 //////////////////////////////////// … … 77 84 text_t::text_t () 78 85 { 86 setencoding(0); 79 87 clear (); 80 88 } … … 82 90 text_t::text_t (int i) 83 91 { 92 setencoding(0); 84 93 clear (); 85 94 appendint (i); … … 87 96 88 97 text_t::text_t (char *s) 89 { 98 { 99 setencoding(0); 90 100 clear (); 91 101 appendcstr (s); … … 223 233 while (ithere != itend) 224 234 { 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 } 227 243 len++; 228 244 ithere++; … … 241 257 while (ithere != itend) 242 258 { 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 } 245 267 len++; 246 268 ithere++; … … 425 447 void inconvertclass::convert (text_t &output, status_t &status) 426 448 { 449 output.clear(); 450 427 451 if (start == NULL || len == 0) 428 452 { … … 442 466 start = (char *)here; // save current position 443 467 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. 472 text_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; 444 501 } 445 502 … … 498 555 { 499 556 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 } 501 564 ++uoutput; 502 565 ++len; … … 508 571 } 509 572 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. 576 text_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 510 594 void outconvertclass::setostream (ostream *theouts) 511 595 {
Note:
See TracChangeset
for help on using the changeset viewer.