本文整理匯總了Java中java.text.BreakIterator.isBoundary方法的典型用法代碼示例。如果您正苦於以下問題:Java BreakIterator.isBoundary方法的具體用法?Java BreakIterator.isBoundary怎麽用?Java BreakIterator.isBoundary使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.text.BreakIterator
的用法示例。
在下文中一共展示了BreakIterator.isBoundary方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testIsBoundary
import java.text.BreakIterator; //導入方法依賴的package包/類
private void testIsBoundary(BreakIterator bi, String text, int[] boundaries) {
logln("testIsBoundary():");
int p = 1;
boolean isB;
for (int i = 0; i <= text.length(); i++) { // change to <= when new BI code goes in
isB = bi.isBoundary(i);
logln("bi.isBoundary(" + i + ") -> " + isB);
if (i == boundaries[p]) {
if (!isB)
errln("Wrong result from isBoundary() for " + i + ": expected true, got false");
++p;
}
else {
if (isB)
errln("Wrong result from isBoundary() for " + i + ": expected false, got true");
}
}
}
示例2: TestBug4153072
import java.text.BreakIterator; //導入方法依賴的package包/類
public void TestBug4153072() {
BreakIterator iter = BreakIterator.getWordInstance();
String str = "...Hello, World!...";
int begin = 3;
int end = str.length() - 3;
boolean gotException = false;
boolean dummy;
iter.setText(new StringCharacterIterator(str, begin, end, begin));
for (int index = -1; index < begin + 1; ++index) {
try {
dummy = iter.isBoundary(index);
if (index < begin)
errln("Didn't get exception with offset = " + index +
" and begin index = " + begin);
}
catch (IllegalArgumentException e) {
if (index >= begin)
errln("Got exception with offset = " + index +
" and begin index = " + begin);
}
}
}
示例3: onDoubleTap
import java.text.BreakIterator; //導入方法依賴的package包/類
@Override
public boolean onDoubleTap(MotionEvent e) {
int x = (int) e.getX();
int y = (int) e.getY();
// find the position
int offset = getOffsetForPosition(x, y);
// select word
BreakIterator iterator = BreakIterator.getWordInstance();
iterator.setText(getText().toString());
// start and end are the word boundaries;
int start;
if (iterator.isBoundary(offset)) {
start = offset;
} else {
start = iterator.preceding(offset);
}
int end = iterator.following(offset);
// handle tapping at the very beginning or end.
if (end == BreakIterator.DONE) {
end = start;
start = iterator.preceding(offset);
if (start == BreakIterator.DONE) start = end;
}
setSelection(start, end);
return super.onDoubleTap(e);
}
示例4: isFinalCased
import java.text.BreakIterator; //導入方法依賴的package包/類
/**
* Implements the "Final_Cased" condition
*
* Specification: Within the closest word boundaries containing C, there is a cased
* letter before C, and there is no cased letter after C.
*
* Regular Expression:
* Before C: [{cased==true}][{wordBoundary!=true}]*
* After C: !([{wordBoundary!=true}]*[{cased}])
*/
private static boolean isFinalCased(String src, int index, Locale locale) {
BreakIterator wordBoundary = BreakIterator.getWordInstance(locale);
wordBoundary.setText(src);
int ch;
// Look for a preceding 'cased' letter
for (int i = index; (i >= 0) && !wordBoundary.isBoundary(i);
i -= Character.charCount(ch)) {
ch = src.codePointBefore(i);
if (isCased(ch)) {
int len = src.length();
// Check that there is no 'cased' letter after the index
for (i = index + Character.charCount(src.codePointAt(index));
(i < len) && !wordBoundary.isBoundary(i);
i += Character.charCount(ch)) {
ch = src.codePointAt(i);
if (isCased(ch)) {
return false;
}
}
return true;
}
}
return false;
}