Path: blob/master/src/java.base/share/classes/sun/text/resources/BreakIteratorRules.java
41159 views
/*1* Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425/*26*/2728/*29* Licensed Materials - Property of IBM30*31* (C) Copyright IBM Corp. 1999 All Rights Reserved.32* (C) IBM Corp. 1997-1998. All Rights Reserved.33*34* The program is provided "as is" without any warranty express or35* implied, including the warranty of non-infringement and the implied36* warranties of merchantibility and fitness for a particular purpose.37* IBM will not be liable for any damages suffered by you as a result38* of using the Program. In no event will IBM be liable for any39* special, indirect or consequential damages or lost profits even if40* IBM has been advised of the possibility of their occurrence. IBM41* will not be liable for any third party claims against you.42*/4344package sun.text.resources;4546import java.util.ListResourceBundle;4748/**49* Default break-iterator rules. These rules are more or less general for50* all locales, although there are probably a few we're missing. The51* behavior currently mimics the behavior of BreakIterator in JDK 1.2.52* There are known deficiencies in this behavior, including the fact that53* the logic for handling CJK characters works for Japanese but not for54* Chinese, and that we don't currently have an appropriate locale for55* Thai. The resources will eventually be updated to fix these problems.56*/5758/* Modified for Hindi 3/1/99. */5960/*61* Since JDK 1.5.0, this file no longer goes to runtime and is used at J2SE62* build phase in order to create [Character|Word|Line|Sentence]BreakIteratorData63* files which are used on runtime instead.64*/6566public class BreakIteratorRules extends ListResourceBundle {67protected final Object[][] getContents() {68return new Object[][] {69// rules describing how to break between logical characters70{ "CharacterBreakRules",7172// ignore non-spacing marks and enclosing marks (since we never73// put a break before ignore characters, this keeps combining74// accents with the base characters they modify)75"<enclosing>=[:Mn::Me:];"7677// other category definitions78+ "<choseong>=[\u1100-\u115f];"79+ "<jungseong>=[\u1160-\u11a7];"80+ "<jongseong>=[\u11a8-\u11ff];"81+ "<surr-hi>=[\ud800-\udbff];"82+ "<surr-lo>=[\udc00-\udfff];"8384// break after every character, except as follows:85+ ".;"8687// keep base and combining characters togethers88+ "<base>=[^<enclosing>^[:Cc::Cf::Zl::Zp:]];"89+ "<base><enclosing><enclosing>*;"9091// keep CRLF sequences together92+ "\r\n;"9394// keep surrogate pairs together95+ "<surr-hi><surr-lo>;"9697// keep Hangul syllables spelled out using conjoining jamo together98+ "<choseong>*<jungseong>*<jongseong>*;"99100// various additions for Hindi support101+ "<nukta>=[\u093c];"102+ "<danda>=[\u0964\u0965];"103+ "<virama>=[\u094d];"104+ "<devVowelSign>=[\u093e-\u094c\u0962\u0963];"105+ "<devConsonant>=[\u0915-\u0939];"106+ "<devNuktaConsonant>=[\u0958-\u095f];"107+ "<devCharEnd>=[\u0902\u0903\u0951-\u0954];"108+ "<devCAMN>=(<devConsonant>{<nukta>});"109+ "<devConsonant1>=(<devNuktaConsonant>|<devCAMN>);"110+ "<zwj>=[\u200d];"111+ "<devConjunct>=({<devConsonant1><virama>{<zwj>}}<devConsonant1>);"112+ "<devConjunct>{<devVowelSign>}{<devCharEnd>};"113+ "<danda><nukta>;"114},115116// default rules for finding word boundaries117{ "WordBreakRules",118// ignore non-spacing marks, enclosing marks, and format characters,119// all of which should not influence the algorithm120//"<ignore>=[:Mn::Me::Cf:];"121"<ignore>=[:Cf:];"122123+ "<enclosing>=[:Mn::Me:];"124125// Hindi phrase separator, kanji, katakana, hiragana, CJK diacriticals,126// other letters, and digits127+ "<danda>=[\u0964\u0965];"128+ "<kanji>=[\u3005\u4e00-\u9fa5\uf900-\ufa2d];"129+ "<kata>=[\u30a1-\u30fa\u30fd\u30fe];"130+ "<hira>=[\u3041-\u3094\u309d\u309e];"131+ "<cjk-diacrit>=[\u3099-\u309c\u30fb\u30fc];"132+ "<letter-base>=[:L::Mc:^[<kanji><kata><hira><cjk-diacrit>]];"133+ "<let>=(<letter-base><enclosing>*);"134+ "<digit-base>=[:N:];"135+ "<dgt>=(<digit-base><enclosing>*);"136137// punctuation that can occur in the middle of a word: currently138// dashes, apostrophes, quotation marks, and periods139+ "<mid-word>=[:Pd::Pc:\u00ad\u2027\\\"\\\'\\.];"140141// punctuation that can occur in the middle of a number: currently142// apostrophes, qoutation marks, periods, commas, and the Arabic143// decimal point144+ "<mid-num>=[\\\"\\\'\\,\u066b\\.];"145146// punctuation that can occur at the beginning of a number: currently147// the period, the number sign, and all currency symbols except the cents sign148+ "<pre-num>=[:Sc:\\#\\.^\u00a2];"149150// punctuation that can occur at the end of a number: currently151// the percent, per-thousand, per-ten-thousand, and Arabic percent152// signs, the cents sign, and the ampersand153+ "<post-num>=[\\%\\&\u00a2\u066a\u2030\u2031];"154155// line separators: currently LF, FF, PS, and LS156+ "<ls>=[\n\u000c\u2028\u2029];"157158// whitespace: all space separators and the tab character159+ "<ws-base>=[:Zs:\t];"160+ "<ws>=(<ws-base><enclosing>*);"161162// a word is a sequence of letters that may contain internal163// punctuation, as long as it begins and ends with a letter and164// never contains two punctuation marks in a row165+ "<word>=((<let><let>*(<mid-word><let><let>*)*){<danda>});"166167// a number is a sequence of digits that may contain internal168// punctuation, as long as it begins and ends with a digit and169// never contains two punctuation marks in a row.170+ "<number>=(<dgt><dgt>*(<mid-num><dgt><dgt>*)*);"171172// break after every character, with the following exceptions173// (this will cause punctuation marks that aren't considered174// part of words or numbers to be treated as words unto themselves)175+ ".;"176177// keep together any sequence of contiguous words and numbers178// (including just one of either), plus an optional trailing179// number-suffix character180+ "{<word>}(<number><word>)*{<number>{<post-num>}};"181182// keep together and sequence of contiguous words and numbers183// that starts with a number-prefix character and a number,184// and may end with a number-suffix character185+ "<pre-num>(<number><word>)*{<number>{<post-num>}};"186187// keep together runs of whitespace (optionally with a single trailing188// line separator or CRLF sequence)189+ "<ws>*{\r}{<ls>};"190191// keep together runs of Katakana and CJK diacritical marks192+ "[<kata><cjk-diacrit>]*;"193194// keep together runs of Hiragana and CJK diacritical marks195+ "[<hira><cjk-diacrit>]*;"196197// keep together runs of Kanji198+ "<kanji>*;"199200// keep together anything else and an enclosing mark201+ "<base>=[^<enclosing>^[:Cc::Cf::Zl::Zp:]];"202+ "<base><enclosing><enclosing>*;"203},204205// default rules for determining legal line-breaking positions206{ "LineBreakRules",207// characters that always cause a break: ETX, tab, LF, FF, LS, and PS208"<break>=[\u0003\t\n\f\u2028\u2029];"209210// ignore format characters and control characters EXCEPT for breaking chars211+ "<ignore>=[:Cf:[:Cc:^[<break>\r]]];"212213// enclosing marks214+ "<enclosing>=[:Mn::Me:];"215216// Hindi phrase separators217+ "<danda>=[\u0964\u0965];"218219// characters that always prevent a break: the non-breaking space220// and similar characters221+ "<glue>=[\u00a0\u0f0c\u2007\u2011\u202f\ufeff];"222223// whitespace: space separators and control characters, except for224// CR and the other characters mentioned above225+ "<space>=[:Zs::Cc:^[<glue><break>\r]];"226227// dashes: dash punctuation and the discretionary hyphen, except for228// non-breaking hyphens229+ "<dash>=[:Pd:\u00ad^<glue>];"230231// characters that stick to a word if they precede it: currency symbols232// (except the cents sign) and starting punctuation233+ "<pre-word>=[:Sc::Ps::Pi:^[\u00a2]\\\"\\\'];"234235// characters that stick to a word if they follow it: ending punctuation,236// other punctuation that usually occurs at the end of a sentence,237// small Kana characters, some CJK diacritics, etc.238+ "<post-word>=[\\\":Pe::Pf:\\!\\%\\.\\,\\:\\;\\?\u00a2\u00b0\u066a\u2030-\u2034\u2103"239+ "\u2105\u2109\u3001\u3002\u3005\u3041\u3043\u3045\u3047\u3049\u3063"240+ "\u3083\u3085\u3087\u308e\u3099-\u309e\u30a1\u30a3\u30a5\u30a7\u30a9"241+ "\u30c3\u30e3\u30e5\u30e7\u30ee\u30f5\u30f6\u30fc-\u30fe\uff01\uff05"242+ "\uff0c\uff0e\uff1a\uff1b\uff1f];"243244// Kanji: actually includes Kanji,Kana and Hangul syllables,245// except for small Kana and CJK diacritics246+ "<kanji>=[\u4e00-\u9fa5\uac00-\ud7a3\uf900-\ufa2d\ufa30-\ufa6a\u3041-\u3094\u30a1-\u30fa^[<post-word><ignore>]];"247248// digits249+ "<digit>=[:Nd::No:];"250251// punctuation that can occur in the middle of a number: periods and commas252+ "<mid-num>=[\\.\\,];"253254// everything not mentioned above255+ "<char>=[^[<break><space><dash><kanji><glue><ignore><pre-word><post-word><mid-num>\r<danda>]];"256257// a "number" is a run of prefix characters and dashes, followed by one or258// more digits with isolated number-punctuation characters interspersed259+ "<number>=([<pre-word><dash>]*<digit><digit>*(<mid-num><digit><digit>*)*);"260261// the basic core of a word can be either a "number" as defined above, a single262// "Kanji" character, or a run of any number of not-explicitly-mentioned263// characters (this includes Latin letters)264+ "<word-core>=(<char>*|<kanji>|<number>);"265266// a word may end with an optional suffix that be either a run of one or267// more dashes or a run of word-suffix characters268+ "<word-suffix>=((<dash><dash>*|<post-word>*));"269270// a word, thus, is an optional run of word-prefix characters, followed by271// a word core and a word suffix (the syntax of <word-core> and <word-suffix>272// actually allows either of them to match the empty string, putting a break273// between things like ")(" or "aaa(aaa"274+ "<word>=(<pre-word>*<word-core><word-suffix>);"275276+ "<hack1>=[\\(];"277+ "<hack2>=[\\)];"278+ "<hack3>=[\\$\\'];"279280// finally, the rule that does the work: Keep together any run of words that281// are joined by runs of one of more non-spacing mark. Also keep a trailing282// line-break character or CRLF combination with the word. (line separators283// "win" over nbsp's)284+ "<word>(((<space>*<glue><glue>*{<space>})|<hack3>)<word>)*<space>*{<enclosing>*}{<hack1><hack2><post-word>*}{<enclosing>*}{\r}{<break>};"285+ "\r<break>;"286},287288// default rules for finding sentence boundaries289{ "SentenceBreakRules",290// ignore non-spacing marks, enclosing marks, and format characters291"<ignore>=[:Mn::Me::Cf:];"292293// letters294+ "<letter>=[:L:];"295296// lowercase letters297+ "<lc>=[:Ll:];"298299// uppercase letters300+ "<uc>=[:Lu:];"301302// NOT lowercase letters303+ "<notlc>=[<letter>^<lc>];"304305// whitespace (line separators are treated as whitespace)306+ "<space>=[\t\r\f\n\u2028:Zs:];"307308// punctuation which may occur at the beginning of a sentence: "starting309// punctuation" and quotation marks310+ "<start-punctuation>=[:Ps::Pi:\\\"\\\'];"311312// punctuation which may occur at the end of a sentence: "ending punctuation"313// and quotation marks314+ "<end>=[:Pe::Pf:\\\"\\\'];"315316// digits317+ "<digit>=[:N:];"318319// characters that unambiguously signal the end of a sentence320+ "<term>=[\\!\\?\u3002\uff01\uff1f];"321322// periods, which MAY signal the end of a sentence323+ "<period>=[\\.\uff0e];"324325// comma, which may not occur at the start of a sentence326+ "<comma>=[\\,];"327328// characters that may occur at the beginning of a sentence: basically anything329// not mentioned above (letters and digits are specifically excluded)330+ "<sent-start>=[^[:L:<space><start-punctuation><end><digit><term><period><comma>\u2029<ignore>]];"331332// Hindi phrase separator333+ "<danda>=[\u0964\u0965];"334335// always break sentences after paragraph separators336+ ".*?{\u2029};"337338// always break after a danda, if it's followed by whitespace339+ ".*?<danda><space>*;"340341// if you see a period, skip over additional periods and ending punctuation342// and if the next character is a paragraph separator, break after the343// paragraph separator344//+ ".*?<period>[<period><end>]*<space>*\u2029;"345//+ ".*?[<period><end>]*<space>*\u2029;"346347// if you see a period, skip over additional periods and ending punctuation,348// followed by optional whitespace, followed by optional starting punctuation,349// and if the next character is something that can start a sentence350// (basically, a capital letter), then put the sentence break between the351// whitespace and the opening punctuation352+ ".*?<period>[<period><end>]*<space><space>*/<notlc>;"353+ ".*?<period>[<period><end>]*<space>*/[<start-punctuation><sent-start>][<start-punctuation><sent-start>]*<letter>;"354355// if you see a sentence-terminating character, skip over any additional356// terminators, periods, or ending punctuation, followed by any whitespace,357// followed by a SINGLE optional paragraph separator, and put the break there358+ ".*?<term>[<term><period><end>]*<space>*{\u2029};"359360// The following rules are here to aid in backwards iteration. The automatically361// generated backwards state table will rewind to the beginning of the362// paragraph all the time (or all the way to the beginning of the document363// if the document doesn't use the Unicode PS character) because the only364// unambiguous character pairs are those involving paragraph separators.365// These specify a few more unambiguous breaking situations.366367// if you see a sentence-starting character, followed by starting punctuation368// (remember, we're iterating backwards), followed by an optional run of369// whitespace, followed by an optional run of ending punctuation, followed370// by a period, this is a safe place to turn around371+ "!<sent-start><start-punctuation>*<space>*<end>*<period>;"372373// if you see a letter or a digit, followed by an optional run of374// starting punctuation, followed by an optional run of whitespace,375// followed by an optional run of ending punctuation, followed by376// a sentence terminator, this is a safe place to turn around377+ "![<sent-start><lc><digit>]<start-punctuation>*<space>*<end>*<term>;"378}379};380}381}382383384