home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 November / Chip_1998-11_cd.bin / tema / Cafe / main.bin / WordBreakData.java < prev    next >
Text File  |  1997-05-20  |  16KB  |  330 lines

  1. /*
  2.  * @(#)WordBreakData.java    1.5 97/01/17
  3.  *
  4.  * (C) Copyright Taligent, Inc. 1996 - All Rights Reserved
  5.  * (C) Copyright IBM Corp. 1996 - All Rights Reserved
  6.  *
  7.  * Portions copyright (c) 1996 Sun Microsystems, Inc. All Rights Reserved.
  8.  *
  9.  *   The original version of this source code and documentation is copyrighted
  10.  * and owned by Taligent, Inc., a wholly-owned subsidiary of IBM. These
  11.  * materials are provided under terms of a License Agreement between Taligent
  12.  * and Sun. This technology is protected by multiple US and International
  13.  * patents. This notice and attribution to Taligent may not be removed.
  14.  *   Taligent is a registered trademark of Taligent, Inc.
  15.  *
  16.  * Permission to use, copy, modify, and distribute this software
  17.  * and its documentation for NON-COMMERCIAL purposes and without
  18.  * fee is hereby granted provided that this copyright notice
  19.  * appears in all copies. Please refer to the file "copyright.html"
  20.  * for further important copyright and licensing information.
  21.  *
  22.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
  23.  * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
  24.  * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  25.  * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
  26.  * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
  27.  * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
  28.  *
  29.  */
  30.  
  31. package java.text;
  32.  
  33. /**
  34.  * The WordBreakData contains data used by SimpleTextBoundary
  35.  * to determine word breaks.
  36.  * @see #BreakIterator
  37.  */
  38. final class WordBreakData extends TextBoundaryData
  39. {
  40.     private static final byte BREAK = 0;
  41.     private static final byte letter = 1;
  42.     private static final byte number = 2;
  43.     private static final byte midLetter = 3;
  44.     private static final byte midLetNum = 4;
  45.     private static final byte preNum = 5;
  46.     private static final byte postNum = 6;
  47.     private static final byte midNum = 7;
  48.     private static final byte preMidNum = 8;
  49.     private static final byte blank = 9;
  50.     private static final byte cr = 10;
  51.     private static final byte kata = 11;
  52.     private static final byte hira = 12;
  53.     private static final byte kanji = 13;
  54.     private static final byte diacrit = 14;
  55.     private static final int COL_COUNT = 15;
  56.     private static final byte SI = (byte)0x80;
  57.     private static final byte kWordForwardData[] =
  58.     {
  59.         // brk        let            num          mLe           mLN
  60.         // prN        poN            mNu          pMN           blk
  61.         // cr         kat            hir          kan           dia
  62.  
  63.         (byte)(0),    (byte)(0),    (byte)(0),    (byte)(0),    (byte)(0),
  64.         (byte)(0),    (byte)(0),    (byte)(0),    (byte)(0),    (byte)(0),
  65.         (byte)(0),    (byte)(0),    (byte)(0),    (byte)(0),    (byte)(0),
  66.  
  67.         (byte)(SI+4), (byte)(SI+2), (byte)(SI+3), (byte)(SI+4), (byte)(SI+4),
  68.         (byte)(SI+5), (byte)(SI+4), (byte)(SI+4), (byte)(SI+5), (byte)(SI+6),
  69.         (byte)(SI+4),(byte)(SI+10),(byte)(SI+11),(byte)(SI+12), (byte)(SI+9),
  70.  
  71.         (byte)(SI+0), (byte)(SI+2), (byte)(SI+3), (byte)(SI+7), (byte)(SI+7),
  72.         (byte)(SI+0), (byte)(SI+0), (byte)(SI+0), (byte)(SI+7), (byte)(SI+0),
  73.         (byte)(SI+0), (byte)(SI+0), (byte)(SI+0), (byte)(SI+0), (byte)(SI+0),
  74.  
  75.         (byte)(SI+0), (byte)(SI+2), (byte)(SI+3), (byte)(SI+0), (byte)(SI+8),
  76.         (byte)(SI+0), (byte)(SI+4), (byte)(SI+8), (byte)(SI+8), (byte)(SI+0),
  77.         (byte)(SI+0), (byte)(SI+0), (byte)(SI+0), (byte)(SI+0), (byte)(SI+0),
  78.  
  79.         (byte)(SI+0), (byte)(SI+0), (byte)(SI+0), (byte)(SI+0), (byte)(SI+0),
  80.         (byte)(SI+0), (byte)(SI+0), (byte)(SI+0), (byte)(SI+0), (byte)(SI+0),
  81.         (byte)(SI+0), (byte)(SI+0), (byte)(SI+0), (byte)(SI+0), (byte)(SI+0),
  82.  
  83.         (byte)(SI+0), (byte)(SI+0), (byte)(SI+3), (byte)(SI+0), (byte)(SI+0),
  84.         (byte)(SI+0), (byte)(SI+0), (byte)(SI+0), (byte)(SI+0), (byte)(SI+0),
  85.         (byte)(SI+0), (byte)(SI+0), (byte)(SI+0), (byte)(SI+0), (byte)(SI+0),
  86.  
  87.         (byte)(SI+0), (byte)(SI+0), (byte)(SI+0), (byte)(SI+0), (byte)(SI+0),
  88.         (byte)(SI+0), (byte)(SI+0), (byte)(SI+0), (byte)(SI+0), (byte)(SI+6),
  89.         (byte)(SI+4), (byte)(SI+0), (byte)(SI+0), (byte)(SI+0), (byte)(SI+0),
  90.  
  91.         (byte)(0), (byte)(SI+2),    (byte)(0),    (byte)(0),    (byte)(0),
  92.         (byte)(0),    (byte)(0),    (byte)(0),    (byte)(0),    (byte)(0),
  93.         (byte)(0),    (byte)(0),    (byte)(0),    (byte)(0),    (byte)(0),
  94.  
  95.         (byte)(0),    (byte)(0), (byte)(SI+3),    (byte)(0),    (byte)(0),
  96.         (byte)(0),    (byte)(0),    (byte)(0),    (byte)(0),    (byte)(0),
  97.         (byte)(0),    (byte)(0),    (byte)(0),    (byte)(0),    (byte)(0),
  98.  
  99.         (byte)(SI+0), (byte)(SI+0), (byte)(SI+0), (byte)(SI+0), (byte)(SI+0),
  100.         (byte)(SI+0), (byte)(SI+0), (byte)(SI+0), (byte)(SI+0), (byte)(SI+0),
  101.         (byte)(SI+0),(byte)(SI+10),(byte)(SI+11), (byte)(SI+0), (byte)(SI+9),
  102.  
  103.         (byte)(SI+0), (byte)(SI+0), (byte)(SI+0), (byte)(SI+0), (byte)(SI+0),
  104.         (byte)(SI+0), (byte)(SI+0), (byte)(SI+0), (byte)(SI+0), (byte)(SI+0),
  105.         (byte)(SI+0),(byte)(SI+10), (byte)(SI+0), (byte)(SI+0),(byte)(SI+10),
  106.  
  107.         (byte)(SI+0), (byte)(SI+0), (byte)(SI+0), (byte)(SI+0), (byte)(SI+0),
  108.         (byte)(SI+0), (byte)(SI+0), (byte)(SI+0), (byte)(SI+0), (byte)(SI+0),
  109.         (byte)(SI+0), (byte)(SI+0),(byte)(SI+11), (byte)(SI+0),(byte)(SI+11),
  110.  
  111.         (byte)(SI+0), (byte)(SI+0), (byte)(SI+0), (byte)(SI+0), (byte)(SI+0),
  112.         (byte)(SI+0), (byte)(SI+0), (byte)(SI+0), (byte)(SI+0), (byte)(SI+0),
  113.         (byte)(SI+0), (byte)(SI+0), (byte)(SI+0),(byte)(SI+12), (byte)(SI+0)
  114.     };
  115.     private static final WordBreakTable kWordForward =
  116.     new WordBreakTable(COL_COUNT, kWordForwardData);
  117.     private static final byte kWordBackwardData[] =
  118.     {
  119.         // brk         let             num            mLe           mLN
  120.         // prN         poN             mNu            pMN           blk
  121.         // cr          kat             hir            kan           dia
  122.         (byte)(0),    (byte)(0),    (byte)(0),    (byte)(0),    (byte)(0),
  123.         (byte)(0),    (byte)(0),    (byte)(0),    (byte)(0),    (byte)(0),
  124.         (byte)(0),    (byte)(0),    (byte)(0),    (byte)(0),    (byte)(0),
  125.  
  126.         (byte)(SI+6), (byte)(SI+2), (byte)(SI+3), (byte)(SI+4), (byte)(SI+5),
  127.         (byte)(SI+6), (byte)(SI+7), (byte)(SI+7), (byte)(SI+5), (byte)(SI+8),
  128.         (byte)(SI+8), (byte)(SI+9),(byte)(SI+10),(byte)(SI+12),(byte)(SI+11),
  129.  
  130.         (byte)(0), (byte)(SI+2), (byte)(SI+3),    (byte)(4),    (byte)(4),
  131.         (byte)(0),    (byte)(0),    (byte)(0),    (byte)(4),    (byte)(0),
  132.         (byte)(0),    (byte)(0),    (byte)(0),    (byte)(0),    (byte)(0),
  133.  
  134.         (byte)(0), (byte)(SI+2), (byte)(SI+3),    (byte)(0),    (byte)(7),
  135.         (byte)(SI+0),    (byte)(0),    (byte)(7), (byte)(SI+7),    (byte)(0),
  136.         (byte)(0),    (byte)(0),    (byte)(0),    (byte)(0),    (byte)(0),
  137.  
  138.         (byte)(0), (byte)(SI+2),    (byte)(0),    (byte)(0),    (byte)(0),
  139.         (byte)(0),    (byte)(0),    (byte)(0),    (byte)(0),    (byte)(0),
  140.         (byte)(0),    (byte)(0),    (byte)(0),    (byte)(0),    (byte)(0),
  141.  
  142.         (byte)(0), (byte)(SI+2), (byte)(SI+3),    (byte)(0),    (byte)(0),
  143.         (byte)(0),    (byte)(0),    (byte)(0),    (byte)(0),    (byte)(0),
  144.         (byte)(0),    (byte)(0),    (byte)(0),    (byte)(0),    (byte)(0),
  145.  
  146.         (byte)(0),    (byte)(0),    (byte)(0),    (byte)(0),    (byte)(0),
  147.         (byte)(0),    (byte)(0),    (byte)(0),    (byte)(0),    (byte)(0),
  148.         (byte)(0),    (byte)(0),    (byte)(0),    (byte)(0),    (byte)(0),
  149.  
  150.         (byte)(0),    (byte)(0), (byte)(SI+3),    (byte)(0),    (byte)(0),
  151.         (byte)(0),    (byte)(0),    (byte)(0),    (byte)(0),    (byte)(0),
  152.         (byte)(0),    (byte)(0),    (byte)(0),    (byte)(0),    (byte)(0),
  153.  
  154.         (byte)(0),    (byte)(0),    (byte)(0),    (byte)(0),    (byte)(0),
  155.         (byte)(0),    (byte)(0),    (byte)(0),    (byte)(0), (byte)(SI+8),
  156.         (byte)(0),    (byte)(0),    (byte)(0),    (byte)(0),    (byte)(0),
  157.  
  158.         (byte)(0),    (byte)(0),    (byte)(0),    (byte)(0),    (byte)(0),
  159.         (byte)(0),    (byte)(0),    (byte)(0),    (byte)(0),    (byte)(0),
  160.         (byte)(0), (byte)(SI+9),    (byte)(0),    (byte)(0),    (byte)(9),
  161.  
  162.         (byte)(0),    (byte)(0),    (byte)(0),    (byte)(0),    (byte)(0),
  163.         (byte)(0),    (byte)(0),    (byte)(0),    (byte)(0),    (byte)(0),
  164.         (byte)(0),    (byte)(0),(byte)(SI+10),    (byte)(0),   (byte)(10),
  165.  
  166.         (byte)(0),    (byte)(0),    (byte)(0),    (byte)(0),    (byte)(0),
  167.         (byte)(0),    (byte)(0),    (byte)(0),    (byte)(0),    (byte)(0),
  168.         (byte)(0), (byte)(SI+9),(byte)(SI+10),    (byte)(0),(byte)(SI+11),
  169.  
  170.         (byte)(0),    (byte)(0),    (byte)(0),    (byte)(0),    (byte)(0),
  171.         (byte)(0),    (byte)(0),    (byte)(0),    (byte)(0),    (byte)(0),
  172.         (byte)(0),    (byte)(0),    (byte)(0),(byte)(SI+12),    (byte)(0)
  173.     };
  174.     private static final WordBreakTable kWordBackward =
  175.     new WordBreakTable(COL_COUNT, kWordBackwardData);
  176.     private static final int kRawMapping[] =
  177.     {
  178.         BREAK, //UNASSIGNED        = 0,
  179.         letter, //UPPERCASE_LETTER    = 1,
  180.         letter, //LOWERCASE_LETTER    = 2,
  181.         letter, //TITLECASE_LETTER    = 3,
  182.         letter, //MODIFIER_LETTER        = 4,
  183.         letter, //OTHER_LETTER        = 5,
  184.         BREAK, //NON_SPACING_MARK    = 6,
  185.         BREAK, //ENCLOSING_MARK        = 7,
  186.         BREAK, //COMBINING_SPACING_MARK    = 8,
  187.         number, //DECIMAL_DIGIT_NUMBER    = 9,
  188.         letter, //LETTER_NUMBER        = 10,
  189.         number, //OTHER_NUMBER        = 11,
  190.         blank, //SPACE_SEPARATOR        = 12,
  191.         BREAK, //LINE_SEPARATOR        = 13,
  192.         BREAK, //PARAGRAPH_SEPARATOR    = 14,
  193.         BREAK, //CONTROL            = 15,
  194.         BREAK, //PRIVATE_USE        = 16,
  195.         BREAK, //FORMAT        = 17,
  196.         BREAK, //???        = 18,
  197.         BREAK, //SURROGATE        = 19,
  198.         midLetter, //DASH_PUNCTUATION    = 20,
  199.         BREAK, //START_PUNCTUATION    = 21,
  200.         BREAK, //END_PUNCTUATION        = 22,
  201.         BREAK, //CONNECTOR_PUNCTUATION    = 23,
  202.         BREAK, //OTHER_PUNCTUATION    = 24,
  203.         BREAK, //MATH_SYMBOL        = 25,
  204.         preNum, //CURRENCY_SYMBOL        = 26,
  205.         BREAK, //MODIFIER_SYMBOL        = 27,
  206.         BREAK //OTHER_SYMBOL        = 28
  207.     };
  208. /*  private static final int kRawMapping[] =
  209.     {
  210.         BREAK, //00   Invalid
  211.         blank, //01   SpaceWhitespace
  212.         blank, //02   ZerowidthSpaceWhitespace
  213.         BREAK, //03   ISOcontrol
  214.         blank, //04   WhitespaceISOcontrol
  215.         BREAK, //05   Dash
  216.         BREAK, //06   Punctuation
  217.         midLetter, //07   DashPunctuation
  218.         BREAK, //08   HyphenPunctuation
  219.         midLetter, //09   DashHyphenPunctuation
  220.         BREAK, //10   PunctuationQuotationmark
  221.         BREAK, //11   PunctuationTerminalpunctuation
  222.         preNum, //12   Currencysymbol
  223.         BREAK, //13   PunctuationPairedpunctuation
  224.         BREAK, //14   PunctuationQuotationmarkPairedpunctuation
  225.         BREAK, //15   PunctuationPairedpunctuationLeftofpair
  226.         BREAK, //16   PunctuationQuotationmarkPairedpunctuationLeftofpair
  227.         BREAK, //17   PunctuationPairedpunctuationCombining
  228.         BREAK, //18   PunctuationPairedpunctuationLeftofpairCombining
  229.         BREAK, //19   Composite
  230.         number, //20   Numeric
  231.         number, //21   CompositeNumeric
  232.         letter, //22   PunctuationAlphabetic
  233.         letter, //23   Diacritic
  234.         letter, //24   CompositeDiacritic
  235.         BREAK, //25   PunctuationIdentifierpart
  236.         number, //26   DecimaldigitNumericIdentifierpart
  237.         number, //27   HexdigitDecimaldigitNumericIdentifierpart
  238.         letter, //28   AlphabeticIdentifierpart
  239.         BREAK, //29   CombiningAlphabeticIdentifierpart
  240.         letter, //30   CompositeAlphabeticIdentifierpart
  241.         BREAK, //31   CombiningCompositeAlphabeticIdentifierpart
  242.         letter, //32   NumericAlphabeticIdentifierpart
  243.         letter, //33   CompositeNumericAlphabeticIdentifierpart
  244.         letter, //34   IdeographicIdentifierpart
  245.         letter, //35   NumericIdeographicIdentifierpart
  246.         BREAK, //36   CombiningDiacriticIdentifierpart
  247.         BREAK, //37   ExtenderIdentifierpart
  248.         BREAK, //38   CompositeExtenderIdentifierpart
  249.         letter, //39   DiacriticExtenderIdentifierpart
  250.         letter, //40   PunctuationDiacriticExtenderIdentifierpart
  251.         blank, //41   ZerowidthWhitespaceBidicontrolIgnorablecontrol
  252.         blank, //42   ZerowidthWhitespaceJoincontrolIgnorablecontrol
  253.         blank, //43   ZerowidthWhitespaceFormatcontrolIgnorablecontrol
  254.         letter, //44   AlphabeticIdentifierpartLower
  255.         letter, //45   CompositeAlphabeticIdentifierpartLower
  256.         letter, //46   HexdigitAlphabeticIdentifierpartLower
  257.         letter, //47   AlphabeticIdentifierpartUpper
  258.         letter, //48   CompositeAlphabeticIdentifierpartUpper
  259.         letter, //49   HexdigitAlphabeticIdentifierpartUpper
  260.         letter, //50   CompositeAlphabeticIdentifierpartTitle
  261.         BREAK, //51   Marknonspacing
  262.         BREAK, //52   CombiningMarknonspacing
  263.         BREAK, //53   CombiningIdentifierpartMarknonspacing
  264.         letter, //54   AlphabeticIdentifierpartMarknonspacing
  265.         BREAK, //55   CombiningAlphabeticIdentifierpartMarknonspacing
  266.         letter, //56   CompositeAlphabeticIdentifierpartMarknonspacing
  267.         BREAK, //57   CombiningCompositeAlphabeticIdentifierpartMarknonspacing
  268.         BREAK, //58   CombiningDiacriticIdentifierpartMarknonspacing
  269.         BREAK, //59   CombiningCompositeDiacriticIdentifierpartMarknonspacing
  270.         BREAK, //60   WhitespaceNongraphicSeparator
  271.         BREAK, //61   WhitespaceISOcontrolNongraphicSeparator
  272.         BREAK, //62   SpaceWhitespaceNongraphicNobreak
  273.         BREAK,
  274.         //63   ZerowidthSpaceWhitespaceIgnorablecontrolNongraphicNobreak
  275.  
  276.     };*/
  277.     private static SpecialMapping kExceptionChar[] =
  278.     {
  279.         //note: the ranges in this table must be sorted in ascending order
  280.         //as required by the UnicodeClassMapping class.
  281.         new SpecialMapping(ASCII_HORIZONTAL_TABULATION, blank),
  282.         new SpecialMapping(ASCII_LINEFEED, cr),
  283.         new SpecialMapping(ASCII_FORM_FEED, ASCII_CARRIAGE_RETURN, cr),
  284.         new SpecialMapping(ASCII_QUOTATION_MARK, midLetNum),
  285.         new SpecialMapping(ASCII_NUMBER_SIGN, preNum),
  286.         new SpecialMapping(ASCII_PERCENT, postNum),
  287.         new SpecialMapping(ASCII_AMPERSAND, postNum),
  288.         new SpecialMapping(ASCII_APOSTROPHE, midLetNum),
  289.         new SpecialMapping(ASCII_COMMA, midNum),
  290.         new SpecialMapping(ASCII_FULL_STOP, preMidNum),
  291.         new SpecialMapping(ASCII_CENT_SIGN, postNum),
  292.         new SpecialMapping(LATIN1_SOFTHYPHEN, midLetter),
  293.         new SpecialMapping(ARABIC_PERCENT_SIGN, postNum),
  294.         new SpecialMapping(ARABIC_DECIMAL_SEPARATOR, midNum),
  295.         new SpecialMapping(PUNCTUATION_HYPHENATION_POINT, midLetter),
  296.         new SpecialMapping(PUNCTUATION_LINE_SEPARATOR,
  297.                            PUNCTUATION_PARAGRAPH_SEPARATOR, cr),
  298.         new SpecialMapping(PER_MILLE_SIGN, postNum),
  299.         new SpecialMapping(PER_TEN_THOUSAND_SIGN, postNum),
  300.         new SpecialMapping(HIRAGANA_LETTER_SMALL_A, HIRAGANA_LETTER_VU, hira),
  301.         new SpecialMapping(COMBINING_KATAKANA_HIRAGANA_VOICED_SOUND_MARK,
  302.                            HIRAGANA_SEMIVOICED_SOUND_MARK, diacrit),
  303.         new SpecialMapping(KATAKANA_LETTER_SMALL_A,
  304.                            KATAKANA_LETTER_SMALL_KE, kata),
  305.         new SpecialMapping(UNICODE_LOW_BOUND_HAN,
  306.                            UNICODE_HIGH_BOUND_HAN, kanji),
  307.         new SpecialMapping(HANGUL_SYL_LOW, HANGUL_SYL_HIGH, letter),
  308.         new SpecialMapping(CJK_COMPATIBILITY_F900,
  309.                            CJK_COMPATIBILITY_FA2D, kanji),
  310.     };
  311.     private static final UnicodeClassMapping kWordMap
  312.         = new UnicodeClassMapping(kRawMapping, kExceptionChar);
  313.  
  314.     public WordBreakTable forward()
  315.     {
  316.         return kWordForward;
  317.     }
  318.  
  319.     public WordBreakTable backward()
  320.     {
  321.         return kWordBackward;
  322.     }
  323.  
  324.     public UnicodeClassMapping map()
  325.     {
  326.         return kWordMap;
  327.     }
  328. }
  329.  
  330.