/** * Replaces all the occurrences of variables with their matching values * from the resolver using the given source builder as a template. * The builder is not altered by this method. * * @param source the builder to use as a template, not changed, null returns null * @return the result of the replace operation */ public String replace(StrBuilder source) { if (source == null) { return null; } StrBuilder buf = new StrBuilder(source.length()).append(source); substitute(buf, 0, buf.length()); return buf.toString(); }
/** * Appends an object followed by a new line to this string builder. * Appending null will call {@link #appendNull()}. * * @param obj the object to append * @return this, to enable chaining * @since 2.3 */ public StrBuilder appendln(Object obj) { return append(obj).appendNewLine(); }
/** * Checks if the specified variable is already in the stack (list) of variables. * * @param varName the variable name to check * @param priorVariables the list of prior variables */ private void checkCyclicSubstitution(String varName, List priorVariables) { if (priorVariables.contains(varName) == false) { return; } StrBuilder buf = new StrBuilder(256); buf.append("Infinite loop in property interpolation of "); buf.append(priorVariables.remove(0)); buf.append(": "); buf.appendWithSeparators(priorVariables, "->"); throw new IllegalStateException(buf.toString()); }
/** * Appends a char value to the string builder. * * @param ch the value to append * @return this, to enable chaining */ public StrBuilder append(char ch) { int len = length(); ensureCapacity(len + 1); buffer[size++] = ch; return this; }
/** * <p>Gets the range as a <code>String</code>.</p> * * <p>The format of the String is 'Range[<i>min</i>,<i>max</i>]'.</p> * * @return the <code>String</code> representation of this range */ public String toString() { if (toString == null) { StrBuilder buf = new StrBuilder(32); buf.append("Range["); buf.append(min); buf.append(','); buf.append(max); buf.append(']'); toString = buf.toString(); } return toString; }
public List<String> split(String input) { List<String> statements = new ArrayList<String>(); StrBuilder currentSql = new StrBuilder(); StrTokenizer lineTokenizer = new StrTokenizer(input); lineTokenizer.setDelimiterMatcher(StrMatcher.charSetMatcher("\r\n")); for (String line : lineTokenizer.getTokenArray()) { String strippedLine = StringUtils.stripEnd(line, null); if (!currentSql.isEmpty()) { currentSql.append(lineEnding.get()); } currentSql.append(strippedLine); if (delimiterType.matches(strippedLine, delimiter)) { statements.add(currentSql.substring(0, currentSql.length() - delimiter.length())); currentSql.clear(); } } if (!currentSql.isEmpty()) { statements.add(currentSql.toString()); } return statements; }
buf.deleteCharAt(pos - 1); - startMatchLen); if (isEnableSubstitutionInVariables()) { StrBuilder bufName = new StrBuilder(varName); substitute(bufName, 0, bufName.length()); varName = bufName.toString(); buf.replace(startPos, endPos, varValue); altered = true; int change = substitute(buf, startPos,
private static String removeEnclosure( String stringToSplit, String enclosure ) { int firstIndex = stringToSplit.indexOf( enclosure ); int lastIndex = stringToSplit.lastIndexOf( enclosure ); if ( firstIndex == lastIndex ) { return stringToSplit; } StrBuilder strBuilder = new StrBuilder( stringToSplit ); strBuilder.replace( firstIndex, enclosure.length() + firstIndex, "" ); strBuilder.replace( lastIndex - enclosure.length(), lastIndex, "" ); return strBuilder.toString(); }
/** * <p>Reverses a String as per {@link StrBuilder#reverse()}.</p> * * <p>A <code>null</code> String returns <code>null</code>.</p> * * <pre> * StringUtils.reverse(null) = null * StringUtils.reverse("") = "" * StringUtils.reverse("bat") = "tab" * </pre> * * @param str the String to reverse, may be null * @return the reversed String, <code>null</code> if null String input */ public static String reverse(String str) { if (str == null) { return null; } return new StrBuilder(str).reverse().toString(); }
/** * Appends another string builder to this string builder. * Appending null will call {@link #appendNull()}. * * @param str the string builder to append * @return this, to enable chaining */ public StrBuilder append(StrBuilder str) { if (str == null) { return appendNull(); } int strLen = str.length(); if (strLen > 0) { int len = length(); ensureCapacity(len + strLen); System.arraycopy(str.buffer, 0, buffer, len, strLen); size += strLen; } return this; }
/** * Concatenate strings with a separator * * @param stringList * @param defaultEmptyValue * @return */ protected String getListWithSeparator(List<String> stringList, String defaultEmptyValue) { final String SEPARATOR = " "; StrBuilder builder = new StrBuilder(); builder = builder.appendWithSeparators(stringList, SEPARATOR); return builder.isEmpty() ? defaultEmptyValue : builder.toString(); }
/** * Replaces all the occurrences of variables with their matching values * from the resolver using the given source string as a template. * * @param source the string to replace in, null returns null * @return the result of the replace operation */ public String replace(String source) { if (source == null) { return null; } StrBuilder buf = new StrBuilder(source); if (substitute(buf, 0, source.length()) == false) { return source; } return buf.toString(); }
/** * Appends the text representing <code>null</code> to this string builder. * * @return this, to enable chaining */ public StrBuilder appendNull() { if (nullText == null) { return this; } return append(nullText); }
/** * Appends part of a string builder to this string builder. * Appending null will call {@link #appendNull()}. * * @param str the string to append * @param startIndex the start index, inclusive, must be valid * @param length the length to append, must be valid * @return this, to enable chaining */ public StrBuilder append(StrBuilder str, int startIndex, int length) { if (str == null) { return appendNull(); } if (startIndex < 0 || startIndex > str.length()) { throw new StringIndexOutOfBoundsException("startIndex must be valid"); } if (length < 0 || (startIndex + length) > str.length()) { throw new StringIndexOutOfBoundsException("length must be valid"); } if (length > 0) { int len = length(); ensureCapacity(len + length); str.getChars(startIndex, startIndex + length, buffer, len); size += length; } return this; }
/** * Appends an object to this string builder. * Appending null will call {@link #appendNull()}. * * @param obj the object to append * @return this, to enable chaining */ public StrBuilder append(Object obj) { if (obj == null) { return appendNull(); } return append(obj.toString()); }
/** {@inheritDoc} */ public String getContent() { String str = super.getContent(); if (str == null) { return StrBuilder.this.toString(); } else { return str; } } }
/** {@inheritDoc} */ public int read() { if (ready() == false) { return -1; } return StrBuilder.this.charAt(pos++); }