home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C++ / Applications / Nuntius 1.2 / src / Nuntius / ISO2022Conversion.h < prev    next >
Encoding:
Text File  |  1994-02-20  |  2.6 KB  |  112 lines  |  [TEXT/MPS ]

  1. // Copyright © 1993 Peter Speck (speck@dat.ruc.dk).  All rights reserved.
  2. // ISO2022Conversion.h
  3.  
  4. /*
  5.  *
  6.  * Japanese Text Code Converter
  7.  * Between Network Code and Macintosh Native Code
  8.  *
  9.  * Copyright (c) 1993 by Shigeru Kanemoto
  10.  *                   and HappySize Incorporated
  11.  *
  12.  *
  13.  */
  14.  
  15. // Ported to C++ by Peter Speck, juni 1993
  16.  
  17.  
  18. #ifndef __UPTROBJECT__
  19. #include "UPtrObject.h"
  20. #endif
  21.  
  22. #ifndef __UDYNDYNARRAY__
  23. #include "UDynDynArray.h"
  24. #endif
  25.  
  26. class PTextCodeConverter;
  27.  
  28. /* Code Conversion Direction */
  29. typedef enum {
  30.     tcvImport,        /* Import into Macintosh */
  31.     tcvExport,        /* Export from Macintosh */
  32. } TCVDirection;
  33.  
  34. typedef Boolean (PTextCodeConverter::*ImportFunc)();
  35. typedef Boolean (PTextCodeConverter::*ExportFunc)();
  36. // returns false when reaching end of text
  37.  
  38. class PTextCodeConverter : public PPtrObject
  39. {
  40.     public:
  41.         virtual void ConvertNet2Mac();
  42.         virtual void ConvertMac2Net();
  43.  
  44.         PTextCodeConverter();
  45.         virtual ~PTextCodeConverter();
  46.     protected:
  47.         virtual unsigned char GetNextChar() = 0;
  48.         // return Ascii0 if end of text
  49.         virtual void OutputOneChar(unsigned char ch) = 0;
  50.         virtual void OutputTwoChars(unsigned char ch1, unsigned char ch2) = 0;
  51.     
  52.     private:
  53.         ImportFunc fImportFunc;
  54.         ExportFunc fExportFunc;
  55.         unsigned char fCurrentExportChar;
  56.         
  57.         Boolean im_roman();
  58.         Boolean im_kana();
  59.         Boolean im_kanji();
  60.         Boolean ImportSwitch();
  61.         Boolean ex_roman();
  62.         Boolean ex_kana();
  63.         Boolean ex_kanji();
  64.         void ExportSwitchToRoman();
  65.         void ExportSwitchToKatakana();
  66.         void ExportSwitchToKanji();
  67. };
  68.  
  69. class PStringTextCodeConverter : public PTextCodeConverter
  70. {
  71.     public:
  72.         CStr255 fOutputString;
  73.         
  74.         virtual void ConvertNet2Mac();
  75.         virtual void ConvertMac2Net();
  76.  
  77.         PStringTextCodeConverter(const CStr255 &inputString);
  78.         virtual ~PStringTextCodeConverter();
  79.     protected:
  80.         virtual unsigned char GetNextChar();
  81.         virtual void OutputOneChar(unsigned char ch);
  82.         virtual void OutputTwoChars(unsigned char ch1, unsigned char ch2);
  83.  
  84.     private:
  85.         const CStr255 &fInputString;
  86.         short fInputIndex;
  87. };
  88.  
  89. class PHandleCodeConverter : public PTextCodeConverter
  90. {
  91.     public:
  92.         long GetOutputSize();
  93.         Ptr GetOutputPtr();
  94.         
  95.         virtual void ConvertNet2Mac();
  96.         virtual void ConvertMac2Net();
  97.  
  98.          // inputH now owned, but must be zero terminated!!!
  99.         PHandleCodeConverter();
  100.         void IHandleCodeConverter(Handle inputH, long outputChunk);
  101.         virtual ~PHandleCodeConverter();
  102.     protected:
  103.         virtual unsigned char GetNextChar();
  104.         virtual void OutputOneChar(unsigned char ch);
  105.         virtual void OutputTwoChars(unsigned char ch1, unsigned char ch2);
  106.  
  107.     private:
  108.         CChunkyHandle fOutput;
  109.         Handle fInputH;
  110.         long fInputOffset;
  111. };
  112.