本文整理匯總了Java中java.text.CharacterIterator.getBeginIndex方法的典型用法代碼示例。如果您正苦於以下問題:Java CharacterIterator.getBeginIndex方法的具體用法?Java CharacterIterator.getBeginIndex怎麽用?Java CharacterIterator.getBeginIndex使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.text.CharacterIterator
的用法示例。
在下文中一共展示了CharacterIterator.getBeginIndex方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: SearchIterator
import java.text.CharacterIterator; //導入方法依賴的package包/類
/**
* Protected constructor for use by subclasses.
* Initializes the iterator with the argument target text for searching
* and sets the BreakIterator.
* See class documentation for more details on the use of the target text
* and {@link BreakIterator}.
*
* @param target The target text to be searched.
* @param breaker A {@link BreakIterator} that is used to determine the
* boundaries of a logical match. This argument can be null.
* @exception IllegalArgumentException thrown when argument target is null,
* or of length 0
* @see BreakIterator
* @stable ICU 2.0
*/
protected SearchIterator(CharacterIterator target, BreakIterator breaker)
{
if (target == null
|| (target.getEndIndex() - target.getBeginIndex()) == 0) {
throw new IllegalArgumentException(
"Illegal argument target. " +
" Argument can not be null or of length 0");
}
search_.setTarget(target);
search_.setBreakIter(breaker);
if (search_.breakIter() != null) {
search_.breakIter().setText((CharacterIterator)target.clone());
}
search_.isOverlap_ = false;
search_.isCanonicalMatch_ = false;
search_.elementComparisonType_ = ElementComparisonType.STANDARD_ELEMENT_COMPARISON;
search_.isForwardSearching_ = true;
search_.reset_ = true;
search_.matchedIndex_ = DONE;
search_.setMatchedLength(0);
}
示例2: append
import java.text.CharacterIterator; //導入方法依賴的package包/類
public static int append(Appendable result, CharacterIterator iterator) {
try {
int start = iterator.getBeginIndex();
int limit = iterator.getEndIndex();
int length = limit - start;
if (start < limit) {
result.append(iterator.first());
while (++start < limit) {
result.append(iterator.next());
}
}
return length;
} catch(IOException e) {
throw new ICUUncheckedIOException(e);
}
}
示例3: previous32
import java.text.CharacterIterator; //導入方法依賴的package包/類
public static int previous32(CharacterIterator ci) {
if (ci.getIndex() <= ci.getBeginIndex()) {
return DONE32;
}
char trail = ci.previous();
int retVal = trail;
if (UTF16.isTrailSurrogate(trail) && ci.getIndex()>ci.getBeginIndex()) {
char lead = ci.previous();
if (UTF16.isLeadSurrogate(lead)) {
retVal = (((int)lead - UTF16.LEAD_SURROGATE_MIN_VALUE) << 10) +
((int)trail - UTF16.TRAIL_SURROGATE_MIN_VALUE) +
UTF16.SUPPLEMENTARY_MIN_VALUE;
} else {
ci.next();
}
}
return retVal;
}
示例4: setText
import java.text.CharacterIterator; //導入方法依賴的package包/類
/**
* Calculate break positions eagerly parallel to reading text.
*/
public void setText(CharacterIterator ci) {
int begin = ci.getBeginIndex();
text = new char[ci.getEndIndex() - begin];
int[] breaks0 = new int[text.length + 1];
int brIx = 0;
breaks0[brIx++] = begin;
int charIx = 0;
boolean inWs = false;
for (char c = ci.first(); c != CharacterIterator.DONE; c = ci.next()) {
text[charIx] = c;
boolean ws = Character.isWhitespace(c);
if (inWs && !ws) {
breaks0[brIx++] = charIx + begin;
}
inWs = ws;
charIx++;
}
if (text.length > 0) {
breaks0[brIx++] = text.length + begin;
}
System.arraycopy(breaks0, 0, breaks = new int[brIx], 0, brIx);
}
示例5: isBoundary
import java.text.CharacterIterator; //導入方法依賴的package包/類
/**
* Returns true if the specified position is a boundary position. As a side
* effect, leaves the iterator pointing to the first boundary position at
* or after "offset".
* @param offset the offset to check.
* @return True if "offset" is a boundary position.
*/
@Override
public boolean isBoundary(int offset) {
CharacterIterator text = getText();
checkOffset(offset, text);
if (offset == text.getBeginIndex()) {
return true;
}
// to check whether this is a boundary, we can use following() on the
// position before the specified one and return true if the position we
// get back is the one the user specified
else {
return following(offset - 1) == offset;
}
}
示例6: StandardGlyphVector
import java.text.CharacterIterator; //導入方法依賴的package包/類
public StandardGlyphVector(Font font, CharacterIterator iter, FontRenderContext frc) {
int offset = iter.getBeginIndex();
char[] text = new char [iter.getEndIndex() - offset];
for(char c = iter.first();
c != CharacterIterator.DONE;
c = iter.next()) {
text[iter.getIndex() - offset] = c;
}
init(font, text, 0, text.length, frc, UNINITIALIZED_FLAGS);
}
示例7: assertSameBreaks
import java.text.CharacterIterator; //導入方法依賴的package包/類
/** Asserts that two breakiterators break the text the same way */
private static void assertSameBreaks(CharacterIterator one, CharacterIterator two, BreakIterator expected, BreakIterator actual) {
expected.setText(one);
actual.setText(two);
assertEquals(expected.current(), actual.current());
// next()
int v = expected.current();
while (v != BreakIterator.DONE) {
assertEquals(v = expected.next(), actual.next());
assertEquals(expected.current(), actual.current());
}
// first()
assertEquals(expected.first(), actual.first());
assertEquals(expected.current(), actual.current());
// last()
assertEquals(expected.last(), actual.last());
assertEquals(expected.current(), actual.current());
// previous()
v = expected.current();
while (v != BreakIterator.DONE) {
assertEquals(v = expected.previous(), actual.previous());
assertEquals(expected.current(), actual.current());
}
// following()
for (int i = one.getBeginIndex(); i <= one.getEndIndex(); i++) {
expected.first();
actual.first();
assertEquals(expected.following(i), actual.following(i));
assertEquals(expected.current(), actual.current());
}
// preceding()
for (int i = one.getBeginIndex(); i <= one.getEndIndex(); i++) {
expected.last();
actual.last();
assertEquals(expected.preceding(i), actual.preceding(i));
assertEquals(expected.current(), actual.current());
}
}
示例8: SafeCharIterator
import java.text.CharacterIterator; //導入方法依賴的package包/類
SafeCharIterator(CharacterIterator base) {
this.base = base;
this.rangeStart = base.getBeginIndex();
this.rangeLimit = base.getEndIndex();
this.currentIndex = base.getIndex();
}
示例9: checkOffset
import java.text.CharacterIterator; //導入方法依賴的package包/類
/**
* Throw IllegalArgumentException unless begin <= offset < end.
*/
protected static final void checkOffset(int offset, CharacterIterator text) {
if (offset < text.getBeginIndex() || offset > text.getEndIndex()) {
throw new IllegalArgumentException("offset out of bounds");
}
}
示例10: previous
import java.text.CharacterIterator; //導入方法依賴的package包/類
/**
* Advances the iterator backwards, to the last boundary preceding this one.
* @return The position of the last boundary position preceding this one.
*/
@Override
public int previous() {
// if we're already sitting at the beginning of the text, return DONE
CharacterIterator text = getText();
if (current() == text.getBeginIndex()) {
return BreakIterator.DONE;
}
// set things up. handlePrevious() will back us up to some valid
// break position before the current position (we back our internal
// iterator up one step to prevent handlePrevious() from returning
// the current position), but not necessarily the last one before
// where we started
int start = current();
int lastResult = cachedLastKnownBreak;
if (lastResult >= start || lastResult <= BreakIterator.DONE) {
getPrevious();
lastResult = handlePrevious();
} else {
//it might be better to check if handlePrevious() give us closer
//safe value but handlePrevious() is slow too
//So, this has to be done carefully
text.setIndex(lastResult);
}
int result = lastResult;
// iterate forward from the known break position until we pass our
// starting point. The last break position before the starting
// point is our return value
while (result != BreakIterator.DONE && result < start) {
lastResult = result;
result = handleNext();
}
// set the current iteration position to be the last break position
// before where we started, and then return that value
text.setIndex(lastResult);
cachedLastKnownBreak = lastResult;
return lastResult;
}
示例11: getStringBounds
import java.text.CharacterIterator; //導入方法依賴的package包/類
/**
* Returns the logical bounds of the characters indexed in the
* specified {@link CharacterIterator} in the
* specified {@code FontRenderContext}. The logical bounds
* contains the origin, ascent, advance, and height, which includes
* the leading. The logical bounds does not always enclose all the
* text. For example, in some languages and in some fonts, accent
* marks can be positioned above the ascent or below the descent.
* To obtain a visual bounding box, which encloses all the text,
* use the {@link TextLayout#getBounds() getBounds} method of
* {@code TextLayout}.
* <p>Note: The returned bounds is in baseline-relative coordinates
* (see {@link java.awt.Font class notes}).
* @param ci the specified {@code CharacterIterator}
* @param beginIndex the initial offset in {@code ci}
* @param limit the end offset in {@code ci}
* @param frc the specified {@code FontRenderContext}
* @return a {@code Rectangle2D} that is the bounding box of the
* characters indexed in the specified {@code CharacterIterator}
* in the specified {@code FontRenderContext}.
* @see FontRenderContext
* @see Font#createGlyphVector
* @since 1.2
* @throws IndexOutOfBoundsException if {@code beginIndex} is
* less than the start index of {@code ci}, or
* {@code limit} is greater than the end index of
* {@code ci}, or {@code beginIndex} is greater
* than {@code limit}
*/
public Rectangle2D getStringBounds(CharacterIterator ci,
int beginIndex, int limit,
FontRenderContext frc) {
int start = ci.getBeginIndex();
int end = ci.getEndIndex();
if (beginIndex < start) {
throw new IndexOutOfBoundsException("beginIndex: " + beginIndex);
}
if (limit > end) {
throw new IndexOutOfBoundsException("limit: " + limit);
}
if (beginIndex > limit) {
throw new IndexOutOfBoundsException("range length: " +
(limit - beginIndex));
}
char[] arr = new char[limit - beginIndex];
ci.setIndex(beginIndex);
for(int idx = 0; idx < arr.length; idx++) {
arr[idx] = ci.current();
ci.next();
}
return getStringBounds(arr,0,arr.length,frc);
}
示例12: getStringBounds
import java.text.CharacterIterator; //導入方法依賴的package包/類
/**
* Returns the logical bounds of the characters indexed in the
* specified {@link CharacterIterator} in the
* specified <code>FontRenderContext</code>. The logical bounds
* contains the origin, ascent, advance, and height, which includes
* the leading. The logical bounds does not always enclose all the
* text. For example, in some languages and in some fonts, accent
* marks can be positioned above the ascent or below the descent.
* To obtain a visual bounding box, which encloses all the text,
* use the {@link TextLayout#getBounds() getBounds} method of
* <code>TextLayout</code>.
* <p>Note: The returned bounds is in baseline-relative coordinates
* (see {@link java.awt.Font class notes}).
* @param ci the specified <code>CharacterIterator</code>
* @param beginIndex the initial offset in <code>ci</code>
* @param limit the end offset in <code>ci</code>
* @param frc the specified <code>FontRenderContext</code>
* @return a <code>Rectangle2D</code> that is the bounding box of the
* characters indexed in the specified <code>CharacterIterator</code>
* in the specified <code>FontRenderContext</code>.
* @see FontRenderContext
* @see Font#createGlyphVector
* @since 1.2
* @throws IndexOutOfBoundsException if <code>beginIndex</code> is
* less than the start index of <code>ci</code>, or
* <code>limit</code> is greater than the end index of
* <code>ci</code>, or <code>beginIndex</code> is greater
* than <code>limit</code>
*/
public Rectangle2D getStringBounds(CharacterIterator ci,
int beginIndex, int limit,
FontRenderContext frc) {
int start = ci.getBeginIndex();
int end = ci.getEndIndex();
if (beginIndex < start) {
throw new IndexOutOfBoundsException("beginIndex: " + beginIndex);
}
if (limit > end) {
throw new IndexOutOfBoundsException("limit: " + limit);
}
if (beginIndex > limit) {
throw new IndexOutOfBoundsException("range length: " +
(limit - beginIndex));
}
char[] arr = new char[limit - beginIndex];
ci.setIndex(beginIndex);
for(int idx = 0; idx < arr.length; idx++) {
arr[idx] = ci.current();
ci.next();
}
return getStringBounds(arr,0,arr.length,frc);
}