List of usage examples for java.lang CharSequence charAt
char charAt(int index);
From source file:org.apache.fop.complexscripts.bidi.UnicodeBidiAlgorithm.java
/** * Convert character sequence (a UTF-16 encoded string) to an array of unicode scalar values * expressed as integers. If a valid UTF-16 surrogate pair is encountered, it is converted to * two integers, the first being the equivalent unicode scalar value, and the second being * negative one (-1). This special mechanism is used to track the use of surrogate pairs while * working with unicode scalar values, and permits maintaining indices that apply both to the * input UTF-16 and out scalar value sequences. * @return a boolean indicating that content is present that triggers bidirectional processing * @param cs a UTF-16 encoded character sequence * @param chars an integer array to accept the converted scalar values, where the length of the * array must be the same as the length of the input character sequence * @throws IllegalArgumentException if the input sequence is not a valid UTF-16 string, e.g., * if it contains an isolated UTF-16 surrogate *///from ww w .j ava 2 s .c om private static boolean convertToScalar(CharSequence cs, int[] chars) throws IllegalArgumentException { boolean triggered = false; if (chars.length != cs.length()) { throw new IllegalArgumentException("characters array length must match input sequence length"); } for (int i = 0, n = chars.length; i < n;) { int chIn = cs.charAt(i); int chOut; if (chIn < 0xD800) { chOut = chIn; } else if (chIn < 0xDC00) { int chHi = chIn; int chLo; if ((i + 1) < n) { chLo = cs.charAt(i + 1); if ((chLo >= 0xDC00) && (chLo <= 0xDFFF)) { chOut = convertToScalar(chHi, chLo); } else { throw new IllegalArgumentException("isolated high surrogate"); } } else { throw new IllegalArgumentException("truncated surrogate pair"); } } else if (chIn < 0xE000) { throw new IllegalArgumentException("isolated low surrogate"); } else { chOut = chIn; } if (!triggered && triggersBidi(chOut)) { triggered = true; } if ((chOut & 0xFF0000) == 0) { chars[i++] = chOut; } else { chars[i++] = chOut; chars[i++] = -1; } } return triggered; }
From source file:ru.jts_dev.common.packets.OutgoingMessageWrapper.java
protected final void writeString(final CharSequence cs) { for (int i = 0; i < cs.length(); i++) { buffer.writeChar(cs.charAt(i)); }//from w w w . ja v a2 s . co m buffer.writeChar(EOS); }
From source file:net.sf.xfd.provider.ProviderBase.java
public static boolean isCanon(CharSequence s) { // XXX suspect conversion final String str = s.toString(); int l = s.length(); // check for dots at the end if (s.charAt(l - 1) == '.') { final int i = str.lastIndexOf('/'); if (i == l - 2 || (i == l - 3 && s.charAt(l - 2) == '.')) { return false; }//from ww w .ja v a2s. c o m } // detect slash-dot-slash segments int start = 0; int idx; do { idx = str.indexOf('/', start); if (idx == -1) { break; } switch (l - idx) { default: case 4: // at least three more chars remaining to right if (s.charAt(idx + 1) == '.' && s.charAt(idx + 2) == '.' && s.charAt(idx + 3) == '/') { return false; } case 3: // at least two more chars remaining to right if (s.charAt(idx + 1) == '.' && s.charAt(idx + 2) == '/') { return false; } case 2: // at least one more char remaining to right if (s.charAt(idx + 1) == '/') { return false; } case 1: } start += 2; } while (start < l); return true; }
From source file:com.nesscomputing.mojo.numbers.NumberField.java
private boolean isNumber(final CharSequence c) { for (int i = 0; i < c.length(); i++) { if (!Character.isDigit(c.charAt(i))) { return false; }/*from www .ja va2s . co m*/ } return true; }
From source file:org.renjin.parser.NumericLiterals.java
private static double parseDoubleHex(CharSequence s, int sign, int startIndex, int endIndex, char dec) { int n;//from www. j a va 2s. c om double fac; double ans = 0.0; int expn = 0; int exph = -1; int p = startIndex; /* This will overflow to Inf if appropriate */ for (p += 2; p < s.length(); p++) { char c = s.charAt(p); if ('0' <= c && c <= '9') { ans = 16 * ans + (s.charAt(p) - '0'); } else if ('a' <= c && c <= 'f') { ans = 16 * ans + (s.charAt(p) - 'a' + 10); } else if ('A' <= c && c <= 'F') { ans = 16 * ans + (s.charAt(p) - 'A' + 10); } else if (c == dec) { exph = 0; continue; } else { break; } if (exph >= 0) { exph += 4; } } if (p < endIndex && (s.charAt(p) == 'p' || s.charAt(p) == 'P')) { int expsign = 1; double p2 = 2.0; switch (s.charAt(++p)) { case '-': expsign = -1; p++; break; case '+': p++; break; } for (n = 0; p < endIndex && s.charAt(p) >= '0' && s.charAt(p) <= '9'; p++) { n = n * 10 + (s.charAt(p) - '0'); } expn += expsign * n; if (exph > 0) { expn -= exph; } if (expn < 0) { for (n = -expn, fac = 1.0; n != 0; n >>= 1, p2 *= p2) { if ((n & 1) != 0) { fac *= p2; } } ans /= fac; } else { for (n = expn, fac = 1.0; n != 0; n >>= 1, p2 *= p2) { if ((n & 1) != 0) fac *= p2; } ans *= fac; } } // Safeguard against malformed input if (p < endIndex) { ans = DoubleVector.NA; p = 0; /* back out */ return (sign * ans); } return sign * ans; }
From source file:org.mariotaku.twidere.adapter.AutoCompleteAdapter.java
@Override public Cursor runQueryOnBackgroundThread(final CharSequence constraint) { char token = mToken; if (mEditText != null && constraint != null) { final CharSequence text = mEditText.getText(); token = text.charAt(mEditText.getSelectionEnd() - constraint.length() - 1); }/* www. j a v a 2 s. c o m*/ if (isAtSymbol(token) == isAtSymbol(mToken)) { final FilterQueryProvider filter = getFilterQueryProvider(); if (filter != null) return filter.runQuery(constraint); } mToken = token; final CharSequence constraint_escaped = constraint != null ? constraint.toString().replaceAll("_", "^_") : null; if (isAtSymbol(token)) { final StringBuilder where = new StringBuilder(); where.append(CachedUsers.SCREEN_NAME + " LIKE '" + constraint_escaped + "%' ESCAPE '^'"); where.append(" OR "); where.append(CachedUsers.NAME + " LIKE '" + constraint_escaped + "%' ESCAPE '^'"); return mResolver.query(CachedUsers.CONTENT_URI, CACHED_USERS_COLUMNS, constraint_escaped != null ? where.toString() : null, null, null); } else { final String where = CachedHashtags.NAME + " LIKE '" + constraint_escaped + "%' ESCAPE '^'"; return mResolver.query(CachedHashtags.CONTENT_URI, CachedHashtags.COLUMNS, constraint_escaped != null ? where : null, null, null); } }
From source file:routines.system.BigDataParserUtils.java
/** * StringUtils from apache commons-lang3 3.3.2 * * We use this implementation in order to avoid using the common lang package and be compatible with any hadoop * distribution.//from w w w . j a va 2 s. c o m * * Checks if a CharSequence is whitespace, empty ("") or null. * * @param cs the CharSequence to check, may be null * @returntrue if the CharSequence is null, empty or whitespace */ public static boolean isBlank(final CharSequence cs) { int strLen; if (cs == null || (strLen = cs.length()) == 0) { return true; } for (int i = 0; i < strLen; i++) { if (Character.isWhitespace(cs.charAt(i)) == false) { return false; } } return true; }
From source file:com.github.nevo.decorators.reply.wechat.WeChatDecorator.java
/** @return the extracted count in 0xFF range and start position in 0xFF00 range */ private int trimAndExtractLeadingCounter(final CharSequence text) { // Parse and remove the leading "[n]" or [n?//] if (text == null || text.length() < 4 || text.charAt(0) != '[') return -1; int text_start = 3, count_end; while (text.charAt(text_start++) != ']') if (text_start >= text.length()) return -1; try {/*from w ww .java 2s . c o m*/ final String num = text.subSequence(1, text_start - 1).toString(); // may contain the suffix "?/" for (count_end = 0; count_end < num.length(); count_end++) if (!Character.isDigit(num.charAt(count_end))) break; if (count_end == 0) return -1; // Not the expected "unread count" final int count = Integer.parseInt(num.substring(0, count_end)); if (count < 2) return -1; return count < 0xFFFF ? (count & 0xFFFF) | ((text_start << 16) & 0xFFFF0000) : 0xFFFF | ((text_start << 16) & 0xFF00); } catch (final NumberFormatException ignored) { Log.d(TAG, "Failed to parse: " + text); return -1; } }
From source file:com.intellij.lang.jsgraphql.ide.annotator.JSGraphQLAnnotator.java
private void applyWhiteSpace(CharSequence source, StringBuilder target, int start, int end) { for (int i = start; i < end; i++) { char c = source.charAt(i); switch (c) { case '\t': case '\n': target.setCharAt(i, c);/*from w ww .ja v a2 s.c om*/ break; default: target.setCharAt(i, ' '); break; } } }
From source file:org.mariotaku.twidere.adapter.ComposeAutoCompleteAdapter.java
@Override public Cursor runQueryOnBackgroundThread(final CharSequence constraint) { if (TextUtils.isEmpty(constraint)) return null; char token = constraint.charAt(0); if (getNormalizedSymbol(token) == getNormalizedSymbol(mToken)) { final FilterQueryProvider filter = getFilterQueryProvider(); if (filter != null) return filter.runQuery(constraint); }//from w ww. ja v a 2 s. c o m mToken = token; final Uri.Builder builder = Suggestions.AutoComplete.CONTENT_URI.buildUpon(); builder.appendQueryParameter(QUERY_PARAM_QUERY, String.valueOf(constraint.subSequence(1, constraint.length()))); switch (getNormalizedSymbol(token)) { case '#': { builder.appendQueryParameter(QUERY_PARAM_TYPE, Suggestions.AutoComplete.TYPE_HASHTAGS); break; } case '@': { builder.appendQueryParameter(QUERY_PARAM_TYPE, Suggestions.AutoComplete.TYPE_USERS); break; } default: { return null; } } builder.appendQueryParameter(QUERY_PARAM_ACCOUNT_KEY, String.valueOf(accountKey)); return mContext.getContentResolver().query(builder.build(), Suggestions.AutoComplete.COLUMNS, null, null, null); }