### Starts With String Source: https://commons.apache.org/proper/commons-text/javadocs/api-release/org/apache/commons/text/StrBuilder.html Checks whether this builder starts with the specified string. Handles null input quietly. ```APIDOC ## startsWith ### Description Checks whether this builder starts with the specified string. Note that this method handles null input quietly, unlike String. ### Parameters #### Path Parameters - `str` (String) - Required - the string to search for, null returns false ### Returns - true if the builder starts with the string ``` -------------------------------- ### ResourceBundle StringLookup (Default) Example Source: https://commons.apache.org/proper/commons-text/apidocs/src-html/org/apache/commons/text/lookup/StringLookupFactory.html Shows how to use the default resourceBundleStringLookup to get a value from a resource bundle. The key format is 'BundleName:BundleKey'. ```java StringLookupFactory.INSTANCE.resourceBundleStringLookup().lookup("com.domain.messages:MyKey"); ``` ```java StringSubstitutor.createInterpolator().replace("... ${resourceBundle:com.domain.messages:MyKey} ...")); ``` -------------------------------- ### Local Host StringLookup Example Source: https://commons.apache.org/proper/commons-text/apidocs/src-html/org/apache/commons/text/lookup/StringLookupFactory.html Shows how to use the InetAddressStringLookup for local host information. It can be used to get the host's name, canonical name, or address, either directly or through a StringSubstitutor. ```java StringLookupFactory.INSTANCE.localHostStringLookup().lookup("canonical-name"); ``` ```java StringSubstitutor.createInterpolator().replace("... ${localhost:canonical-name} ...")); ``` -------------------------------- ### get() Source: https://commons.apache.org/proper/commons-text/apidocs/org/apache/commons/text/TextStringBuilder.html Converts this instance to a String. ```APIDOC ## get() ### Description Converts this instance to a String. ### Method Not specified (assumed to be a method call on a TextStringBuilder instance) ### Returns String - The string representation of the builder. ``` -------------------------------- ### Example Builder Implementation Source: https://commons.apache.org/proper/commons-text/apidocs/org/apache/commons/text/Builder.html Demonstrates how to implement the Builder interface for constructing a Font object. Configuration methods return `this` to allow chaining. ```java class FontBuilder implements Builder { private Font font; public FontBuilder(String fontName) { this.font = new Font(fontName, Font.PLAIN, 12); } public FontBuilder bold() { this.font = this.font.deriveFont(Font.BOLD); return this; // Reference returned so calls can be chained } public FontBuilder size(float pointSize) { this.font = this.font.deriveFont(pointSize); return this; // Reference returned so calls can be chained } // Other Font construction methods public Font build() { return this.font; } } ``` -------------------------------- ### Get Substring from Start Index Source: https://commons.apache.org/proper/commons-text/cpd.html Extracts a portion of this string builder as a string from the specified start index to the end. ```java /** * Extracts a portion of this string builder as a string. * * @param start the start index, inclusive, must be valid. * @return The new string. * @throws IndexOutOfBoundsException if the index is invalid. */ public String substring(final int start) { return substring(start, size); } ``` -------------------------------- ### Get Pattern Example Source: https://commons.apache.org/proper/commons-text/xref/org/apache/commons/text/ExtendedMessageFormat.html Retrieves the pattern string used by the ExtendedMessageFormat. ```java @Override public String toPattern() { return toPattern; } ``` -------------------------------- ### Basic Tokenization Examples Source: https://commons.apache.org/proper/commons-text/apidocs/org/apache/commons/text/StringTokenizer.html Demonstrates basic tokenization scenarios with different inputs and default CSV processing. ```java "a,b,c" - Three tokens "a","b","c" (comma delimiter) ``` ```java " a, b , c " - Three tokens "a","b","c" (default CSV processing trims whitespace) ``` ```java "a, ", b ,", c" - Three tokens "a, " , " b ", ", c" (quoted text untouched) ``` -------------------------------- ### Example Builder Usage Source: https://commons.apache.org/proper/commons-text/javadocs/api-release/org/apache/commons/text/Builder.html Demonstrates how to use the FontBuilder to construct a Font object by chaining configuration methods. ```java Font bold14ptSansSerifFont = new FontBuilder(Font.SANS_SERIF).bold() .size(14.0f) .build(); ``` -------------------------------- ### getVariablePrefixMatcher Source: https://commons.apache.org/proper/commons-text/xref/org/apache/commons/text/StringSubstitutor.html Gets the StringMatcher that defines the prefix for variable names. This is used to identify the start of a variable reference. ```APIDOC ## getVariablePrefixMatcher ### Description Gets the variable prefix matcher currently in use. This matcher identifies the start of a variable. ### Method GET ### Endpoint N/A (Method Call) ### Returns - **StringMatcher**: The prefix matcher in use. ``` -------------------------------- ### Example Builder Usage Source: https://commons.apache.org/proper/commons-text/apidocs/org/apache/commons/text/Builder.html Shows how to use the `FontBuilder` to create a bold, 14pt sans-serif font by chaining builder methods. ```java Font bold14ptSansSerifFont = new FontBuilder(Font.SANS_SERIF) .bold() .size(14.0f) .get(); ``` -------------------------------- ### Example of Recursive Variable in Value Source: https://commons.apache.org/proper/commons-text/apidocs/org/apache/commons/text/StringSubstitutor.html Demonstrates how a variable value can contain another variable that gets replaced recursively. Cyclic replacements are detected and will throw an exception. ```text "The variable ${${name}} must be used." ``` -------------------------------- ### Java - toCamelCase Method Examples Source: https://commons.apache.org/proper/commons-text/javadocs/api-release/org/apache/commons/text/CaseUtils.html Illustrates various scenarios for the toCamelCase method, showing its behavior with null input, empty strings, different delimiters, and capitalization options. ```java CaseUtils.toCamelCase(null, false) = null CaseUtils.toCamelCase("", false, *) = "" CaseUtils.toCamelCase(*, false, null) = * CaseUtils.toCamelCase(*, true, new char[0]) = * CaseUtils.toCamelCase("To.Camel.Case", false, new char[]{'.'}) = "toCamelCase" CaseUtils.toCamelCase(" to @ Camel case", true, new char[]{'@'}) = "ToCamelCase" CaseUtils.toCamelCase(" @to @ Camel case", false, new char[]{'@'}) = "toCamelCase" ``` -------------------------------- ### startsWith Source: https://commons.apache.org/proper/commons-text/apidocs/org/apache/commons/text/TextStringBuilder.html Checks whether this builder starts with the specified string. Handles null input quietly. ```APIDOC ## startsWith ### Description Checks whether this builder starts with the specified string. Note that this method handles null input quietly, unlike String. ### Method public boolean startsWith(String str) ### Parameters #### Path Parameters - **str** (String) - Required - The string to search for, null returns false. ### Returns - **boolean** - true if the builder starts with the string. ``` -------------------------------- ### Get Localized Digit String Source: https://commons.apache.org/proper/commons-text/apidocs/src-html/org/apache/commons/text/numbers/DoubleFormat.html Constructs a string containing localized digits 0-9 based on the provided DecimalFormatSymbols. It starts with the zero digit and adds the next nine consecutive characters. ```java private static String getDigitString(final DecimalFormatSymbols symbols) { final int zeroDelta = symbols.getZeroDigit() - DEFAULT_DECIMAL_DIGITS.charAt(0); final char[] digitChars = new char[DEFAULT_DECIMAL_DIGITS.length()]; for (int i = 0; i < DEFAULT_DECIMAL_DIGITS.length(); ++i) { digitChars[i] = (char) (DEFAULT_DECIMAL_DIGITS.charAt(i) + zeroDelta); } return String.valueOf(digitChars); } ``` -------------------------------- ### Lookup Example Format Source: https://commons.apache.org/proper/commons-text/jacoco/org.apache.commons.text.lookup/XmlStringLookup.java.html Demonstrates the expected format for lookup keys, which combines the document path and an XPath expression separated by a colon. ```java "com/domain/document.xml:/path/to/node" ``` -------------------------------- ### Example FontBuilder Implementation Source: https://commons.apache.org/proper/commons-text/apidocs/src-html/org/apache/commons/text/Builder.html Demonstrates a concrete implementation of the Builder interface for constructing Font objects. It includes methods for setting bold style and font size, returning 'this' for chaining. ```java class FontBuilder implements Builder { private Font font; public FontBuilder(String fontName) { this.font = new Font(fontName, Font.PLAIN, 12); } public FontBuilder bold() { this.font = this.font.deriveFont(Font.BOLD); return this; // Reference returned so calls can be chained } public FontBuilder size(float pointSize) { this.font = this.font.deriveFont(pointSize); return this; // Reference returned so calls can be chained } // Other Font construction methods public Font build() { return this.font; } } ``` -------------------------------- ### Swap Case Example Source: https://commons.apache.org/proper/commons-text/apidocs/org/apache/commons/text/WordUtils.html Swaps the case of characters in a string based on specific rules: uppercase to lowercase, title case to lowercase, lowercase after whitespace or at the start to title case, and other lowercase to uppercase. Handles null and empty strings. ```java StringUtils.swapCase(null) = null StringUtils.swapCase("") = "" StringUtils.swapCase("The dog has a BONE") = "tHE DOG HAS A bone" ``` -------------------------------- ### Environment Variable Lookup Example Source: https://commons.apache.org/proper/commons-text/apidocs/src-html/org/apache/commons/text/lookup/StringLookupFactory.html Demonstrates looking up environment variables using the INSTANCE_ENVIRONMENT_VARIABLES. This is useful for interpolating environment-specific values. ```java StringLookupFactory.INSTANCE.environmentVariableStringLookup().lookup("USER"); ``` ```java StringSubstitutor.createInterpolator().replace("... ${env:USER} ...")); ``` -------------------------------- ### Get Previous Token Index Source: https://commons.apache.org/proper/commons-text/jacoco/org.apache.commons.text/StringTokenizer.java.html Gets the index of the previous token. ```Java @Override public int previousIndex() { return tokenPos - 1; } ``` -------------------------------- ### Find First Character Index from Start Source: https://commons.apache.org/proper/commons-text/xref/org/apache/commons/text/StrBuilder.html Searches for the first occurrence of a specified character starting from a given index. Invalid start indices are adjusted to the nearest valid edge. ```Java public int indexOf(final char ch, final int startIndex) { // Implementation details for searching from startIndex would follow here. // This is a placeholder based on the provided snippet structure. return -1; // Placeholder return } ``` -------------------------------- ### System Property StringLookup Example Source: https://commons.apache.org/proper/commons-text/javadocs/api-release/org/apache/commons/text/lookup/StringLookupFactory.html Shows how to use SystemPropertyStringLookup via StringLookupFactory to retrieve system property values. ```java StringLookupFactory.INSTANCE.systemPropertyStringLookup().lookup("os.name"); ``` ```java StringSubstitutor.createInterpolator().replace("... ${sys:os.name} ...")); ``` -------------------------------- ### get() Source: https://commons.apache.org/proper/commons-text/jacoco/org.apache.commons.text/TextStringBuilder.java.html Gets the current String representation of the StringBuilder. This is equivalent to calling toString(). ```APIDOC ## get() ### Description Gets the current String representation of the StringBuilder. This is equivalent to calling toString(). ### Method GET ### Endpoint N/A (Method call) ### Parameters None ### Response #### Success Response (200) - **string** (string) - The string representation of the StringBuilder. ``` -------------------------------- ### DNS String Lookup Example Source: https://commons.apache.org/proper/commons-text/apidocs/src-html/org/apache/commons/text/lookup/StringLookupFactory.html Demonstrates how to use the DnsStringLookup to resolve hostnames and IP addresses. It can be used directly or with a StringSubstitutor. ```Java StringLookupFactory.INSTANCE.dnsStringLookup().lookup("address|apache.org"); ``` ```Java Map lookupMap = new HashMap<>(); lookupMap.put("dns", StringLookupFactory.INSTANCE.dnsStringLookup()); StringLookup variableResolver = StringLookupFactory.INSTANCE.interpolatorStringLookup(lookupMap, null, false); new StringSubstitutor(variableResolver).replace("... ${dns:address|apache.org} ..."); ``` -------------------------------- ### Get Next Token Index Source: https://commons.apache.org/proper/commons-text/jacoco/org.apache.commons.text/StringTokenizer.java.html Gets the index of the next token to return. ```Java @Override public int nextIndex() { return tokenPos; } ``` -------------------------------- ### Basic Tokenization Example Source: https://commons.apache.org/proper/commons-text/javadocs/api-release/org/apache/commons/text/StrTokenizer.html Demonstrates basic tokenization of a comma-separated string. By default, it splits on commas and trims whitespace. ```java StrTokenizer tokenizer = new StrTokenizer("a,b,c"); String[] tokens = tokenizer.getTokenAsArray(); // tokens is {"a", "b", "c"} ``` -------------------------------- ### Get Capacity of StrBuilder Source: https://commons.apache.org/proper/commons-text/xref/org/apache/commons/text/StrBuilder.html Gets the current size of the internal character array buffer. ```java public int capacity() { return buffer.length; } ``` -------------------------------- ### Find First Match Using StringMatcher from Start Source: https://commons.apache.org/proper/commons-text/jacoco/org.apache.commons.text/TextStringBuilder.java.html Searches for the first match of a StringMatcher, starting from a specified index. Returns -1 if no match is found or if the matcher is null. Invalid start indices are adjusted. ```Java public int indexOf(final StringMatcher matcher, int startIndex) { startIndex = Math.max(0, startIndex); if (matcher == null || startIndex >= size) { return StringUtils.INDEX_NOT_FOUND; } final int len = size; final char[] buf = buffer; for (int i = startIndex; i < len; i++) { if (matcher.isMatch(buf, i, startIndex, len) > 0) { return i; } } return StringUtils.INDEX_NOT_FOUND; } ``` -------------------------------- ### Java - WordUtils Abbreviate Examples Source: https://commons.apache.org/proper/commons-text/javadocs/api-release/org/apache/commons/text/WordUtils.html Demonstrates various ways to use the WordUtils.abbreviate method with different string inputs, lower and upper limits, and append strings. Shows expected outputs and potential exceptions. ```java WordUtils.abbreviate("Now is the time for all good men", 0, 40, null)); = "Now" WordUtils.abbreviate("Now is the time for all good men", 10, 40, null)); = "Now is the" WordUtils.abbreviate("Now is the time for all good men", 20, 40, null)); = "Now is the time for all" WordUtils.abbreviate("Now is the time for all good men", 0, 40, "")); = "Now" WordUtils.abbreviate("Now is the time for all good men", 10, 40, "")); = "Now is the" WordUtils.abbreviate("Now is the time for all good men", 20, 40, "")); = "Now is the time for all" WordUtils.abbreviate("Now is the time for all good men", 0, 40, " ...")); = "Now ..." WordUtils.abbreviate("Now is the time for all good men", 10, 40, " ...")); = "Now is the ..." WordUtils.abbreviate("Now is the time for all good men", 20, 40, " ...")); = "Now is the time for all ..." WordUtils.abbreviate("Now is the time for all good men", 0, -1, "")); = "Now" WordUtils.abbreviate("Now is the time for all good men", 10, -1, "")); = "Now is the" WordUtils.abbreviate("Now is the time for all good men", 20, -1, "")); = "Now is the time for all" WordUtils.abbreviate("Now is the time for all good men", 50, -1, "")); = "Now is the time for all good men" WordUtils.abbreviate("Now is the time for all good men", 1000, -1, "")); = "Now is the time for all good men" WordUtils.abbreviate("Now is the time for all good men", 9, -10, null)); = IllegalArgumentException WordUtils.abbreviate("Now is the time for all good men", 10, 5, null)); = IllegalArgumentException ``` -------------------------------- ### Find First Character Index from Start Index Source: https://commons.apache.org/proper/commons-text/jacoco/org.apache.commons.text/StrBuilder.java.html Searches for the first occurrence of a specified character within the StrBuilder, starting from a given index. Invalid start indices are rounded to the nearest valid edge. ```Java public int indexOf(final char ch, int startIndex) { startIndex = Math.max(startIndex, 0); if (startIndex >= size) { return -1; } final char[] thisBuf = buffer; for (int i = startIndex; i < size; i++) { if (thisBuf[i] == ch) { return i; } } return -1; } ``` -------------------------------- ### Date String Lookup Example Source: https://commons.apache.org/proper/commons-text/apidocs/org/apache/commons/text/lookup/StringLookupFactory.html Demonstrates formatting the current date using the DateStringLookup from StringLookupFactory with a specified format. ```java StringLookupFactory.INSTANCE.dateStringLookup().lookup("yyyy-MM-dd"); ``` ```java StringSubstitutor.createInterpolator().replace("... ${date:yyyy-MM-dd} ...")); ``` -------------------------------- ### build Source: https://commons.apache.org/proper/commons-text/javadocs/api-release/org/apache/commons/text/TextStringBuilder.html Implement the Builder interface. Returns the final String. ```APIDOC ## build ### Description Implement the Builder interface. Returns the final String. ### Method Not applicable (Java method) ### Returns (String) - The final String built by the builder. ``` -------------------------------- ### Get Character at Index Source: https://commons.apache.org/proper/commons-text/xref/org/apache/commons/text/StrBuilder.html Gets the character at the specified index. Throws an IndexOutOfBoundsException if the index is invalid. ```java @Override public char charAt(final int index) { if (index < 0 || index >= length()) { throw new StringIndexOutOfBoundsException(index); } return buffer[index]; } ``` -------------------------------- ### Java Platform String Lookup Example Source: https://commons.apache.org/proper/commons-text/jacoco/org.apache.commons.text.lookup/JavaPlatformStringLookup.java.html Demonstrates how to use JavaPlatformStringLookup to retrieve system properties like Java version. This lookup is useful for dynamically accessing environment details. ```java return "Java version " + getSystemProperty("java.version"); ``` ```java return getRuntime(); ``` ```java return getVirtualMachine(); ``` ```java return getOperatingSystem(); ``` ```java return getHardware(); ``` ```java return getLocale(); ``` ```java throw new IllegalArgumentException(key); ``` -------------------------------- ### substring(int start) Source: https://commons.apache.org/proper/commons-text/javadocs/api-release/org/apache/commons/text/TextStringBuilder.html Extracts a portion of this string builder as a string, starting from the specified index. ```APIDOC ## substring(int start) ### Description Extracts a portion of this string builder as a new `String`, starting from the specified index to the end of the builder. ### Method `substring` ### Parameters * **start** (int) - The starting index (inclusive) of the substring. ### Returns `String` - A new `String` representing the extracted portion. ``` -------------------------------- ### Get Previous Token (Nullable) Source: https://commons.apache.org/proper/commons-text/jacoco/org.apache.commons.text/StringTokenizer.java.html Gets the previous token from the String. Returns null when no more tokens are found. ```Java public String previousToken() { if (hasPrevious()) { return tokens[--tokenPos]; } return null; } ``` -------------------------------- ### startsWith(String str) Source: https://commons.apache.org/proper/commons-text/apidocs/org/apache/commons/text/StrBuilder.html Checks whether this builder starts with the specified string. This method is deprecated. ```APIDOC ## startsWith(String str) ### Description Checks whether this builder starts with the specified string. ### Method Not specified (likely a method call on a StrBuilder object) ### Parameters * **str** (String) - The string to check for. ### Returns * **boolean** - true if the builder starts with the string, false otherwise. ### Deprecated This method is deprecated. ``` -------------------------------- ### Base64 Decoder Example Source: https://commons.apache.org/proper/commons-text/apidocs/src-html/org/apache/commons/text/lookup/StringLookupFactory.html Demonstrates decoding a Base64 encoded string using the INSTANCE_BASE64_DECODER. This is useful for interpolating Base64 encoded values. ```java StringSubstitutor.createInterpolator().replace("... ${base64Decoder:SGVsbG9Xb3JsZCE=} ...")); ``` -------------------------------- ### Get Next Token (Iterator) Source: https://commons.apache.org/proper/commons-text/jacoco/org.apache.commons.text/StringTokenizer.java.html Gets the next token from the String. Throws NoSuchElementException if no more tokens are available. ```Java @Override public String next() { if (hasNext()) { return tokens[tokenPos++]; } throw new NoSuchElementException(); } ``` -------------------------------- ### Using Fenced File StringLookup with builder() Source: https://commons.apache.org/proper/commons-text/jacoco/org.apache.commons.text.lookup/StringLookupFactory.java.html Demonstrates how to configure a file StringLookup with fences using the builder. It shows successful lookups and examples that throw IllegalArgumentException for restricted paths. ```java StringLookupFactory factory = StringLookupFactory.builder().setFences(Paths.get("")).get(); factory.fileStringLookup().lookup("UTF-8:com/domain/document.txt"); // throws IllegalArgumentException factory.fileStringLookup().lookup("UTF-8:/rootdir/foo/document.txt"); // throws IllegalArgumentException factory.fileStringLookup().lookup("UTF-8:../document.txt"); ``` -------------------------------- ### Find First Substring Index from Start Source: https://commons.apache.org/proper/commons-text/jacoco/org.apache.commons.text/TextStringBuilder.java.html Searches for the first occurrence of a specified string, starting from a given index. Handles null input strings by returning -1. Invalid start indices are adjusted to the nearest valid boundary. ```Java public int indexOf(final String str, int startIndex) { startIndex = Math.max(0, startIndex); if (str == null || startIndex >= size) { return StringUtils.INDEX_NOT_FOUND; } final int strLen = str.length(); if (strLen == 1) { return indexOf(str.charAt(0), startIndex); } if (strLen == 0) { return startIndex; } if (strLen > size) { return StringUtils.INDEX_NOT_FOUND; } final char[] thisBuf = buffer; final int searchLen = size - strLen + 1; for (int i = startIndex; i < searchLen; i++) { boolean found = true; for (int j = 0; j < strLen && found; j++) { found = str.charAt(j) == thisBuf[i + j]; } if (found) { return i; } } return StringUtils.INDEX_NOT_FOUND; } ``` -------------------------------- ### accept Method Source: https://commons.apache.org/proper/commons-text/javadocs/api-release/org/apache/commons/text/diff/DeleteCommand.html Accepts a visitor and calls the appropriate visit method on it. For DeleteCommand, it calls `visitDeleteCommand`. ```APIDOC ## accept(CommandVisitor visitor) ### Description Accept a visitor. When a `DeleteCommand` accepts a visitor, it calls its `visitDeleteCommand` method. ### Parameters * **visitor** (CommandVisitor) - The visitor to be accepted. ### Implements `accept` in class `EditCommand` ``` -------------------------------- ### Environment Variable StringLookup Example Source: https://commons.apache.org/proper/commons-text/jacoco/org.apache.commons.text.lookup/StringLookupFactory.java.html Demonstrates looking up environment variables using the StringLookupFactory. This can be used directly or within a StringSubstitutor. ```java StringLookupFactory.INSTANCE.environmentVariableStringLookup().lookup("USER"); ``` ```java StringSubstitutor.createInterpolator().replace("... ${env:USER} ..."); ``` -------------------------------- ### Extract Substring from Start Index Source: https://commons.apache.org/proper/commons-text/xref/org/apache/commons/text/StrBuilder.html Extracts a portion of the StrBuilder as a String starting from the specified index to the end of the builder. ```Java public String substring(final int start) { return substring(start, size); } ``` -------------------------------- ### build Source: https://commons.apache.org/proper/commons-text/javadocs/api-release/org/apache/commons/text/TextStringBuilder.html Implement the Builder interface. Returns the builder as a String. ```APIDOC ## build ### Description Implement the `Builder` interface. ### Method ```java public String build() ``` ### Returns The builder as a String ### See Also `toString()` ``` -------------------------------- ### substring(int start) Source: https://commons.apache.org/proper/commons-text/jacoco/org.apache.commons.text/TextStringBuilder.java.html Extracts a portion of this string builder as a string, starting from the specified index to the end of the builder. ```APIDOC ## substring(int start) ### Description Extracts a portion of this string builder as a string, starting from the specified index to the end of the builder. ### Method public String substring(final int start) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **substring** (String) - The new string representing the extracted portion. ### Response Example None ### Error Handling - **IndexOutOfBoundsException**: If the start index is invalid. ``` -------------------------------- ### URL StringLookup Example Source: https://commons.apache.org/proper/commons-text/apidocs/org/apache/commons/text/lookup/StringLookupFactory.html Demonstrates how to use the URLStringLookup to fetch content from a given URL. This lookup is typically used with a StringSubstitutor for variable interpolation. ```java StringLookupFactory.INSTANCE.urlStringLookup().lookup("UTF-8:https://www.apache.org"); ``` -------------------------------- ### Check if String Starts With Source: https://commons.apache.org/proper/commons-text/cpd.html Checks if the current buffer starts with the given string. Handles null and empty strings. ```java public boolean startsWith(final String str) { if (str == null) { return false; } final int len = str.length(); if (len == 0) { return true; } if (len > size) { return false; } for (int i = 0; i < len; i++) { if (buffer[i] != str.charAt(i)) { return false; } } return true; } ``` -------------------------------- ### build() Source: https://commons.apache.org/proper/commons-text/apidocs/org/apache/commons/text/TextStringBuilder.html Deprecated. Use get() instead. Converts this instance to a String. ```APIDOC ## build() ### Description Deprecated. Use `get()` instead. Converts this instance to a String. ### Method Not specified (assumed to be a method call on a TextStringBuilder instance) ### Returns String - The string representation of the builder. ``` -------------------------------- ### substring(int start) Source: https://commons.apache.org/proper/commons-text/apidocs/org/apache/commons/text/StrBuilder.html Extracts a portion of this string builder as a string, starting from the specified index to the end. This method is deprecated. ```APIDOC ## substring(int start) ### Description Extracts a portion of this string builder as a string, starting from the specified index to the end. ### Method Not specified (likely a method call on a StrBuilder object) ### Parameters * **start** (int) - The starting index of the substring. ### Returns * **String** - The extracted substring. ### Deprecated This method is deprecated. ``` -------------------------------- ### Find First String Index from Start Index Source: https://commons.apache.org/proper/commons-text/jacoco/org.apache.commons.text/StrBuilder.java.html Searches for the first occurrence of a specified string within the StrBuilder, starting from a given index. Handles null input strings by returning -1. Invalid start indices are rounded to the nearest valid edge. ```Java public int indexOf(final String str, int startIndex) { startIndex = Math.max(0, startIndex); if (str == null || startIndex >= size) { return StringUtils.INDEX_NOT_FOUND; } final int strLen = str.length(); if (strLen == 1) { return indexOf(str.charAt(0), startIndex); } if (strLen == 0) { return startIndex; } if (strLen > size) { return StringUtils.INDEX_NOT_FOUND; } final char[] thisBuf = buffer; final int searchLen = size - strLen + 1; for (int i = startIndex; i < searchLen; i++) { boolean found = true; for (int j = 0; j < strLen && found; j++) { found = str.charAt(j) == thisBuf[i + j]; } if (found) { return i; } } return StringUtils.INDEX_NOT_FOUND; } ``` -------------------------------- ### build Source: https://commons.apache.org/proper/commons-text/javadocs/api-release/org/apache/commons/text/StrBuilder.html Implement the Builder interface. ```APIDOC ## build ### Description Implement the Builder interface. ### Method public String build() ### Specified by build in interface Builder ### Returns The builder as a String ``` -------------------------------- ### Properties StringLookup Example Source: https://commons.apache.org/proper/commons-text/apidocs/src-html/org/apache/commons/text/lookup/StringLookupFactory.html Demonstrates how to use the propertiesStringLookup to retrieve a value from a properties file. The key format is 'propertiesFileName:keyName'. ```java StringLookupFactory.INSTANCE.propertiesStringLookup(Paths.get("")).lookup("com/domain/document.properties::MyKey"); ``` -------------------------------- ### validateRange Source: https://commons.apache.org/proper/commons-text/apidocs/src-html/org/apache/commons/text/TextStringBuilder.html Validates parameters defining a range within the builder. Ensures start index is non-negative and adjusts end index if it exceeds the builder's size. Throws StringIndexOutOfBoundsException if the start index is negative or if the start index is greater than the adjusted end index. ```APIDOC ## validateRange(int startIndex, int endIndex) ### Description Validates parameters defining a range of the builder. ### Method Signature protected int validateRange(final int startIndex, int endIndex) ### Parameters * **startIndex** (int) - The start index, inclusive, must be valid. * **endIndex** (int) - The end index, exclusive, must be valid except that if too large it is treated as end of string. ### Returns * **int** - A valid end index. ### Throws * **StringIndexOutOfBoundsException** - If the index is invalid (startIndex < 0 or startIndex > endIndex after adjustment). ``` -------------------------------- ### toCamelCase Example Usage Source: https://commons.apache.org/proper/commons-text/apidocs/org/apache/commons/text/CaseUtils.html Demonstrates various scenarios of converting strings to camelCase using different inputs, capitalization flags, and delimiters. Handles null strings, empty strings, and strings with only delimiters. ```java CaseUtils.toCamelCase(null, false) = null CaseUtils.toCamelCase("", false, *) = "" CaseUtils.toCamelCase(*, false, null) = * CaseUtils.toCamelCase(*, true, new char[0]) = * CaseUtils.toCamelCase("To.Camel.Case", false, new char[]{'.'}) = "toCamelCase" CaseUtils.toCamelCase(" to @ Camel case", true, new char[]{'@'}) = "ToCamelCase" CaseUtils.toCamelCase(" @to @ Camel case", false, new char[]{'@'}) = "toCamelCase" CaseUtils.toCamelCase(" @", false, new char[]{'@'}) = "" ``` -------------------------------- ### Get StrBuilder as Writer Source: https://commons.apache.org/proper/commons-text/xref/org/apache/commons/text/StrBuilder.html Gets this builder as a Writer that can be written to. This allows populating the builder using any standard method that takes a Writer. ```java public Writer asWriter() { return new StrBuilderWriter(); } ``` -------------------------------- ### Java Platform StringLookup Example Source: https://commons.apache.org/proper/commons-text/apidocs/src-html/org/apache/commons/text/lookup/StringLookupFactory.html Demonstrates how to use the JavaPlatformStringLookup to retrieve information about the Java environment. This lookup can be accessed directly or via a StringSubstitutor. ```java StringLookupFactory.INSTANCE.javaPlatformStringLookup().lookup("version"); ``` ```java StringSubstitutor.createInterpolator().replace("... ${java:version} ...")); ``` -------------------------------- ### Get Previous Token (Iterator) Source: https://commons.apache.org/proper/commons-text/jacoco/org.apache.commons.text/StringTokenizer.java.html Gets the token previous to the last returned token. Throws NoSuchElementException if no previous token exists. ```Java @Override public String previous() { if (hasPrevious()) { return tokens[--tokenPos]; } throw new NoSuchElementException(); } ``` -------------------------------- ### Builder Example with Accumulate and SelectFrom Source: https://commons.apache.org/proper/commons-text/apidocs/src-html/org/apache/commons/text/RandomStringGenerator.html Demonstrates how to configure a RandomStringGenerator to accumulate characters and select from a specific set, including punctuation. This is useful for generating strings with a diverse character pool. ```java RandomStringGenerator gen = RandomStringGenerator.builder() .setAccumulate(true) .withinRange(new char[][] { { 'a', 'z' }, { 'A', 'Z' }, { '0', '9' } }) .selectFrom('!', "\"", '#', '$', '&', "'", '(', ')', ',', '.', ':', ';', '?', '@', '[', '\\', ']', '^', '_', '`', '{', '|', '}', '~') // punctuation // additional builder calls as needed .build(); ``` -------------------------------- ### Get Next Token (Nullable) Source: https://commons.apache.org/proper/commons-text/jacoco/org.apache.commons.text/StringTokenizer.java.html Gets the next token from the String. Returns null rather than throwing NoSuchElementException when no tokens remain. ```Java public String nextToken() { if (hasNext()) { return tokens[tokenPos++]; } return null; } ``` -------------------------------- ### XML Decoder StringLookup Example Source: https://commons.apache.org/proper/commons-text/apidocs/org/apache/commons/text/lookup/StringLookupFactory.html Illustrates using the XmlDecoderStringLookup to decode XML-encoded strings. The example shows direct usage of the lookup. ```java StringLookupFactory.INSTANCE.xmlDecoderStringLookup().lookup("<element>"); ``` -------------------------------- ### Constant String Lookup Example Source: https://commons.apache.org/proper/commons-text/apidocs/org/apache/commons/text/lookup/StringLookupFactory.html Demonstrates looking up a fully-qualified static final value using the ConstantStringLookup from StringLookupFactory. ```java StringLookupFactory.INSTANCE.constantStringLookup().lookup("java.awt.event.KeyEvent.VK_ESCAPE"); ``` ```java StringSubstitutor.createInterpolator().replace("... ${const:java.awt.event.KeyEvent.VK_ESCAPE} ...")); ``` -------------------------------- ### Java - CaseUtils Constructor Usage Source: https://commons.apache.org/proper/commons-text/javadocs/api-release/org/apache/commons/text/CaseUtils.html Demonstrates the recommended way to use CaseUtils methods, emphasizing that instances should not be constructed. Instead, use static methods directly. ```java CaseUtils.toCamelCase("foo bar", true, new char[]{'-'}); ``` -------------------------------- ### get Source: https://commons.apache.org/proper/commons-text/xref/org/apache/commons/text/StrBuilder.html Converts this StrBuilder instance to a String. This method is an override of the standard 'get' method, providing a String representation of the builder's content. ```APIDOC ## get ### Description Converts this StrBuilder instance to a String. This method is an override of the standard 'get' method, providing a String representation of the builder's content. ### Method public String get() ### Parameters None ### Response #### Success Response (String) Returns the String representation of this StrBuilder. #### Response Example ``` "example string" ``` ``` -------------------------------- ### substring Source: https://commons.apache.org/proper/commons-text/apidocs/src-html/org/apache/commons/text/StrBuilder.html Extracts a portion of the string builder as a new `String` object. Overloaded versions allow specifying a start index only (to the end) or both start and end indices. ```APIDOC ## substring ### Description Extracts a portion of this string builder as a string. ### Method public String substring(int start) public String substring(int start, int end) ### Parameters #### Path Parameters - **start** (int) - The starting index, inclusive. - **end** (int) - The ending index, exclusive (for the two-argument version). ### Response #### Success Response - **return** (String) - The new string representing the extracted portion. ``` -------------------------------- ### get Source: https://commons.apache.org/proper/commons-text/apidocs/src-html/org/apache/commons/text/numbers/DoubleFormat.Builder.html Builds and returns a new double format function based on the current builder configuration. ```APIDOC ## get ### Description Builds and returns a new double format function based on the current builder configuration. This function can then be used to format double values. ### Method `get()` ### Returns * `DoubleFunction` - A function that takes a double and returns its formatted string representation. ``` -------------------------------- ### Base64 Encoder Example Source: https://commons.apache.org/proper/commons-text/apidocs/src-html/org/apache/commons/text/lookup/StringLookupFactory.html Demonstrates encoding a string to Base64 using the INSTANCE_BASE64_ENCODER. This is useful for interpolating Base64 encoded values. ```java StringLookupFactory.INSTANCE.base64EncoderStringLookup().lookup("HelloWorld!"); ``` ```java StringSubstitutor.createInterpolator().replace("... ${base64Encoder:HelloWorld!} ...")); ``` -------------------------------- ### Jaro-Winkler Distance Examples Source: https://commons.apache.org/proper/commons-text/apidocs/src-html/org/apache/commons/text/similarity/JaroWinklerDistance.html Illustrates various string comparisons using the Jaro-Winkler distance algorithm. These examples show the expected similarity scores for different input pairs. ```java distance.apply("hippo", "elephant") = 0.56 distance.apply("hippo", "zzzzzzzz") = 1.0 distance.apply("hello", "hallo") = 0.12 distance.apply("ABC Corporation", "ABC Corp") = 0.09 distance.apply("D N H Enterprises Inc", "D & H Enterprises, Inc.") = 0.05 distance.apply("My Gym Children's Fitness Center", "My Gym. Childrens Fitness") = 0.08 distance.apply("PENNSYLVANIA", "PENNCISYLVNIA") = 0.12 ``` -------------------------------- ### StringSubstitutor Instance Methods Source: https://commons.apache.org/proper/commons-text/apidocs/org/apache/commons/text/StringSubstitutor.html Documents the instance methods for StringSubstitutor, covering retrieval of configuration settings and performing string replacements. ```APIDOC ## Instance Methods ### `char getEscapeChar()` Returns the escape character. ### `StringLookup getStringLookup()` Gets the StringLookup that is used to lookup variables. ### `StringMatcher getValueDelimiterMatcher()` Gets the variable default value delimiter matcher currently in use. ### `StringMatcher getVariablePrefixMatcher()` Gets the variable prefix matcher currently in use. ### `StringMatcher getVariableSuffixMatcher()` Gets the variable suffix matcher currently in use. ### `boolean isDisableSubstitutionInValues()` Returns a flag whether substitution is disabled in variable values. If set to **true**, the values of variables can contain other variables will not be processed and substituted original variable is evaluated, e.g. ### `boolean isEnableSubstitutionInVariables()` Returns a flag whether substitution is done in variable names. ### `boolean isEnableUndefinedVariableException()` Returns a flag whether exception can be thrown upon undefined variable. ### `boolean isPreserveEscapes()` Returns the flag controlling whether escapes are preserved during substitution. ### `String replace(char[] source)` Replaces all the occurrences of variables with their matching values from the resolver using the given source array as a template. ### `String replace(char[] source, int offset, int length)` Replaces all the occurrences of variables with their matching values from the resolver using the given source array as a template. ### `String replace(CharSequence source)` Replaces all the occurrences of variables with their matching values from the resolver using the given source as a template. ### `String replace(CharSequence source, int offset, int length)` Replaces all the occurrences of variables with their matching values from the resolver using the given source as a template. ### `String replace(Object source)` Replaces all the occurrences of variables in the given source object with their matching values from the resolver. ``` -------------------------------- ### lastIndexOf(StrMatcher matcher, int startIndex) Source: https://commons.apache.org/proper/commons-text/apidocs/src-html/org/apache/commons/text/StrBuilder.html Finds the last index where a StrMatcher finds a match, starting the search from a given index. The start index is adjusted to be within the bounds of the builder. ```APIDOC ## lastIndexOf(StrMatcher matcher, int startIndex) ### Description Searches the string builder using the matcher to find the last match, starting the search from the given index. Matchers can be used to perform advanced searching behavior. ### Method `public int lastIndexOf(final StrMatcher matcher, int startIndex)` ### Parameters * `matcher` (StrMatcher) - The matcher to use for finding matches. If null, -1 is returned. * `startIndex` (int) - The index to start the search from. Invalid indices are rounded to the nearest valid edge. ### Returns The last index matched, or -1 if not found. ``` -------------------------------- ### Example of Substitution with Disabled Substitution in Values Source: https://commons.apache.org/proper/commons-text/apidocs/src-html/org/apache/commons/text/StrSubstitutor.html Demonstrates how disabling substitution in variable values prevents nested variable expansion. The example shows that when 'name' is resolved, the embedded '${surname}' is not further processed. ```Java Map valuesMap = new HashMap<>(); valuesMap.put("name", "Douglas ${surname}"); valuesMap.put("surname", "Crockford"); String templateString = "Hi ${name}"; StrSubstitutor sub = new StrSubstitutor(valuesMap); String resolvedString = sub.replace(templateString); ``` -------------------------------- ### InsertCommand.accept Method Source: https://commons.apache.org/proper/commons-text/apidocs/org/apache/commons/text/diff/InsertCommand.html Accepts a visitor and calls the appropriate visit method on it. For InsertCommand, it calls the `visitInsertCommand` method of the visitor. ```APIDOC ## accept Method ### Description Accepts a visitor. When an `InsertCommand` accepts a visitor, it calls its `visitInsertCommand` method. ### Method `void accept(CommandVisitor visitor)` ### Parameters #### Path Parameters - **visitor** (CommandVisitor) - Required - The visitor to be accepted. ``` -------------------------------- ### Find Character Index in StrBuilder Source: https://commons.apache.org/proper/commons-text/xref/org/apache/commons/text/StrBuilder.html Searches the string builder to find the first reference to the specified character, starting from a given index. Returns -1 if the character is not found or the start index is out of bounds. ```java public int indexOf(final char ch, int startIndex) { startIndex = Math.max(startIndex, 0); if (startIndex >= size) { return -1; } final char[] thisBuf = buffer; for (int i = startIndex; i < size; i++) { if (thisBuf[i] == ch) { return i; } } return -1; } ``` -------------------------------- ### Fenced StringSubstitutor with Properties Lookup Source: https://commons.apache.org/proper/commons-text/apidocs/src-html/org/apache/commons/text/lookup/StringLookupFactory.html Illustrates building a fenced StringSubstitutor that uses a Properties StringLookup. This example shows how to replace placeholders in a string, with path validation enforced by the fences. ```java // Make the fence the current directory final StringLookupFactory factory = StringLookupFactory.builder().setFences(Paths.get("")).get(); final StringSubstitutor stringSubstitutor = new StringSubstitutor(factory.interpolatorStringLookup()); stringSubstitutor.replace("... ${properties:com/domain/document.properties::MyKey} ..."); // throws IllegalArgumentException stringSubstitutor.replace("... ${properties:/rootdir/foo/document.properties::MyKey} ..."); ``` -------------------------------- ### Creating a Function StringLookup Source: https://commons.apache.org/proper/commons-text/jacoco/org.apache.commons.text.lookup/StringLookupFactory.java.html Demonstrates how to create a StringLookup that uses a provided function to resolve lookup keys. ```java public StringLookup functionStringLookup(final Function function) { return FunctionStringLookup.on(function); } ``` -------------------------------- ### Find Last Match with StringMatcher from Start Index Source: https://commons.apache.org/proper/commons-text/jacoco/org.apache.commons.text/TextStringBuilder.java.html Searches the string builder from a specified index using a StringMatcher to find the last match. Handles null matcher and invalid start indices. ```java public int lastIndexOf(final StringMatcher matcher, int startIndex) { startIndex = startIndex >= size ? size - 1 : startIndex; if (matcher == null || startIndex < 0) { return StringUtils.INDEX_NOT_FOUND; } final char[] buf = buffer; final int endIndex = startIndex + 1; for (int i = startIndex; i >= 0; i--) { if (matcher.isMatch(buf, i, 0, endIndex) > 0) { return i; } } return StringUtils.INDEX_NOT_FOUND; } ``` -------------------------------- ### Find Last Matcher Index from Index Source: https://commons.apache.org/proper/commons-text/xref/org/apache/commons/text/StrBuilder.html Searches the string builder using a StrMatcher to find the last match, starting the search from the given index. Handles null matchers and invalid start indices. ```java public int lastIndexOf(final StrMatcher matcher, int startIndex) { startIndex = startIndex >= size ? size - 1 : startIndex; if (matcher == null || startIndex < 0) { return -1; } final char[] buf = buffer; final int endIndex = startIndex + 1; for (int i = startIndex; i >= 0; i--) { if (matcher.isMatch(buf, i, 0, endIndex) > 0) { return i; } } return -1; } ``` -------------------------------- ### Configuration Methods Source: https://commons.apache.org/proper/commons-text/apidocs/org/apache/commons/text/StringSubstitutor.html Methods for configuring the StringSubstitutor's behavior. ```APIDOC ## setDisableSubstitutionInValues(boolean disableSubstitutionInValues) ### Description Sets a flag whether substitution is done in variable values (recursive). ### Method StringSubstitutor ### Parameters * **disableSubstitutionInValues** (boolean) - If true, substitution in values is disabled. ### Response * **StringSubstitutor** - The StringSubstitutor instance for chaining. ## setEnableSubstitutionInVariables(boolean enableSubstitutionInVariables) ### Description Sets a flag whether substitution is done in variable names. ### Method StringSubstitutor ### Parameters * **enableSubstitutionInVariables** (boolean) - If true, substitution in variable names is enabled. ### Response * **StringSubstitutor** - The StringSubstitutor instance for chaining. ## setEnableUndefinedVariableException(boolean failOnUndefinedVariable) ### Description Sets a flag whether an exception should be thrown if any variable is undefined. ### Method StringSubstitutor ### Parameters * **failOnUndefinedVariable** (boolean) - If true, an exception is thrown for undefined variables. ### Response * **StringSubstitutor** - The StringSubstitutor instance for chaining. ## setEscapeChar(char escapeChar) ### Description Sets the escape character. ### Method StringSubstitutor ### Parameters * **escapeChar** (char) - The character to use for escaping. ### Response * **StringSubstitutor** - The StringSubstitutor instance for chaining. ## setPreserveEscapes(boolean preserveEscapes) ### Description Sets a flag controlling whether escapes are preserved during substitution. ### Method StringSubstitutor ### Parameters * **preserveEscapes** (boolean) - If true, escapes are preserved. ### Response * **StringSubstitutor** - The StringSubstitutor instance for chaining. ## setValueDelimiter(char valueDelimiter) ### Description Sets the variable default value delimiter to use. ### Method StringSubstitutor ### Parameters * **valueDelimiter** (char) - The character to use as the value delimiter. ### Response * **StringSubstitutor** - The StringSubstitutor instance for chaining. ## setValueDelimiter(String valueDelimiter) ### Description Sets the variable default value delimiter to use. ### Method StringSubstitutor ### Parameters * **valueDelimiter** (String) - The string to use as the value delimiter. ### Response * **StringSubstitutor** - The StringSubstitutor instance for chaining. ## setValueDelimiterMatcher(StringMatcher valueDelimiterMatcher) ### Description Sets the variable default value delimiter matcher to use. ### Method StringSubstitutor ### Parameters * **valueDelimiterMatcher** (StringMatcher) - The StringMatcher to use for value delimiters. ### Response * **StringSubstitutor** - The StringSubstitutor instance for chaining. ## setVariablePrefix(char prefix) ### Description Sets the variable prefix to use. ### Method StringSubstitutor ### Parameters * **prefix** (char) - The character to use as the variable prefix. ### Response * **StringSubstitutor** - The StringSubstitutor instance for chaining. ## setVariablePrefix(String prefix) ### Description Sets the variable prefix to use. ### Method StringSubstitutor ### Parameters * **prefix** (String) - The string to use as the variable prefix. ### Response * **StringSubstitutor** - The StringSubstitutor instance for chaining. ## setVariablePrefixMatcher(StringMatcher prefixMatcher) ### Description Sets the variable prefix matcher currently in use. ### Method StringSubstitutor ### Parameters * **prefixMatcher** (StringMatcher) - The StringMatcher to use for variable prefixes. ### Response * **StringSubstitutor** - The StringSubstitutor instance for chaining. ## setVariableResolver(StringLookup variableResolver) ### Description Sets the VariableResolver that is used to lookup variables. ### Method StringSubstitutor ### Parameters * **variableResolver** (StringLookup) - The StringLookup implementation to resolve variables. ### Response * **StringSubstitutor** - The StringSubstitutor instance for chaining. ## setVariableSuffix(char suffix) ### Description Sets the variable suffix to use. ### Method StringSubstitutor ### Parameters * **suffix** (char) - The character to use as the variable suffix. ### Response * **StringSubstitutor** - The StringSubstitutor instance for chaining. ## setVariableSuffix(String suffix) ### Description Sets the variable suffix to use. ### Method StringSubstitutor ### Parameters * **suffix** (String) - The string to use as the variable suffix. ### Response * **StringSubstitutor** - The StringSubstitutor instance for chaining. ## setVariableSuffixMatcher(StringMatcher suffixMatcher) ### Description Sets the variable suffix matcher currently in use. ### Method StringSubstitutor ### Parameters * **suffixMatcher** (StringMatcher) - The StringMatcher to use for variable suffixes. ### Response * **StringSubstitutor** - The StringSubstitutor instance for chaining. ``` -------------------------------- ### lastIndexOf(char ch, int startIndex) Source: https://commons.apache.org/proper/commons-text/jacoco/org.apache.commons.text/TextStringBuilder.java.html Searches the string builder to find the last reference to the specified character, starting the search from the given index. Invalid start indices are rounded to the nearest edge. ```APIDOC ## lastIndexOf(char ch, int startIndex) ### Description Searches the string builder to find the last reference to the specified character, starting the search from the given index. Invalid start indices are rounded to the nearest edge. ### Method public int lastIndexOf(final char ch, int startIndex) ### Parameters #### Path Parameters - **ch** (char) - The character to search for. - **startIndex** (int) - The index to start the search from. Invalid indices are rounded to the edge of the string builder. ### Response #### Success Response (int) - Returns the last index of the character, or -1 if the character is not found. ``` -------------------------------- ### Script StringLookup Example Source: https://commons.apache.org/proper/commons-text/javadocs/api-release/org/apache/commons/text/lookup/StringLookupFactory.html Illustrates using ScriptStringLookup via StringLookupFactory to execute scripts based on the 'ScriptEngineName:Script' format. ```java StringLookupFactory.INSTANCE.scriptStringLookup().lookup("javascript:3 + 4"); ``` ```java StringSubstitutor.createInterpolator().replace("... ${javascript:3 + 4} ...")); ``` -------------------------------- ### SimilarityInput.length() Source: https://commons.apache.org/proper/commons-text/apidocs/org/apache/commons/text/similarity/SimilarityInput.html Gets the length of the input. ```APIDOC ## Method: length ### Description Gets the length of the input. ### Method Signature `int length()` ### Returns * `int` - the length of the input. ```