List of usage examples for java.lang CharSequence charAt
char charAt(int index);
From source file:org.openqa.selendroid.server.model.AndroidNativeElement.java
private static int indexOfSpecialKey(CharSequence string, int startIndex) { for (int i = startIndex; i < string.length(); i++) { if (AndroidKeys.hasAndroidKeyEvent(string.charAt(i))) { return i; }/*from w ww. j a va 2 s .c om*/ } return string.length(); }
From source file:org.apache.fop.fonts.GlyphMapping.java
/** * Given a mapped character sequence MCS, obtain glyph position adjustments from the * font's kerning data.//from w ww.j a va2 s .c o m * * @param mcs mapped character sequence * @param font applicable font * @return glyph position adjustments (or null if no kerning) */ private static int[][] getKerningAdjustments(CharSequence mcs, final Font font, int[][] gpa) { int nc = mcs.length(); // extract kerning array int[] ka = new int[nc]; // kerning array for (int i = 0, n = nc, cPrev = -1; i < n; i++) { int c = mcs.charAt(i); // TODO !BMP if (cPrev >= 0) { ka[i] = font.getKernValue(cPrev, c); } cPrev = c; } // was there a non-zero kerning? boolean hasKerning = false; for (int i = 0, n = nc; i < n; i++) { if (ka[i] != 0) { hasKerning = true; break; } } // if non-zero kerning, then create and return glyph position adjustment array if (hasKerning) { if (gpa == null) { gpa = new int[nc][4]; } for (int i = 0, n = nc; i < n; i++) { if (i > 0) { gpa[i - 1][GlyphPositioningTable.Value.IDX_X_ADVANCE] += ka[i]; } } return gpa; } else { return null; } }
From source file:com.piketec.jenkins.plugins.tpt.publisher.PieChart.java
private static final String plural(boolean plural, CharSequence text) { StringBuilder b = new StringBuilder(); int mode = 0; for (int i = 0; i < text.length(); i++) { char c = text.charAt(i); switch (mode) { case 0: // regular mode {//from w w w .j a va2s . co m if (c == '{') { mode = 1; } else { b.append(c); // always append } break; } case 1: // singular mode { if (c == '|') { mode = 2; } else if (!plural) { b.append(c); // append if singular } break; } case 2: // plural mode { if (c == '}') { mode = 0; } else if (plural) { b.append(c); // append if plural } break; } default: throw new RuntimeException(); } } return b.toString(); }
From source file:org.elasticsearch.hadoop.util.StringUtils.java
public static boolean hasText(CharSequence sequence) { if (!hasLength(sequence)) { return false; }//from w w w . j ava 2 s. c om int length = sequence.length(); for (int i = 0; i < length; i++) { if (!Character.isWhitespace(sequence.charAt(i))) { return true; } } return false; }
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 w w. j a v a 2 s . c o m 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:netbeanstypescript.TSService.java
static void stringToJS(StringBuilder sb, CharSequence s) { sb.append('"'); for (int i = 0; i < s.length(); i++) { char c = s.charAt(i); if (c < 0x20) { sb.append("\\u"); for (int j = 12; j >= 0; j -= 4) { sb.append("0123456789ABCDEF".charAt((c >> j) & 0x0F)); }//from w w w . j a v a2s . c om } else { if (c == '\\' || c == '"') { sb.append('\\'); } sb.append(c); } } sb.append('"'); }
From source file:com.fiveamsolutions.nci.commons.audit.DefaultProcessor.java
/** * encodes individual values in multi-value (eg Collection) attribute. * @param result where to write the encoded value. * @param val an individual value in the collection. */// w w w . j a va 2 s. com public static void escape(StringBuffer result, CharSequence val) { if (val == null) { return; } else if (val.length() == 0) { result.append("\"\""); } else { for (int i = 0; i < val.length(); i++) { char c = val.charAt(i); if (c == '\\' || c == ',' || c == '(' || c == ')') { result.append('\\'); } result.append(c); } } }
From source file:com.shishu.utility.string.StringUtil.java
/** * ?/* w w w.j a v a 2 s .co m*/ * * @author wangtao 2014-4-29 */ public static boolean isContainChar(CharSequence pat, CharSequence sub) { for (int i = 0; i < sub.length(); i++) { char subChar = sub.charAt(i); boolean isContain = false; for (int j = 0; j < pat.length(); j++) { if (pat.charAt(j) == subChar) { isContain = true; } } if (!isContain) { return false; } } return true; }
From source file:org.elasticsearch.hadoop.util.StringUtils.java
public static String deleteWhitespace(CharSequence sequence) { if (!hasLength(sequence)) { return EMPTY; }/*from w w w. ja v a 2 s. c om*/ StringBuilder sb = new StringBuilder(sequence.length()); for (int i = 0; i < sequence.length(); i++) { char currentChar = sequence.charAt(i); if (!Character.isWhitespace(currentChar)) { sb.append(currentChar); } } // return the initial String if no whitespace is found return (sb.length() == sequence.length() ? sequence.toString() : sb.toString()); }
From source file:org.artifactory.util.PathUtils.java
public static CharSequence trimTrailingSlashesChars(CharSequence path) { if (path == null) { return null; }/*from www . j a va 2s .c om*/ if (path.length() > 0 && path.charAt(path.length() - 1) == '/') { path = path.subSequence(0, path.length() - 1); return trimTrailingSlashes(path); } return path; }