本文整理汇总了Java中com.ibm.icu.lang.UScript类的典型用法代码示例。如果您正苦于以下问题:Java UScript类的具体用法?Java UScript怎么用?Java UScript使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
UScript类属于com.ibm.icu.lang包,在下文中一共展示了UScript类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getResolvedScriptSetWithout
import com.ibm.icu.lang.UScript; //导入依赖的package包/类
/**
* Computes the resolved script set for a string, omitting characters having the specified script. If
* UScript.CODE_LIMIT is passed as the second argument, all characters are included.
*/
private void getResolvedScriptSetWithout(CharSequence input, int script, ScriptSet result) {
result.setAll();
ScriptSet temp = new ScriptSet();
for (int utf16Offset = 0; utf16Offset < input.length();) {
int codePoint = Character.codePointAt(input, utf16Offset);
utf16Offset += Character.charCount(codePoint);
// Compute the augmented script set for the character
getAugmentedScriptSet(codePoint, temp);
// Intersect the augmented script set with the resolved script set, but only if the character doesn't
// have the script specified in the function call
if (script == UScript.CODE_LIMIT || !temp.get(script)) {
result.and(temp);
}
}
}
示例2: appendStringTo
import com.ibm.icu.lang.UScript; //导入依赖的package包/类
public void appendStringTo(StringBuilder sb) {
sb.append("{ ");
if (isEmpty()) {
sb.append("- ");
} else if (isFull()) {
sb.append("* ");
} else {
for (int script = 0; script < UScript.CODE_LIMIT; script++) {
if (get(script)) {
sb.append(UScript.getShortName(script));
sb.append(" ");
}
}
}
sb.append("}");
}
示例3: loadGroups
import com.ibm.icu.lang.UScript; //导入依赖的package包/类
private boolean loadGroups(CollationData data) {
headerLength = 1 + NUM_SPECIAL_GROUPS;
int r0 = (CollationFastLatin.VERSION << 8) | headerLength;
result.append((char)r0);
// The first few reordering groups should be special groups
// (space, punct, ..., digit) followed by Latn, then Grek and other scripts.
for(int i = 0; i < NUM_SPECIAL_GROUPS; ++i) {
lastSpecialPrimaries[i] = data.getLastPrimaryForGroup(Collator.ReorderCodes.FIRST + i);
if(lastSpecialPrimaries[i] == 0) {
// missing data
return false;
}
result.append(0); // reserve a slot for this group
}
firstDigitPrimary = data.getFirstPrimaryForGroup(Collator.ReorderCodes.DIGIT);
firstLatinPrimary = data.getFirstPrimaryForGroup(UScript.LATIN);
lastLatinPrimary = data.getLastPrimaryForGroup(UScript.LATIN);
if(firstDigitPrimary == 0 || firstLatinPrimary == 0) {
// missing data
return false;
}
return true;
}
示例4: getScript
import com.ibm.icu.lang.UScript; //导入依赖的package包/类
/**
* fast version of UScript.getScript(). Basic Latin is an array lookup
*/
private int getScript(int codepoint) {
if (0 <= codepoint && codepoint < basicLatin.length) {
return basicLatin[codepoint];
} else {
int script = UScript.getScript(codepoint);
if (combineCJ) {
if (script == UScript.HAN || script == UScript.HIRAGANA || script == UScript.KATAKANA) {
return UScript.JAPANESE;
} else if (codepoint >= 0xFF10 && codepoint <= 0xFF19) {
// when using CJK dictionary breaking, don't let full width numbers go to it, otherwise
// they are treated as punctuation. we currently have no cleaner way to fix this!
return UScript.LATIN;
} else {
return script;
}
} else {
return script;
}
}
}
示例5: getScript
import com.ibm.icu.lang.UScript; //导入依赖的package包/类
/** fast version of UScript.getScript(). Basic Latin is an array lookup */
private int getScript(int codepoint) {
if (0 <= codepoint && codepoint < basicLatin.length) {
return basicLatin[codepoint];
} else {
int script = UScript.getScript(codepoint);
if (combineCJ) {
if (script == UScript.HAN || script == UScript.HIRAGANA || script == UScript.KATAKANA) {
return UScript.JAPANESE;
} else if (codepoint >= 0xFF10 && codepoint <= 0xFF19) {
// when using CJK dictionary breaking, don't let full width numbers go to it, otherwise
// they are treated as punctuation. we currently have no cleaner way to fix this!
return UScript.LATIN;
} else {
return script;
}
} else {
return script;
}
}
}
示例6: testTokenAttributes
import com.ibm.icu.lang.UScript; //导入依赖的package包/类
public void testTokenAttributes() throws Exception {
TokenStream ts = a.tokenStream("dummy", "This is a test");
try {
ScriptAttribute scriptAtt = ts.addAttribute(ScriptAttribute.class);
ts.reset();
while (ts.incrementToken()) {
assertEquals(UScript.LATIN, scriptAtt.getCode());
assertEquals(UScript.getName(UScript.LATIN), scriptAtt.getName());
assertEquals(UScript.getShortName(UScript.LATIN), scriptAtt.getShortName());
assertTrue(ts.reflectAsString(false).contains("script=Latin"));
}
ts.end();
} finally {
IOUtils.closeWhileHandlingException(ts);
}
}
示例7: scriptNameToCode
import com.ibm.icu.lang.UScript; //导入依赖的package包/类
/**
* Return the script code for a given name, or
* UScript.INVALID_CODE if not found.
*/
private static int scriptNameToCode(String name) {
try{
int[] codes = UScript.getCode(name);
return codes != null ? codes[0] : UScript.INVALID_CODE;
}catch( MissingResourceException e){
///CLOVER:OFF
return UScript.INVALID_CODE;
///CLOVER:ON
}
}
示例8: handles
import com.ibm.icu.lang.UScript; //导入依赖的package包/类
public boolean handles(int c, int breakType) {
if (breakType == BreakIterator.KIND_WORD || breakType == BreakIterator.KIND_LINE) {
int script = UCharacter.getIntPropertyValue(c, UProperty.SCRIPT);
return (script == UScript.KHMER);
}
return false;
}
示例9: handles
import com.ibm.icu.lang.UScript; //导入依赖的package包/类
@Override
public boolean handles(int c, int breakType) {
if (breakType == BreakIterator.KIND_WORD || breakType == BreakIterator.KIND_LINE) {
int script = UCharacter.getIntPropertyValue(c, UProperty.SCRIPT);
return (script == UScript.MYANMAR);
}
return false;
}
示例10: handles
import com.ibm.icu.lang.UScript; //导入依赖的package包/类
public boolean handles(int c, int breakType) {
if (breakType == BreakIterator.KIND_WORD || breakType == BreakIterator.KIND_LINE) {
int script = UCharacter.getIntPropertyValue(c, UProperty.SCRIPT);
return (script == UScript.LAO);
}
return false;
}
示例11: setAllowedLocales
import com.ibm.icu.lang.UScript; //导入依赖的package包/类
/**
* Limit characters that are acceptable in identifiers being checked to those normally used with the languages
* associated with the specified locales. Any previously specified list of locales is replaced by the new
* settings.
*
* A set of languages is determined from the locale(s), and from those a set of acceptable Unicode scripts is
* determined. Characters from this set of scripts, along with characters from the "common" and "inherited"
* Unicode Script categories will be permitted.
*
* Supplying an empty string removes all restrictions; characters from any script will be allowed.
*
* The {@link #CHAR_LIMIT} test is automatically enabled for this SpoofChecker when calling this function with a
* non-empty list of locales.
*
* The Unicode Set of characters that will be allowed is accessible via the {@link #getAllowedChars} function.
* setAllowedLocales() will <i>replace</i> any previously applied set of allowed characters.
*
* Adjustments, such as additions or deletions of certain classes of characters, can be made to the result of
* {@link #setAllowedChars} by fetching the resulting set with {@link #getAllowedChars}, manipulating it with
* the Unicode Set API, then resetting the spoof detectors limits with {@link #setAllowedChars}.
*
* @param locales
* A Set of ULocales, from which the language and associated script are extracted. If the locales Set
* is null, no restrictions will be placed on the allowed characters.
*
* @return self
* @stable ICU 4.6
*/
public Builder setAllowedLocales(Set<ULocale> locales) {
fAllowedCharsSet.clear();
for (ULocale locale : locales) {
// Add the script chars for this locale to the accumulating set
// of allowed chars.
addScriptChars(locale, fAllowedCharsSet);
}
// If our caller provided an empty list of locales, we disable the
// allowed characters checking
fAllowedLocales.clear();
if (locales.size() == 0) {
fAllowedCharsSet.add(0, 0x10ffff);
fChecks &= ~CHAR_LIMIT;
return this;
}
// Add all common and inherited characters to the set of allowed
// chars.
UnicodeSet tempSet = new UnicodeSet();
tempSet.applyIntPropertyValue(UProperty.SCRIPT, UScript.COMMON);
fAllowedCharsSet.addAll(tempSet);
tempSet.applyIntPropertyValue(UProperty.SCRIPT, UScript.INHERITED);
fAllowedCharsSet.addAll(tempSet);
// Store the updated spoof checker state.
fAllowedLocales.clear();
fAllowedLocales.addAll(locales);
fChecks |= CHAR_LIMIT;
return this;
}
示例12: addScriptChars
import com.ibm.icu.lang.UScript; //导入依赖的package包/类
private void addScriptChars(ULocale locale, UnicodeSet allowedChars) {
int scripts[] = UScript.getCode(locale);
if (scripts != null) {
UnicodeSet tmpSet = new UnicodeSet();
for (int i = 0; i < scripts.length; i++) {
tmpSet.applyIntPropertyValue(UProperty.SCRIPT, scripts[i]);
allowedChars.addAll(tmpSet);
}
}
// else it's an unknown script.
// Maybe they asked for the script of "zxx", which refers to no linguistic content.
// Maybe they asked for the script of a newer locale that we don't know in the older version of ICU.
}
示例13: getAugmentedScriptSet
import com.ibm.icu.lang.UScript; //导入依赖的package包/类
/**
* Computes the augmented script set for a code point, according to UTS 39 section 5.1.
*/
private static void getAugmentedScriptSet(int codePoint, ScriptSet result) {
result.clear();
UScript.getScriptExtensions(codePoint, result);
// Section 5.1 step 1
if (result.get(UScript.HAN)) {
result.set(UScript.HAN_WITH_BOPOMOFO);
result.set(UScript.JAPANESE);
result.set(UScript.KOREAN);
}
if (result.get(UScript.HIRAGANA)) {
result.set(UScript.JAPANESE);
}
if (result.get(UScript.KATAKANA)) {
result.set(UScript.JAPANESE);
}
if (result.get(UScript.HANGUL)) {
result.set(UScript.KOREAN);
}
if (result.get(UScript.BOPOMOFO)) {
result.set(UScript.HAN_WITH_BOPOMOFO);
}
// Section 5.1 step 2
if (result.get(UScript.COMMON) || result.get(UScript.INHERITED)) {
result.setAll();
}
}
示例14: getRestrictionLevel
import com.ibm.icu.lang.UScript; //导入依赖的package包/类
/**
* Computes the restriction level of a string, according to UTS 39 section 5.2.
*/
private RestrictionLevel getRestrictionLevel(String input) {
// Section 5.2 step 1:
if (!fAllowedCharsSet.containsAll(input)) {
return RestrictionLevel.UNRESTRICTIVE;
}
// Section 5.2 step 2:
if (ASCII.containsAll(input)) {
return RestrictionLevel.ASCII;
}
// Section 5.2 steps 3:
ScriptSet resolvedScriptSet = new ScriptSet();
getResolvedScriptSet(input, resolvedScriptSet);
// Section 5.2 step 4:
if (!resolvedScriptSet.isEmpty()) {
return RestrictionLevel.SINGLE_SCRIPT_RESTRICTIVE;
}
// Section 5.2 step 5:
ScriptSet resolvedNoLatn = new ScriptSet();
getResolvedScriptSetWithout(input, UScript.LATIN, resolvedNoLatn);
// Section 5.2 step 6:
if (resolvedNoLatn.get(UScript.HAN_WITH_BOPOMOFO) || resolvedNoLatn.get(UScript.JAPANESE)
|| resolvedNoLatn.get(UScript.KOREAN)) {
return RestrictionLevel.HIGHLY_RESTRICTIVE;
}
// Section 5.2 step 7:
if (!resolvedNoLatn.isEmpty() && !resolvedNoLatn.get(UScript.CYRILLIC) && !resolvedNoLatn.get(UScript.GREEK)
&& !resolvedNoLatn.get(UScript.CHEROKEE)) {
return RestrictionLevel.MODERATELY_RESTRICTIVE;
}
// Section 5.2 step 8:
return RestrictionLevel.MINIMALLY_RESTRICTIVE;
}
示例15: handles
import com.ibm.icu.lang.UScript; //导入依赖的package包/类
public boolean handles(int c, int breakType) {
if (breakType == BreakIterator.KIND_WORD || breakType == BreakIterator.KIND_LINE) {
int script = UCharacter.getIntPropertyValue(c, UProperty.SCRIPT);
return (script == UScript.THAI);
}
return false;
}