int getPrevIdx() { return str.offsetByCodePoints(idx, -1); }
/** * Returns the index within this {@code CharSeq} that is * offset from the given {@code index} by * {@code codePointOffset} code points. Unpaired surrogates * within the text range given by {@code index} and * {@code codePointOffset} count as one code point each. * * @param index the index to be offset * @param codePointOffset the offset in code points * @return the index within this {@code CharSeq} * @throws IndexOutOfBoundsException if {@code index} * is negative or larger then the length of this * {@code CharSeq}, or if {@code codePointOffset} is positive * and the substring starting with {@code index} has fewer * than {@code codePointOffset} code points, * or if {@code codePointOffset} is negative and the substring * before {@code index} has fewer than the absolute value * of {@code codePointOffset} code points. */ public int offsetByCodePoints(int index, int codePointOffset) { return back.offsetByCodePoints(index, codePointOffset); }
int next() { final int idx = this.idx; try { return str.codePointAt(idx); } finally { this.idx = str.offsetByCodePoints(idx, 1); } }
IllegalArgumentException unexpectedCharacter() { return new IllegalArgumentException("Unexpected character at " + string.offsetByCodePoints(idx, -1)); }
private static void appendSegment(final StringBuilder b, final String segment) { int cp; for (int i = 0; i < segment.length(); i = segment.offsetByCodePoints(i, 1)) { cp = segment.codePointAt(i); if (cp == '/' || cp == '\'' || cp == '"') { b.append('\\'); } b.appendCodePoint(cp); } }
private static String getBasePropMatcherName(final MethodParamModel prop, final String suffix) { final String name = prop.getName(); final int fst = Character.toUpperCase(name.codePointAt(0)); return 'm' + String.copyValueOf(Character.toChars(fst)) + name.substring(name.offsetByCodePoints(0, 1)) + suffix; }
protected static String capitalize(String name) { if (name == null || name.length() == 0) return name; int offset1 = name.offsetByCodePoints(0, 1); return name.substring(0, offset1).toUpperCase() + name.substring(offset1); } }
@Override public TextValue substring( int start, int length ) { int s = Math.min( start, length() ); int e = Math.min( s + length, length() ); int codePointStart = value.offsetByCodePoints( 0, s ); int codePointEnd = value.offsetByCodePoints( 0, e ); return Values.stringValue( value.substring( codePointStart, codePointEnd ) ); }
public int next() { if (! hasNext()) throw new NoSuchElementException(); try { offset++; return string.codePointAt(idx + offs); } finally { idx = string.offsetByCodePoints(idx + offs, 1) - offs; } }
public int prev() { if (! hasPrev()) throw new NoSuchElementException(); idx = string.offsetByCodePoints(idx + offs, -1) - offs; offset--; return string.codePointAt(idx + offs); }
private static String importStringFromIphone(String str) { StringBuilder buff = new StringBuilder(str.length()); for (int i = 0; i < str.length(); i = str.offsetByCodePoints(i, 1)) { int codePoint = str.codePointAt(i); buff.appendCodePoint(importCodePointFromIphone(codePoint)); } return buff.toString(); }
public int previous() { if (! hasPrevious()) throw new NoSuchElementException(); idx = string.offsetByCodePoints(idx + offs, - 1) - offs; offset--; return string.codePointAt(idx + offs); }
public int next() { if (! hasNext()) throw new NoSuchElementException(); try { offset++; return string.codePointAt(idx + offs); } finally { idx = string.offsetByCodePoints(idx + offs, 1) - offs; } }
int prev() { final int idx = this.idx; try { return str.codePointBefore(idx); } finally { this.idx = str.offsetByCodePoints(idx, -1); } }
/** * Checks an identifier. * * @param signature a string containing the signature that must be checked. * @param startPos index of first character to be checked. * @return the index of the first character after the checked part. */ private static int checkSignatureIdentifier(final String signature, final int startPos) { int pos = startPos; while (pos < signature.length() && ".;[/<>:".indexOf(signature.codePointAt(pos)) == -1) { pos = signature.offsetByCodePoints(pos, 1); } if (pos == startPos) { throw new IllegalArgumentException(signature + ": identifier expected at index " + startPos); } return pos; }
public static String enforceMaxLength(String val, int maxLength) { if (val == null) { return null; } String value = val; if (maxLength > 0) { int valLength = val.codePointCount(0, val.length()); if (valLength > maxLength) { // Truncate the excess chars to fit the character length. // Also make sure we take supplementary chars into account. value = val.substring(0, val.offsetByCodePoints(0, maxLength)); } } return value; }
@Override public void encodePrintableString(final String str) { for (int i = 0; i < str.length(); i = str.offsetByCodePoints(i, 1)) { validatePrintableByte(str.codePointAt(i)); } writeElement(PRINTABLE_STRING_TYPE, str.getBytes(StandardCharsets.US_ASCII)); }
private static IllegalArgumentException invalidExpressionSyntax(final String string, final int index) { String msg = CommonMessages.msg.invalidExpressionSyntax(index); StringBuilder b = new StringBuilder(msg.length() + string.length() + string.length() + 5); b.append(msg); b.append('\n').append('\t').append(string); b.append('\n').append('\t'); for (int i = 0; i < index; i = string.offsetByCodePoints(i, 1)) { final int cp = string.codePointAt(i); if (Character.isWhitespace(cp)) { b.append(cp); } else if (Character.isValidCodePoint(cp) && ! Character.isISOControl(cp)) { b.append(' '); } } b.append('^'); return new IllegalArgumentException(b.toString()); }
int next() { if (! hasNext()) throw unexpectedEnd(); try { return string.codePointAt(idx); } finally { idx = string.offsetByCodePoints(idx, 1); } }
private Path pathFor(String name) { assert name.codePointCount(0, name.length()) > 0; String normalizedName = name; if (encoded) { normalizedName = Normalizer.normalize(name, Normalizer.Form.NFKC) .toLowerCase(Locale.ROOT) .replaceAll("[^a-z0-9]", "_"); } Path path = root; int idx = 0; for (int level = 0; level < levels; level ++) { int newIdx = normalizedName.offsetByCodePoints(idx, 1); path = path.resolve(normalizedName.substring(idx, newIdx)); idx = newIdx; if (idx == normalizedName.length()) { break; } } if (encoded) { String base32 = ByteIterator.ofBytes(new ByteStringBuilder().append(name).toArray()) .base32Encode(Base32Alphabet.STANDARD, false).drainToString(); name = normalizedName + "-" + base32; } return path.resolve(name + ".xml"); }