List of usage examples for java.lang CharSequence length
int length();
From source file:com.kstenschke.shifter.utils.UtilsTextual.java
/** * @param text Text to be analyzed * @param offset Character offset in text, intersecting the word dealing with * @return int Starting position offset of word at given offset in given CharSequence *//* w w w . ja v a 2s . c o m*/ public static int getStartOfWordAtOffset(CharSequence text, int offset) { if (text.length() == 0) return 0; if (offset > 0 && !Character.isJavaIdentifierPart(text.charAt(offset)) && Character.isJavaIdentifierPart(text.charAt(offset - 1))) { offset--; } if (Character.isJavaIdentifierPart(text.charAt(offset))) { int start = offset; while (start > 0 && Character.isJavaIdentifierPart(text.charAt(start - 1))) { start--; } return start; } return 0; }
From source file:com.kstenschke.shifter.utils.UtilsTextual.java
/** * @param text Text containing the sequence * @param offsetStart Sub sequence start character offset * @param offsetEnd Sub sequence end character offset * @return Sub sequence of given offsets out of given text *//*w ww .j a v a2 s. c o m*/ public static String getSubString(CharSequence text, int offsetStart, int offsetEnd) { if (text.length() == 0) return null; return text.subSequence(offsetStart, offsetEnd).toString(); }
From source file:com.kstenschke.shifter.utils.UtilsTextual.java
/** * Get word at caret offset out of given text * * @param text The full text * @param cursorOffset Character offset of caret * @return The extracted word or null *///from w w w. j av a 2 s . co m public static String getWordAtOffset(CharSequence text, int cursorOffset) { if (text.length() == 0 || cursorOffset >= text.length()) return null; if (cursorOffset > 0 && !Character.isJavaIdentifierPart(text.charAt(cursorOffset)) && Character.isJavaIdentifierPart(text.charAt(cursorOffset - 1))) { cursorOffset--; } if (Character.isJavaIdentifierPart(text.charAt(cursorOffset))) { int start = cursorOffset; int end = cursorOffset; while (start > 0 && Character.isJavaIdentifierPart(text.charAt(start - 1))) { start--; } while (end < text.length() && Character.isJavaIdentifierPart(text.charAt(end))) { end++; } return text.subSequence(start, end).toString(); } return null; }
From source file:Main.java
/** * Determines if the input character sequence <code>cs</code> is a NCName * (Non-Colon Name). An NCName is a string which starts with an NCName start * character and is followed by zero or more NCName characters. * /*from w w w .j a v a2s. c om*/ * Source: http://www.w3.org/TR/xml-names/#NT-NCName * * @param cs * The character sequence to test. * @return Returns <code>true</code> if the input character sequence is a * NCName or <code>false</code> otherwise. */ public static boolean isNCName(CharSequence cs) { if (isEmpty(cs)) { return false; } int firstChar = Character.codePointAt(cs, 0); if (!isNCNameStartChar(firstChar)) { return false; } for (int i = Character.charCount(firstChar); i < cs.length();) { int c = Character.codePointAt(cs, i); if (!isNCNameChar(c)) { return false; } i += Character.charCount(c); } return true; }
From source file:dollar.internal.runtime.script.parser.DollarLexer.java
@SuppressWarnings("AssignmentToForLoopParameter") @NotNull//from w w w . j av a2 s. c o m private static String tokenizeBackTick(@NotNull CharSequence text) { int end = text.length() - 1; StringBuilder buf = new StringBuilder(); for (int i = 1; i < end; i++) { char c = text.charAt(i); if (c == '`') { buf.append('`'); i++; } else { buf.append(c); } } return buf.toString(); }
From source file:it.unimi.di.big.mg4j.document.SimpleCompressedDocumentCollectionBuilder.java
public static int writeSelfDelimitedUtf8String(final OutputBitStream obs, final CharSequence s) throws IOException { final int len = s.length(); int bits = 0; bits += obs.writeDelta(len);/*from w w w .j av a 2 s. c om*/ for (int i = 0; i < len; i++) bits += obs.writeZeta(s.charAt(i), 7); return bits; }
From source file:com.github.jillesvangurp.osm2geojson.OsmBlobIterable.java
static boolean fastEndsWith(CharSequence buf, String postFix) { // String.endsWith is very slow and creating extra String objects // every time we want to check the CharSequence content is // inefficient. This implementation simply inspects the end of the // CharSequence one character at the time. if (buf.length() < postFix.length()) { return false; } else {/* w ww . j a v a 2 s .c om*/ boolean match = true; for (int i = 1; i <= postFix.length(); i++) { match = match && buf.charAt(buf.length() - i) == postFix.charAt(postFix.length() - i); if (!match) { return false; } } return match; } }
From source file:com.aegiswallet.utils.BasicUtils.java
private static String guessAppropriateEncoding(CharSequence contents) { for (int i = 0; i < contents.length(); i++) { if (contents.charAt(i) > 0xFF) { return "UTF-8"; }/*w w w .j a va 2s .c om*/ } return null; }
From source file:Main.java
/** * Determines if a character sequence is an NCName (Non-Colonised Name). An * NCName is a string which starts with an NCName start character and is * followed by zero or more NCName characters. * /*w ww.jav a 2 s . c o m*/ * @param s * The character sequence to be tested. * @return {@code true} if {@code s} is an NCName, otherwise {@code false}. */ public static boolean isNCName(@Nullable CharSequence s) { if (isNullOrEmpty(s)) { return false; } assert s != null; int firstCodePoint = Character.codePointAt(s, 0); if (!isNCNameStartChar(firstCodePoint)) { return false; } for (int i = Character.charCount(firstCodePoint); i < s.length();) { int codePoint = Character.codePointAt(s, i); if (!isNCNameChar(codePoint)) { return false; } i += Character.charCount(codePoint); } return true; }
From source file:org.soitoolkit.commons.mule.util.MiscUtil.java
static private int findPlaceholderEndIndex(CharSequence buf, int startIndex) { int index = startIndex + placeholderPrefix.length(); int withinNestedPlaceholder = 0; while (index < buf.length()) { if (StringUtils.substringMatch(buf, index, placeholderSuffix)) { if (withinNestedPlaceholder > 0) { withinNestedPlaceholder--; index = index + 1;//w w w . j av a 2s .c om } else { return index; } } else if (StringUtils.substringMatch(buf, index, placeholderPrefix)) { withinNestedPlaceholder++; index = index + placeholderPrefix.length(); } else { index++; } } return -1; }