private int find_extension() { int lastSlashIndex; final StringBuilder str = mString; // only look at the filename lastSlashIndex = str.lastIndexOf(File.pathSeparator); if (lastSlashIndex == -1) { lastSlashIndex = 0; } else { lastSlashIndex++; } // find the last dot return str.lastIndexOf(".", lastSlashIndex); }
private static void appendSeparatorToScriptIfNecessary(StringBuilder scriptBuilder, @Nullable String separator) { if (separator == null) { return; } String trimmed = separator.trim(); if (trimmed.length() == separator.length()) { return; } // separator ends in whitespace, so we might want to see if the script is trying // to end the same way if (scriptBuilder.lastIndexOf(trimmed) == scriptBuilder.length() - trimmed.length()) { scriptBuilder.append(separator.substring(trimmed.length())); } }
private static StringBuilder clearLastComma(StringBuilder buff) { int lastComma = buff.lastIndexOf(", "); // No comma found, take everything if (-1 != lastComma) buff.delete(lastComma, buff.length()); return buff; }
private static StringBuilder clearLastComma(StringBuilder buff) { int lastComma = buff.lastIndexOf(", "); // No comma found, take everything if (-1 != lastComma) buff.delete(lastComma, buff.length()); return buff; }
private static String join(StringBuilder out, Object[] linesToBreak) { for (Object line : linesToBreak) { out.append(line.toString()).append("\n"); } int lastBreak = out.lastIndexOf("\n"); return out.replace(lastBreak, lastBreak+1, "").toString(); } }
private static String replaceLast(String text, String pattern, String replacement) { StringBuilder builder = new StringBuilder(text); int lastIndexOf = builder.lastIndexOf(pattern); return builder.replace(lastIndexOf, lastIndexOf + pattern.length(), replacement).toString(); }
private String replaceLast(String text, String pattern, String replacement) { StringBuilder builder = new StringBuilder(text); int lastIndexOf = builder.lastIndexOf(pattern); return builder.replace(lastIndexOf, lastIndexOf + pattern.length(), replacement).toString(); } },
static void replaceVariable(StringBuilder sb, String key, String value) { // infinite loop avoidance if (key.equals(value)) { return; } // replace with minimum char movement int idx = sb.lastIndexOf(key); while (idx >= 0) { sb.replace(idx, idx + key.length(), value); idx = sb.lastIndexOf(key, idx); } } }
private void removeLastSegment(StringBuilder b) { int index = b.lastIndexOf("/"); if (index == -1) { b.setLength(0); } else { b.setLength(index); } }
public static String wordWrap(String text, int width) { StringBuilder builder = new StringBuilder(text); int i = 0; while (i + width < builder.length() && (i = builder.lastIndexOf(S_SPACE, i + width)) != -1) { builder.replace(i, i + 1, S_NEWLINE); } return builder.toString(); }
public static String wordWrap(String text, int width) { StringBuilder builder = new StringBuilder(text); int i = 0; while (i + width < builder.length() && (i = builder.lastIndexOf(S_SPACE, i + width)) != -1) { builder.replace(i, i + 1, S_NEWLINE); } return builder.toString(); }
public static String join(final Collection collection, String delimiter) { if (collection == null || collection.size() == 0) { return EMPTY; } final StringBuilder sb = new StringBuilder(collection.size() * 16); for (Object element : collection) { sb.append((String) element); sb.append(delimiter); } return sb.toString().substring(0, sb.lastIndexOf(delimiter)); }
private String substituteNameFromMap(String name, Map<String, String> keywordMap) { StringBuilder sbName = new StringBuilder(name); int fromIndex = sbName.length(); int equalIndex; while (-1 != (equalIndex = sbName.lastIndexOf("=", fromIndex))) { int commaIndex = sbName.lastIndexOf(",", equalIndex); String subName = sbName.substring(commaIndex + 1, equalIndex).trim(); if (keywordMap.containsKey(subName)) { sbName.replace(commaIndex + 1, equalIndex, keywordMap.get(subName)); } fromIndex = commaIndex; } return sbName.toString(); } }
@Override public String toString() { StringBuilder builder = new StringBuilder(); for (Attribute<?, ?> attribute : attributes) { builder.append(attribute.getName()).append("."); } return builder.length() == 0 ? "" : builder.substring(0, builder.lastIndexOf(".")); } }
private <T> Where in(List<T> values) { builder.append(Options.IN).append(" ("); String sep = ", "; for (T value : values) { if (value instanceof CharSequence) builder.append("'").append(value).append("'"); else if (value instanceof Integer || value instanceof Long || value instanceof Short) builder.append(value); builder.append(sep); } if (builder.lastIndexOf(sep) > 0) builder.delete(builder.length() - 2, builder.length()); builder.append(")"); return this; }
private CTEClause findCTEFromName(QB qb, String cteName) { StringBuilder qId = new StringBuilder(); if (qb.getId() != null) { qId.append(qb.getId()); } while (qId.length() > 0) { String nm = qId + ":" + cteName; CTEClause cte = aliasToCTEs.get(nm); if (cte != null) { return cte; } int lastIndex = qId.lastIndexOf(":"); lastIndex = lastIndex < 0 ? 0 : lastIndex; qId.setLength(lastIndex); } return aliasToCTEs.get(cteName); }
public static ConfigInfo merge(String dataId, String group, String tenant, List<ConfigInfoAggr> datumList) { StringBuilder sb = new StringBuilder(); String appName = null; for (ConfigInfoAggr aggrInfo : datumList) { if (aggrInfo.getAppName() != null) { appName = aggrInfo.getAppName(); } sb.append(aggrInfo.getContent()); sb.append(Constants.NACOS_LINE_SEPARATOR); } String content = sb.substring(0, sb.lastIndexOf(Constants.NACOS_LINE_SEPARATOR)); return new ConfigInfo(dataId, group, tenant, appName, content); }
public void process( final HttpRequest req, final HttpContext context ) throws HttpException, IOException { // set the Accept-Encoding header: String encoding = getContentEncoding(); if ( !req.containsHeader( ACCEPT_ENC_HDR ) ) req.addHeader( ACCEPT_ENC_HDR, encoding ); else { StringBuilder values = new StringBuilder(); for ( Header h : req.getHeaders( ACCEPT_ENC_HDR ) ) values.append( h.getValue() ).append( "," ); String encList = (!values.toString().contains( encoding )) ? values .append( encoding ).toString() : values.toString().substring( 0, values.lastIndexOf( "," ) ); req.setHeader( ACCEPT_ENC_HDR, encList ); } //TODO compress request and add content-encoding header. } }
static final void scanFor(StringBuilder sourceCode, String annotation, String inDoc, StringBuilder e, String baseClassName) { int index = 0; for (;;) { int idx = sourceCode.indexOf(annotation, index); if (idx < 0) { break; } int j = sourceCode.lastIndexOf("/**", idx); // see if the last /** is not before the index (last time the annotation was found // indicating an uncommented method like subscribe() if (j > index) { int k = sourceCode.indexOf(inDoc, j); if (k < 0 || k > idx) { // when printed on the console, IDEs will create a clickable link to help navigate to the offending point e.append("java.lang.RuntimeException: missing ").append(inDoc).append(" section\r\n") ; int lc = lineNumber(sourceCode, idx); e.append(" at io.reactivex.").append(baseClassName) .append(" (").append(baseClassName).append(".java:") .append(lc).append(")").append("\r\n\r\n"); } } index = idx + annotation.length(); } }
int j = sourceCode.lastIndexOf("/**", idx);