home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 October: Mac OS SDK / Dev.CD Oct 00 SDK1.toast / Development Kits / Mac OS / AIAT / Headers / Analysis / JapaneseTokenizer.h < prev    next >
Encoding:
Text File  |  1998-04-16  |  1.7 KB  |  76 lines  |  [TEXT/CWIE]

  1. // JapaneseTokenizer.h
  2. //    Copyright:    © 1996 - 1998 by Apple Computer, Inc., all rights reserved.
  3.  
  4. // This tokenizer breaks on changes from one writing system to another.  In
  5. // 1-byte text, it breaks on most non-alphanumeric characters, but allows
  6. // emebedded periods and commas because they might be decimal points.
  7.  
  8. #pragma once
  9. #ifndef JapaneseTokenizer_h
  10. #define JapaneseTokenizer_h
  11.  
  12. #pragma import on
  13. #if PRAGMA_STRUCT_ALIGN
  14.     #pragma options align=power
  15. #endif
  16.  
  17. #include <ctype.h>
  18. #include <Script.h>    // Macintosh platform specific include
  19.  
  20. #include "IAAnalysis.h"
  21. #include "IACharStream.h"
  22.  
  23. #pragma IA_BEGIN_EXPORTS
  24.  
  25. class DoubleByteChar
  26. {
  27. public:
  28.     UInt16                    code;
  29.     UInt8                    len;
  30.     UInt8                    kind;
  31.     IACharStream*            fCharStream;
  32.     bool                    ungetFlag;    // if true then do NOT getchar()
  33.     unsigned long             fCurrentPos; // position in stream
  34.     
  35.  
  36.     DoubleByteChar(IACharStream* stream) :
  37.         code(0), len(0), kind(0), ungetFlag(false),
  38.         fCurrentPos(0), fCharStream(stream) {}    
  39.     ~DoubleByteChar() {}
  40.     
  41.     OSErr GetNextDBChar();
  42.     short EndOfFile();
  43.     void UngetChar() {ungetFlag = true;}
  44.     UInt32 GetCurrentPos() {return fCharStream->CurrentPos();}
  45. private:
  46.     bool    IsTokenChar(int c){return isalnum(c) || strchr(".," ,c);}
  47.  
  48. };
  49.  
  50. class JapaneseTokenizer : public IATokenStream
  51. {
  52. public:
  53.     JapaneseTokenizer(IACharStream* stream);
  54.     ~JapaneseTokenizer(); // deletes fCharStream
  55.     
  56.     IAToken*    GetNextToken();
  57.     void        GetTextSpan(byte* buffer, uint32 startPos, uint32 endPos);
  58. private:
  59.     IAToken*    GetNextTokenInternal();
  60.     bool        BuildNextToken(StringPtr token, UInt32* startPos, UInt32* endPos);
  61.     IACharStream*        fCharStream;
  62.     DoubleByteChar*        fDBChar;
  63.     char*                buffer;
  64. };
  65.  
  66. #pragma IA_END_EXPORTS
  67.  
  68. #if PRAGMA_STRUCT_ALIGN
  69.     #pragma options align=reset
  70. #endif
  71.  
  72. #pragma import reset
  73.  
  74.  
  75. #endif
  76.