- Timestamp:
- 2000-07-13T10:21:53+12:00 (24 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/New_Config_Format-branch/gsdl/lib/gsdlunicode.cpp
r1076 r1279 28 28 /* 29 29 $Log$ 30 Revision 1.12.2.1 2000/07/12 22:20:55 sjboddie 31 merged changes to trunk into New_Config_Format branch 32 33 Revision 1.14 2000/06/23 05:03:29 nzdl 34 fixed a couple of compiler warnings created by the new encoding stuff 35 36 Revision 1.13 2000/06/23 03:21:38 sjboddie 37 Created converter classes for simple 8 bit encodings that use a 38 simple textual map file. Instances of these classes are used to handle 39 the Windows 1256 (Arabic) encoding. 40 30 41 Revision 1.12 2000/04/06 19:58:02 cs025 31 42 Correcting a correction - reinstated all lib files due to silly … … 70 81 #include <stdio.h> 71 82 83 #if defined(GSDL_USE_OBJECTSPACE) 84 # include <ospace\std\iostream> 85 # include <ospace\std\fstream> 86 #elif defined(GSDL_USE_IOS_H) 87 # include <iostream.h> 88 # include <fstream.h> 89 #else 90 # include <iostream> 91 # include <fstream> 92 #endif 72 93 73 94 … … 551 572 else status = unfinished; 552 573 } 574 575 576 bool simplemapconvert::loadmapfile (bool in) { 577 if (loaded) return true; 578 if (mapfile.empty()) return false; 579 580 char *cfilename = mapfile.getcstr(); 581 #ifdef GSDL_USE_IOS_H 582 ifstream mapfilein (cfilename, ios::in | ios::nocreate); 583 #else 584 ifstream mapfilein (cfilename, ios::in); 585 #endif 586 delete cfilename; 587 if (!mapfilein) return false; 588 589 char cline[2048]; 590 text_t line; 591 592 while (!mapfilein.eof()) { 593 mapfilein.getline (cline, 2048); 594 line.clear(); 595 line.appendcstr (cline); 596 if (line.empty()) continue; 597 // remove comments 598 text_t::iterator end = line.end(); 599 text_t::iterator here = findchar (line.begin(), end, '#'); 600 if (here != end) { 601 line.erase (here, end); 602 if (line.empty()) continue; 603 } 604 605 text_tarray parts; 606 splitchar (line.begin(), line.end(), '\t', parts); 607 608 // do some simple sanity checks 609 if (parts.size() < 2) continue; 610 text_t::iterator begin1 = parts[0].begin(); 611 text_t::iterator begin2 = parts[1].begin(); 612 if (*begin1 != '0' || *(begin1+1) != 'x') continue; 613 if (*begin2 != '0' || *(begin2+1) != 'x') continue; 614 char *from = parts[0].getcstr(); 615 char *to = parts[1].getcstr(); 616 unsigned int f = 0, t = 0; 617 sscanf (from, "%i", &f); 618 sscanf (to, "%i", &t); 619 delete from; 620 delete to; 621 622 if (in) mapping[(unsigned short)f] = (unsigned short)t; 623 else mapping[(unsigned short)t] = (unsigned short)f; 624 } 625 626 loaded = true; 627 return true; 628 } 629 630 unsigned short simplemapconvert::convert (unsigned short c, bool in) { 631 632 if (!loaded) 633 if (!loadmapfile(in)) return absentc; 634 635 return mapping[c]; 636 } 637 638 639 void simplemapinconvertclass::convert (text_t &output, status_t &status) { 640 output.clear(); 641 642 if (start == NULL || len == 0) { 643 status = finished; 644 return; 645 } 646 647 // don't want any funny sign conversions happening 648 unsigned char *here = (unsigned char *)start; 649 while (len > 0) { 650 651 if (*here < 0x80) 652 output.push_back (*here); // append this character 653 else 654 output.push_back (converter.convert(*here, true)); 655 656 ++here; 657 --len; 658 } 659 660 start = (char *)here; // save current position 661 status = finished; 662 } 663 664 665 void simplemapoutconvertclass::convert (char *output, size_t maxlen, 666 size_t &len, status_t &status) { 667 668 if (input == NULL || output == NULL) { 669 status = finished; 670 return; 671 } 672 673 // don't want any funny sign conversions happening 674 unsigned char *uoutput = (unsigned char *)output; 675 text_t::iterator textend = input->end(); 676 len = 0; 677 while ((len < maxlen) && (texthere != textend)) { 678 679 if (*texthere < 0x80) *uoutput = (unsigned char)(*texthere); 680 else *uoutput = converter.convert (*texthere, false); 681 682 ++uoutput; 683 ++len; 684 ++texthere; 685 } 686 687 if (texthere == textend) status = finished; 688 else status = unfinished; 689 }
Note:
See TracChangeset
for help on using the changeset viewer.