本文整理汇总了Java中java.text.BreakIterator.preceding方法的典型用法代码示例。如果您正苦于以下问题:Java BreakIterator.preceding方法的具体用法?Java BreakIterator.preceding怎么用?Java BreakIterator.preceding使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.text.BreakIterator
的用法示例。
在下文中一共展示了BreakIterator.preceding方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findWordLimit
import java.text.BreakIterator; //导入方法依赖的package包/类
/**
* Needed to unify forward and backward searching.
* The method assumes that s is the text assigned to words.
*/
private int findWordLimit(int index, BreakIterator words, boolean direction,
String s) {
// Fix for 4256660 and 4256661.
// Words iterator is different from character and sentence iterators
// in that end of one word is not necessarily start of another word.
// Please see java.text.BreakIterator JavaDoc. The code below is
// based on nextWordStartAfter example from BreakIterator.java.
int last = (direction == NEXT) ? words.following(index)
: words.preceding(index);
int current = (direction == NEXT) ? words.next()
: words.previous();
while (current != BreakIterator.DONE) {
for (int p = Math.min(last, current); p < Math.max(last, current); p++) {
if (Character.isLetter(s.charAt(p))) {
return last;
}
}
last = current;
current = (direction == NEXT) ? words.next()
: words.previous();
}
return BreakIterator.DONE;
}
示例2: testPreceding
import java.text.BreakIterator; //导入方法依赖的package包/类
private void testPreceding(BreakIterator bi, String text, int[] boundaries) {
logln("testPreceding():");
int p = 0;
int i = 0;
try {
for (i = 0; i <= text.length(); i++) { // change to <= when new BI code goes in
int b = bi.preceding(i);
logln("bi.preceding(" + i + ") -> " + b);
if (b != boundaries[p])
errln("Wrong result from preceding() for " + i + ": expected " + boundaries[p]
+ ", got " + b);
if (i == boundaries[p + 1])
++p;
}
} catch (IllegalArgumentException illargExp) {
errln("IllegalArgumentException caught from preceding() for offset: " + i);
}
}
示例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: getBreakSpot
import java.text.BreakIterator; //导入方法依赖的package包/类
/**
* Returns a location to break at in the passed in region, or
* BreakIterator.DONE if there isn't a good location to break at
* in the specified region.
*/
private int getBreakSpot(int p0, int p1) {
if (breakSpots == null) {
// Re-calculate breakpoints for the whole view
int start = getStartOffset();
int end = getEndOffset();
int[] bs = new int[end + 1 - start];
int ix = 0;
// Breaker should work on the parent element because there may be
// a valid breakpoint at the end edge of the view (space, etc.)
Element parent = getElement().getParentElement();
int pstart = (parent == null ? start : parent.getStartOffset());
int pend = (parent == null ? end : parent.getEndOffset());
Segment s = getText(pstart, pend);
s.first();
BreakIterator breaker = getBreaker();
breaker.setText(s);
// Backward search should start from end+1 unless there's NO end+1
int startFrom = end + (pend > end ? 1 : 0);
for (;;) {
startFrom = breaker.preceding(s.offset + (startFrom - pstart))
+ (pstart - s.offset);
if (startFrom > start) {
// The break spot is within the view
bs[ix++] = startFrom;
} else {
break;
}
}
SegmentCache.releaseSharedSegment(s);
breakSpots = new int[ix];
System.arraycopy(bs, 0, breakSpots, 0, ix);
}
int breakSpot = BreakIterator.DONE;
for (int i = 0; i < breakSpots.length; i++) {
int bsp = breakSpots[i];
if (bsp <= p1) {
if (bsp > p0) {
breakSpot = bsp;
}
break;
}
}
return breakSpot;
}