/** {@inheritDoc} */ public String getContent() { String str = super.getContent(); if (str == null) { return StrBuilder.this.toString(); } else { return str; } } }
/** * Sets the field delimiter character. * * @param delim the delimiter character to use * @return this, to enable chaining */ public StrTokenizer setDelimiterChar(char delim) { return setDelimiterMatcher(StrMatcher.charMatcher(delim)); }
/** * Replaces all the occurrences of variables in the given source object with * their matching values from the system properties. * * @param source the source text containing the variables to substitute, null returns null * @return the result of the replace operation */ public static String replaceSystemProperties(Object source) { return new StrSubstitutor(StrLookup.systemPropertiesLookup()).replace(source); }
/** * Replaces all the occurrences of variables within the given source * builder with their matching values from the resolver. * * @param source the builder to replace in, updated, null returns zero * @return true if altered */ public boolean replaceIn(StrBuilder source) { if (source == null) { return false; } return substitute(source, 0, source.length()); }
/** * 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; }
/** * Sets the field delimiter string. * * @param delim the delimiter string to use * @return this, to enable chaining */ public StrTokenizer setDelimiterString(String delim) { return setDelimiterMatcher(StrMatcher.stringMatcher(delim)); }
/** * Set the character to ignore. * <p> * This character is ignored when parsing the String, unless it is * within a quoted region. * * @param ignored the ignored character to use * @return this, to enable chaining */ public StrTokenizer setIgnoredChar(char ignored) { return setIgnoredMatcher(StrMatcher.charMatcher(ignored)); }
/** * Sets the quote character to use. * <p> * The quote character is used to wrap data between the tokens. * This enables delimiters to be entered as data. * * @param quote the quote character to use * @return this, to enable chaining */ public StrTokenizer setQuoteChar(char quote) { return setQuoteMatcher(StrMatcher.charMatcher(quote)); }
/** * Sets the variable prefix to use. * <p> * The variable prefix is the character or characters that identify the * start of a variable. This method allows a single character prefix to * be easily set. * * @param prefix the prefix character to use * @return this, to enable chaining */ public StrSubstitutor setVariablePrefix(char prefix) { return setVariablePrefixMatcher(StrMatcher.charMatcher(prefix)); }
/** * Sets the variable suffix to use. * <p> * The variable suffix is the characer or characters that identify the * end of a variable. This method allows a single character suffix to * be easily set. * * @param suffix the suffix character to use * @return this, to enable chaining */ public StrSubstitutor setVariableSuffix(char suffix) { return setVariableSuffixMatcher(StrMatcher.charMatcher(suffix)); }
/** * Utility method to parse and then reformat a String. * * @param input String to reformat * @return A reformatted String * @throws ParseException thrown by parseObject(String) call */ public String reformat(String input) throws ParseException { return format(parseObject(input)); }
/** * Creates a new instance and initializes it. Uses defaults for variable * prefix and suffix and the escaping character. * * @param valueMap the map with the variables' values, may be null */ public StrSubstitutor(Map valueMap) { this(StrLookup.mapLookup(valueMap), DEFAULT_PREFIX, DEFAULT_SUFFIX, DEFAULT_ESCAPE); }
/** * Searches the string builder to find the first reference to the specified char. * * @param ch the character to find * @return the first index of the character, or -1 if not found */ public int indexOf(char ch) { return indexOf(ch, 0); }
/** * Searches the string builder to find the last reference to the specified string. * <p> * Note that a null input string will return -1, whereas the JDK throws an exception. * * @param str the string to find, null returns -1 * @return the last index of the string, or -1 if not found */ public int lastIndexOf(String str) { return lastIndexOf(str, size - 1); }
/** * Returns a lookup which looks up values using a map. * <p> * If the map is null, then null will be returned from every lookup. * The map result object is converted to a string using toString(). * * @param map the map of keys to values, may be null * @return a lookup using the map, not null */ public static StrLookup mapLookup(Map map) { return new MapStrLookup(map); }
/** * Returns a clone of <code>CSV_TOKENIZER_PROTOTYPE</code>. * * @return a clone of <code>CSV_TOKENIZER_PROTOTYPE</code>. */ private static StrTokenizer getCSVClone() { return (StrTokenizer) CSV_TOKENIZER_PROTOTYPE.clone(); }
/** * Gets the number of tokens found in the String. * * @return the number of matched tokens */ public int size() { checkTokenized(); return tokens.length; }
/** * Searches the string builder to find the first reference to the specified string. * <p> * Note that a null input string will return -1, whereas the JDK throws an exception. * * @param str the string to find, null returns -1 * @return the first index of the string, or -1 if not found */ public int indexOf(String str) { return indexOf(str, 0); }