/** * Obtains a {@code CollationElementIterator} for the given string. * * @param source * the source string. * @return the {@code CollationElementIterator} for {@code source}. */ public CollationElementIterator getCollationElementIterator(String source) { if (source == null) { throw new NullPointerException("source == null"); } return new CollationElementIterator(icuColl.getCollationElementIterator(source)); }
int e0, e1; do { e1 = s1.next(); } while (e1 == 0); if (e1 == -1) { e0 = s0.next(); } while (e0 == 0); if (e0 == -1) { int start = s0.getOffset(); if (collationStartsWith(s0, s1)) { if (matchAtEnd) { do { e0 = s0.next(); } while (e0 == 0); if (e0 == -1) { if (offsets != null) { offsets[0] = start - 1; offsets[1] = s0.getOffset(); s0.setOffset(start); if (s0.getOffset() != start) { s0.next(); s1.reset();
sourceCursor.setOffset(0); } catch (NoSuchMethodError ex3) { sOrder = sourceCursor.next(); try { targetCursor.setOffset(toffset); } catch (NoSuchMethodError ex4) { tOrder = targetCursor.next(); if (sOrder == tOrder) { try { toffset = targetCursor.getOffset(); } catch (NoSuchMethodError ex) { pSOrder = CollationElementIterator.primaryOrder(sOrder); pTOrder = CollationElementIterator.primaryOrder(tOrder); if (pSOrder == pTOrder) { try { toffset = targetCursor.getOffset(); } catch (NoSuchMethodError ex2) { tOrder = targetCursor.next(); debug("next tOrder=" + tOrder); sOrder = sourceCursor.next(); } else { gets = true;
/** * Returns the next element from an iterator. * @param it iterator * @return next element, or {@code -1} */ private static int next(final CollationElementIterator it) { do { final int c = it.next(); if(c != 0) return c; } while(true); } }
@Override protected int indexOf(final String string, final String contains, final Mode mode, final InputInfo info) throws QueryException { if(!(collator instanceof RuleBasedCollator)) throw CHARCOLL.get(info); final RuleBasedCollator rbc = (RuleBasedCollator) collator; final CollationElementIterator iterS = rbc.getCollationElementIterator(string); final CollationElementIterator iterC = rbc.getCollationElementIterator(contains); final int elemC = next(iterC); if(elemC == -1) return 0; final int offC = iterC.getOffset(); do { // find first equal character for(int elemS; (elemS = next(iterS)) != elemC;) { if(elemS == -1 || mode == Mode.STARTS_WITH) return -1; } final int offS = iterS.getOffset(); if(startsWith(iterS, iterC)) { if(mode == Mode.INDEX_AFTER) { return iterS.getOffset(); } else if(mode == Mode.ENDS_WITH) { if(next(iterS) == -1) return offS - 1; } else { return offS - 1; } } iterS.setOffset(offS); iterC.setOffset(offC); } while(true); }
private String show(int ce) { return "" + CollationElementIterator.primaryOrder(ce) + "/" + CollationElementIterator.secondaryOrder(ce) + "/" + CollationElementIterator.tertiaryOrder(ce); }
@Override public int compare(int ce1, int ce2) { int c1 = Integer.compare(CollationElementIterator.primaryOrder(ce1), CollationElementIterator.primaryOrder(ce2)); if (c1 == 0) { return Integer.compare((int) CollationElementIterator.secondaryOrder(ce1), (int) CollationElementIterator.secondaryOrder(ce2)); } else { return c1; } }
@Override public int compare(int ce1, int ce2) { return Integer.compare(CollationElementIterator.primaryOrder(ce1), CollationElementIterator.primaryOrder(ce2)); }
int e0, e1; do { e1 = s1.next(); } while (e1 == 0); if (e1 == -1) { e0 = s0.next(); } while (e0 == 0); if (e0 == -1) { int start = s0.getOffset(); if (collationStartsWith(s0, s1)) { if (matchAtEnd) { do { e0 = s0.next(); } while (e0 == 0); if (e0 == -1) { if (offsets != null) { offsets[0] = start-1; offsets[1] = s0.getOffset(); s0.setOffset(start); if (s0.getOffset() != start) { s0.next(); s1.reset();
/** * Returns the next element from an iterator. * @param it iterator * @return next element, or {@code -1} */ private static int next(final CollationElementIterator it) { do { final int c = it.next(); if(c != 0) return c; } while(true); } }
@Override protected int indexOf(final String string, final String contains, final Mode mode, final InputInfo info) throws QueryException { if(!(collator instanceof RuleBasedCollator)) throw CHARCOLL.get(info); final RuleBasedCollator rbc = (RuleBasedCollator) collator; final CollationElementIterator iterS = rbc.getCollationElementIterator(string); final CollationElementIterator iterC = rbc.getCollationElementIterator(contains); final int elemC = next(iterC); if(elemC == -1) return 0; final int offC = iterC.getOffset(); do { // find first equal character for(int elemS; (elemS = next(iterS)) != elemC;) { if(elemS == -1 || mode == Mode.STARTS_WITH) return -1; } final int offS = iterS.getOffset(); if(startsWith(iterS, iterC)) { if(mode == Mode.INDEX_AFTER) { return iterS.getOffset(); } else if(mode == Mode.ENDS_WITH) { if(next(iterS) == -1) return offS - 1; } else { return offS - 1; } } iterS.setOffset(offS); iterC.setOffset(offC); } while(true); }
private String show(int ce) { return "" + CollationElementIterator.primaryOrder(ce) + "/" + CollationElementIterator.secondaryOrder(ce) + "/" + CollationElementIterator.tertiaryOrder(ce); }
@Override public int compare(int ce1, int ce2) { int c1 = Integer.compare(CollationElementIterator.primaryOrder(ce1), CollationElementIterator.primaryOrder(ce2)); if (c1 == 0) { return Integer.compare((int) CollationElementIterator.secondaryOrder(ce1), (int) CollationElementIterator.secondaryOrder(ce2)); } else { return c1; } }
@Override public int compare(int ce1, int ce2) { return Integer.compare(CollationElementIterator.primaryOrder(ce1), CollationElementIterator.primaryOrder(ce2)); }
int e0, e1; do { e1 = s1.next(); } while (e1 == 0); if (e1 == -1) { e0 = s0.next(); } while (e0 == 0); if (e0 == -1) { int start = s0.getOffset(); if (collationStartsWith(s0, s1)) { if (matchAtEnd) { do { e0 = s0.next(); } while (e0 == 0); if (e0 == -1) { if (offsets != null) { offsets[0] = start-1; offsets[1] = s0.getOffset(); s0.setOffset(start); if (s0.getOffset() != start) { s0.next(); s1.reset();
/** * Determine whether one string starts with another, under the terms of a given * collating sequence. * * @param s0 iterator over the collation elements of the containing string * @param s1 iterator over the collation elements of the contained string * @return true if the first string starts with the second */ private boolean collationStartsWith(CollationElementIterator s0, CollationElementIterator s1) { while (true) { int e0, e1; do { e1 = s1.next(); } while (e1 == 0); if (e1 == -1) { return true; } do { e0 = s0.next(); } while (e0 == 0); if (e0 != e1) { return false; } } }
/** * Obtains a {@code CollationElementIterator} for the given * {@code CharacterIterator}. The source iterator's integrity will be * preserved since a new copy will be created for use. * * @param source * the source character iterator. * @return a {@code CollationElementIterator} for {@code source}. */ public CollationElementIterator getCollationElementIterator(CharacterIterator source) { if (source == null) { throw new NullPointerException("source == null"); } return new CollationElementIterator(icuColl.getCollationElementIterator(source)); }
@Override public int compare(int ce1, int ce2) { int c1 = Integer.compare(CollationElementIterator.primaryOrder(ce1), CollationElementIterator.primaryOrder(ce2)); if (c1 == 0) { int c2 = Integer.compare((int) CollationElementIterator.secondaryOrder(ce1), (int) CollationElementIterator.secondaryOrder(ce2)); if (c2 == 0) { return Integer.compare((int) CollationElementIterator.tertiaryOrder(ce1), (int) CollationElementIterator.tertiaryOrder(ce2)); } else { return c2; } } else { return c1; } }