Top Description Inners Fields Constructors Methods
org.codehaus.groovy.runtime

public Class StringGroovyMethods

extends DefaultGroovyMethodsSupport
Class Inheritance
Imports
groovy.lang.Closure, .EmptyRange, .GString, .GroovyRuntimeException, .IntRange, .Range, groovy.transform.stc.ClosureParams, .FromString, .PickFirstResolver, org.apache.groovy.io.StringBuilderWriter, org.apache.groovy.lang.annotation.Incubating, org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation, org.codehaus.groovy.util.CharSequenceReader, java.io.BufferedWriter, .File, .IOException, .Writer, java.lang.invoke.MethodHandle, .MethodHandles, .MethodType, java.math.BigDecimal, .BigInteger, java.util.ArrayList, .Arrays, .Collection, .HashSet, .Iterator, .List, .Map, .NoSuchElementException, .Optional, .Set, .StringTokenizer, java.util.function.Function, java.util.regex.Matcher, .Pattern

This class defines new groovy methods which appear on String-related JDK classes (String, CharSequence, Matcher) inside the Groovy environment. Static methods are used with the first parameter being the destination class, e.g. public static String reverse(String self) provides a reverse() method for String.

Note

While this class contains many 'public' static methods, it is primarily regarded as an internal class (its internal package name suggests this also). We value backwards compatibility of these methods when used within Groovy but value less backwards compatibility at the Java method call level. I.e. future versions of Groovy may remove or move a method call in this file but would normally aim to keep the method available from within Groovy.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
private static class
private static class
private static class

Field Summary

Modifier and TypeField and Description
pack-priv static String

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static StringBuilder

Returns:

the StringBuilder
append
(final StringBuilder
a StringBuilder
sb
,
GStringImpl
a GStringImpl
gs
)

Append the GString to the StringBuilder using a more efficient approach than Java's default approach for a CharSequence.

public static boolean

Returns:

the boolean value
asBoolean
(final CharSequence
the character sequence
chars
)

Coerces a CharSequence to a boolean value.

public static boolean

Returns:

the boolean value
asBoolean
(final Matcher
the matcher
matcher
)

Coerces a Matcher instance to a boolean value.

public static <T> T

Returns:

the converted object
asType
(final CharSequence
a CharSequence
self
,
final Class<T>
the desired class
c
)

Provides a method to perform custom 'dynamic' type conversion to the given class using the as operator.

public static <T> T

Returns:

the converted object
asType
(final GString
a GString
self
,
final Class<T>
the desired class
c
)

Converts the GString to a File, or delegates to the default org.codehaus.groovy.runtime.DefaultGroovyMethods#asType(Object, Class).

public static <T> T

Returns:

the converted object
asType
(final String
a String
self
,
final Class<T>
the desired class
c
)

Provides a method to perform custom 'dynamic' type conversion to the given class using the as operator.

public static Pattern

Returns:

the regular expression pattern
bitwiseNegate
(final CharSequence
a String to convert into a regular expression
self
)

Turns a CharSequence into a regular expression Pattern.

public static String

Returns:

A String containing the capitalized toString() of the CharSequence
capitalize
(final CharSequence
The CharSequence to capitalize
self
)

Convenience method to capitalize the first letter of a CharSequence (typically the first letter of a word).

public static String

Returns:

the centered toString() of this CharSequence with padded characters around it
center
(final CharSequence
a CharSequence object
self
,
final Number
the total minimum number of characters of the result
numberOfChars
)

Pads a CharSequence to a minimum length specified by numberOfChars by adding the space character around it as many times as needed so that it remains centered.

public static String

Returns:

the centered toString() of this CharSequence with padded characters around it
center
(final CharSequence
a CharSequence object
self
,
final Number
the total minimum number of characters of the resulting CharSequence
numberOfChars
,
final CharSequence
the characters used for padding
padding
)

Pad a CharSequence to a minimum length specified by numberOfChars, appending the supplied padding CharSequence around the original as many times as needed keeping it centered.

public static String

Returns:

A new string in which all characters that require escaping have been replaced with the corresponding replacements as determined by the transform Closure.
collectReplacements
(final String
the original String
self
,
final Closure<String> transform)

Iterates through this String a character at a time collecting either the original character or a transformed replacement String.

public static String

Returns:

A new string in which all characters that require escaping have been replaced with the corresponding replacements as determined by the transform function.
collectReplacements
(final String
the original String
self
,
final List<Function<Character, Optional<String>>>
one or more transforms which potentially convert a single character to a transformed string
transforms
)

Iterates through this String a character at a time collecting either the original character or a transformed replacement String.

public static boolean

Returns:

true if this CharSequence contains the given text
contains
(final CharSequence
a CharSequence
self
,
final CharSequence
the CharSequence to look for
text
)

Provides an implementation of contains() like java.util.Collection#contains(Object) to make CharSequences more polymorphic.

public static boolean

Returns:

true if the character sequence represented by the argument exists in this CharSequence ignoring the case considerations. false otherwise. Returns false if the argument is null
containsIgnoreCase
(final CharSequence
the original CharSequence
self
,
final CharSequence
CharSequence being checked against this
searchString
)

Checks whether this CharSequence contains the searchString ignoring the caseConsiderations.

public static int

Returns:

the number of occurrences of the given CharSequence inside this CharSequence
count
(final CharSequence
a CharSequence
self
,
final CharSequence
a sub CharSequence
text
)

Counts the number of occurrences of a sub CharSequence.

public static String

Returns:

the denormalized toString() of this CharSequence
denormalize
(final CharSequence
a CharSequence object
self
)

Return a CharSequence with lines (separated by LF, CR/LF, or CR) terminated by the platform specific line separator.

public static CharSequence

Returns:

a CharSequence consisting of all characters except the first num ones, or else an empty String, if this CharSequence has less than num characters.
drop
(final CharSequence
the original CharSequence
self
,
final int
the number of characters to drop from this String
num
)

Drops the given number of chars from the head of this CharSequence if they are available.

public static String

Returns:

a String consisting of all characters except the first num ones, or else an empty String, if the toString() of this GString has less than num characters.
drop
(final GString
the original GString
self
,
final int
the number of characters to drop from this GString
num
)

A GString variant of the equivalent CharSequence method.

public static String

Returns:

a String consisting of all characters except the first num ones, or else an empty String, if the String has less than num characters.
drop
(final String
the original String
self
,
final int
the number of characters to drop from this String
num
)

A String variant of the equivalent CharSequence method.

public static CharSequence

Returns:

CharSequence after removing the right num chars and empty of the num is greater than the length of the CharSequence
dropRight
(final CharSequence
the original CharSequence
self
,
final int
number of characters
num
)

Returns new CharSequence after removing the right num chars.

public static String

Returns:

String after removing the right num chars and empty of the num is greater than the length of the CharSequence
dropRight
(final String
the original CharSequence
self
,
final int
number of characters
num
)

A String variant of the equivalent CharSequence method dropRight(CharSequence, int).

public static String

Returns:

String after removing the right num chars and empty of the num is greater than the length of the CharSequence
dropRight
(final GString
the original CharSequence
self
,
final int
number of characters
num
)

A GString variant of the equivalent CharSequence method dropRight(CharSequence, int).

public static String

Returns:

the shortest suffix of the given CharSequence such that the given closure condition evaluates to true for each element dropped from the front of the CharSequence
dropWhile
(final CharSequence
the original CharSequence
self
,
final Closure<V>
the closure that while continuously evaluating to true will cause us to drop elements from the front of the original CharSequence
condition
)

Creates a suffix of the given CharSequence by dropping as many characters as possible from the front of the original CharSequence such that calling the given closure condition evaluates to true when passed each of the dropped characters.

public static String

Returns:

the shortest suffix of the given GString such that the given closure condition evaluates to true for each element dropped from the front of the CharSequence
dropWhile
(final GString
the original GString
self
,
final Closure<V>
the closure that while continuously evaluating to true will cause us to drop elements from the front of the original GString
condition
)

A GString variant of the equivalent CharSequence method.

public static CharSequence
dropWhile$$bridge(final CharSequence self, final Closure<V> condition)

Deprecated
public static <T> T

Returns:

the last value returned by the closure
eachLine
(final CharSequence
a CharSequence
self
,
final Closure<T>
a closure
closure
)

Iterates through this CharSequence line by line.

public static <T> T

Returns:

the last value returned by the closure
eachLine
(final CharSequence
a CharSequence
self
,
final int
the line number value used for the first line (default is 1, set to 0 to start counting from 0)
firstLine
,
final Closure<T>
a closure (arg 1 is line, optional arg 2 is line number)
closure
)

Iterates through this CharSequence line by line.

public static <T extends CharSequence> T

Returns:

the source CharSequence
eachMatch
(final T
the source CharSequence
self
,
final CharSequence
a Regex CharSequence
regex
,
final Closure<V>
a closure with one parameter or as many parameters as groups
closure
)

Processes each regex group matched substring of the given CharSequence.

public static <T extends CharSequence> T

Returns:

the source CharSequence
eachMatch
(final T
the source CharSequence
self
,
final Pattern
a regex Pattern
pattern
,
final Closure<V>
a closure with one parameter or as many parameters as groups
closure
)

Processes each regex group matched substring of the given pattern.

public static String

Returns:

the source string
eachMatch
(final String
the source string
self
,
final Pattern
a regex Pattern
pattern
,
final Closure<V>
a closure with one parameter or as many parameters as groups
closure
)

Processes each regex group matched substring of the given pattern.

public static String

Returns:

the source string
eachMatch
(final String
the source string
self
,
final String
a Regex string
regex
,
final Closure<V>
a closure with one parameter or as many parameters as groups
closure
)

Process each regex group matched substring of the given string.

public static boolean

Returns:

true if this CharSequence ends with any specified suffixes
endsWithAny
(final CharSequence self, final CharSequence...
the suffixes.
suffixes
)

Tests if this CharSequence ends with any specified suffixes.

public static boolean

Returns:

true if the character sequence represented by the argument is a suffix of this CharSequence ignoring the case considerations. false otherwise. Returns false if the argument is null
endsWithIgnoreCase
(final CharSequence
the original CharSequence
self
,
final CharSequence
CharSequence bring checked against this
searchString
)

Checks whether this CharSequence ends with the searchString ignoring the case considerations.

public static String

Returns:

The expanded toString() of this CharSequence
expand
(final CharSequence
A CharSequence to expand
self
)

Expands all tabs into spaces with tabStops of size 8.

public static String

Returns:

The expanded toString() of this CharSequence
expand
(final CharSequence
A CharSequence to expand
self
,
final int
The number of spaces a tab represents
tabStop
)

Expands all tabs into spaces.

public static String

Returns:

The expanded toString() of this CharSequence
expandLine
(final CharSequence
A line to expand
self
,
final int
The number of spaces a tab represents
tabStop
)

Expands all tabs into spaces.

public static String

Returns:

a String containing the matched portion, or null if the regex doesn't match
find
(final CharSequence
a CharSequence
self
,
final CharSequence
the capturing regex
regex
)

Finds the first occurrence of a regular expression String within a String.

public static String

Returns:

a String containing the result of calling the closure (calling toString() if needed), or null if the regex pattern doesn't match
find
(final CharSequence
a CharSequence
self
,
final CharSequence
the capturing regex CharSequence
regex
,
final Closure<V>
the closure that will be passed the full match, plus each of the capturing groups (if any)
closure
)

Returns the result of calling a closure with the first occurrence of a regular expression found within a CharSequence.

public static String

Returns:

a String containing the matched portion, or null if the regex pattern doesn't match
find
(final CharSequence
a CharSequence
self
,
final Pattern
the compiled regex Pattern
pattern
)

Finds the first occurrence of a compiled regular expression Pattern within a String.

public static String

Returns:

a String containing the result of calling the closure (calling toString() if needed), or null if the regex pattern doesn't match
find
(final CharSequence
a CharSequence
self
,
final Pattern
the compiled regex Pattern
pattern
,
final Closure<V>
the closure that will be passed the full match, plus each of the capturing groups (if any)
closure
)

Returns the result of calling a closure with the first occurrence of a compiled regular expression found within a String.

public static List<String>

Returns:

a List containing all full matches of the regex within the CharSequence, an empty list will be returned if there are no matches
findAll
(final CharSequence
a CharSequence
self
,
final CharSequence
the capturing regex CharSequence
regex
)

Returns a (possibly empty) list of all occurrences of a regular expression (provided as a CharSequence) found within a CharSequence.

public static <T> List<T>

Returns:

a List containing all results from calling the closure with each full match (and potentially capturing groups) of the regex within the CharSequence, an empty list will be returned if there are no matches
findAll
(final CharSequence
a CharSequence
self
,
final CharSequence
the capturing regex CharSequence
regex
,
final Closure<T>
will be passed the full match plus each of the capturing groups (if any)
closure
)

Finds all occurrences of a regular expression string within a CharSequence.

public static List<String>

Returns:

a List containing all full matches of the Pattern within the CharSequence, an empty list will be returned if there are no matches
findAll
(final CharSequence
a CharSequence
self
,
final Pattern
the compiled regex Pattern
pattern
)

Returns a (possibly empty) list of all occurrences of a regular expression (in Pattern format) found within a CharSequence.

public static <T> List<T>

Returns:

a List containing all results from calling the closure with each full match (and potentially capturing groups) of the regex pattern within the CharSequence, an empty list will be returned if there are no matches
findAll
(final CharSequence
a CharSequence
self
,
final Pattern
the compiled regex Pattern
pattern
,
final Closure<T>
will be passed the full match plus each of the capturing groups (if any)
closure
)

Finds all occurrences of a compiled regular expression Pattern within a CharSequence.

private static int
findMinimumLeadingSpaces(final String line, final int count)

public static String

Returns:

a String consisting of the characters at the given indices
getAt
(final CharSequence
a CharSequence
self
,
final Collection<E>
a Collection of indices
indices
)

Selects a List of characters from a CharSequence using a Collection to identify the indices to be selected.

public static String

Returns:

the empty String
getAt
(final CharSequence
a CharSequence
self
,
final EmptyRange<T extends Comparable<T>>
an EmptyRange
range
)

Supports the range subscript operator for CharSequence or StringBuffer with EmptyRange

public static CharSequence

Returns:

the Character at the given index
getAt
(final CharSequence
a CharSequence
self
,
int
the index of the Character to get
index
)

Supports the subscript operator for CharSequence.

public static String

Returns:

the Character at the given index
getAt
(final GString
a GString
self
,
final int
the index of the Character to get
index
)

Supports the subscript operator for GString.

public static CharSequence

Returns:

the subsequence CharSequence
getAt
(final CharSequence
a CharSequence
self
,
final IntRange
an IntRange
range
)

Supports the range subscript operator for CharSequence with IntRange.

public static String

Returns:

the String of characters corresponding to the provided range
getAt
(final GString
a GString
self
,
final IntRange
an IntRange
range
)

Supports the range subscript operator for GString with IntRange.

public static CharSequence

Returns:

the subsequence CharSequence
getAt
(final CharSequence
a CharSequence
self
,
final Range<T extends Comparable<T>>
a Range
range
)

Supports the range subscript operator for CharSequence.

public static String

Returns:

the String of characters corresponding to the provided range
getAt
(final GString
a GString
self
,
final Range<T extends Comparable<T>>
a Range
range
)

Supports the range subscript operator for GString.

public static List<E>

Returns:

a String of the values at the given indices
getAt
(final Matcher
a Matcher
self
,
Collection<E>
a Collection of indices
indices
)

Selects a List of values from a Matcher using a Collection to identify the indices to be selected.

public static Object

Returns:

object a matched String if no groups matched, list of matched groups otherwise.
getAt
(final Matcher
a Matcher
self
,
int
an index
index
)

Supports the subscript operator, e.g. matcher[index], for a Matcher.

public static String

Returns:

the Character at the given index
getAt
(final String
a String
self
,
int
the index of the Character to get
index
)

Supports the subscript operator for String.

public static String

Returns:

the resulting String
getAt
(final String
a String
self
,
final IntRange
an IntRange
range
)

Supports the range subscript operator for String with IntRange.

public static String

Returns:

a substring corresponding to the Range
getAt
(final String
a String
self
,
final Range<T extends Comparable<T>>
a Range
range
)

Supports the range subscript operator for String.

public static char[]

Returns:

an array of characters
getChars
(final CharSequence
a CharSequence
self
)

Converts the given CharSequence into an array of characters.

public static int

Returns:

int the number of Strings matched to the given matcher.
getCount
(final Matcher
a Matcher
self
)

Finds the number of Strings matched to the given Matcher.

private static List<String>
getGroups(final Matcher matcher)

private static String
getPadding(final CharSequence padding, final int length)

private static String

Returns:

replacement correspond replacement for a match
getReplacement
(final Matcher
the matcher object used for matching
matcher
,
final Closure<?>
specified with replaceAll() to get replacement
closure
)

Gets a replacement corresponding to the matched pattern for org.codehaus.groovy.runtime.StringGroovyMethods#replaceAll(CharSequence, Pattern, Closure).

private static int
guessCapacity(final int capacity, final Map<CharSequence, CharSequence> replacements)

Crude heuristic for setting the created StringBuilder capacity if not supplied: If at least one replacement text is bigger than the original text use a capacity 50% larger than the original; otherwise, use the original size.

public static boolean

Returns:

boolean true if matcher contains at least one group.
hasGroup
(final Matcher
a Matcher
self
)

Checks whether a Matcher contains a group or not.

public static boolean

Returns:

true If all characters are whitespace characters
isAllWhitespace
(final CharSequence
The CharSequence to check the characters in
self
)

Returns true if a CharSequence only contains whitespace characters.

public static Boolean

Returns:

true if the value represented by left is equal to or bigger than the value represented by right
isAtLeast
(final String
a String representing a number
left
,
final String
a String representing a number
right
)

Compares a String representing a number to another.

public static boolean

Returns:

true if the CharSequence can be parsed
isBigDecimal
(final CharSequence
a CharSequence
self
)

Determines if a CharSequence can be parsed as a BigDecimal.

public static boolean

Returns:

true if the CharSequence can be parsed
isBigInteger
(final CharSequence
a CharSequence
self
)

Determines if a CharSequence can be parsed as a BigInteger.

public static boolean

Returns:

true if this CharSequence is blank
isBlank
(final CharSequence self)

Tests if this CharSequence is blank.

public static boolean

Returns:

true if the switchValue's toString() equals the caseValue
isCase
(final CharSequence
the case value
caseValue
,
final Object
the switch value
switchValue
)

'Case' implementation for a CharSequence, which uses equals between the toString() of the caseValue and the switchValue.

public static boolean

Returns:

true if the switchValue is deemed to match the caseValue
isCase
(final Pattern
the case value
caseValue
,
final Object
the switch value
switchValue
)

'Case' implementation for the java.util.regex.Pattern class, which allows testing a String against a number of regular expressions.

public static boolean

Returns:

true if the CharSequence can be parsed
isDouble
(final CharSequence
a CharSequence
self
)

Determines if a CharSequence can be parsed as a Double.

public static boolean

Returns:

true if the CharSequence can be parsed
isFloat
(final CharSequence
a CharSequence
self
)

Determines if a CharSequence can be parsed as a Float.

public static boolean

Returns:

true if the CharSequence can be parsed
isInteger
(final CharSequence
a CharSequence
self
)

Determines if a CharSequence can be parsed as an Integer.

public static boolean

Returns:

true if the CharSequence can be parsed
isLong
(final CharSequence
a CharSequence
self
)

Determines if a CharSequence can be parsed as a Long.

public static boolean

Returns:

true if the CharSequence can be parsed
isNumber
(final CharSequence
a CharSequence
self
)

Determines if a CharSequence can be parsed as a Number.

public static Iterator<E>

Returns:

an Iterator for a Matcher
iterator
(final Matcher
a Matcher object
self
)

Returns an java.util.Iterator which traverses each match.

public static StringBuilder

Returns:

a StringBuilder built from this CharSequence
leftShift
(final CharSequence
a CharSequence
self
,
final Object
an Object
value
)

Overloads the left shift operator to provide an easy way to append multiple objects as string representations to a CharSequence.

public static StringBuffer

Returns:

a StringBuffer built from this string
leftShift
(final String
a String
self
,
final Object
an Object
value
)

Overloads the left shift operator to provide an easy way to append multiple objects as string representations to a String.

public static StringBuffer

Returns:

the StringBuffer on which this operation was invoked
leftShift
(final StringBuffer
a StringBuffer
self
,
final Object
a value to append
value
)

Overloads the left shift operator to provide an easy way to append multiple objects as string representations to a StringBuffer.

public static StringBuilder

Returns:

the original StringBuilder
leftShift
(final StringBuilder
a StringBuilder
self
,
final Object
an Object
value
)

Overloads the left shift operator to provide syntactic sugar for appending to a StringBuilder.

public static boolean

Returns:

true if the CharSequence matches
matches
(final CharSequence
the CharSequence that is to be matched
self
,
final Pattern
the regex Pattern to which the string of interest is to be matched
pattern
)

Determines if a CharSequence matches the given regular expression.

public static boolean

Returns:

true if more input to the String could make the matcher match the associated pattern, false otherwise.
matchesPartially
(final Matcher
the Matcher
self
)

Given a matcher that matches a string against a pattern, returns true when the string matches the pattern or if a longer string, could match the pattern.

public static String

Returns:

a String containing the original minus the part to be removed
minus
(final CharSequence
a CharSequence
self
,
final Object
an object representing the part to remove
target
)

Removes a part of a CharSequence by replacing the first occurrence of target within self with empty string and returns the result.

public static String

Returns:

a String minus the part to be removed
minus
(final CharSequence
a String
self
,
final Pattern
a Pattern representing the part to remove
pattern
)

Removes a part of a CharSequence.

public static String

Returns:

a String composed of a repetition
multiply
(final CharSequence
a CharSequence to be repeated
self
,
final Number
the number of times the CharSequence should be repeated
factor
)

Repeats a CharSequence a certain number of times.

public static String

Returns:

a value obtained by incrementing the toString() of the CharSequence
next
(final CharSequence
a CharSequence
self
)

Overloads the ++ operator for the class CharSequence.

private static void
nextMatch(final String text, final StringGroovyMethods.ReplaceState state)

Helper method to find the next match for the replace method.

public static String

Returns:

the normalized toString() for the CharSequence
normalize
(final CharSequence
a CharSequence object
self
)

Returns a String with linefeeds and carriage returns normalized to linefeeds.

public static String

Returns:

the CharSequence padded to the left as a String
padLeft
(final CharSequence
a CharSequence object
self
,
final Number
the total minimum number of characters of the resulting CharSequence
numberOfChars
)

Pads a CharSequence to a minimum length specified by numberOfChars by adding the space character to the left as many times as needed.

public static String

Returns:

the CharSequence padded to the left as a String
padLeft
(final CharSequence
a CharSequence object
self
,
final Number
the total minimum number of characters of the resulting CharSequence
numberOfChars
,
final CharSequence
the characters used for padding
padding
)

Pads a CharSequence to a minimum length specified by numberOfChars, adding the supplied padding CharSequence as many times as needed to the left.

public static String

Returns:

the CharSequence padded to the right as a String
padRight
(final CharSequence
a CharSequence object
self
,
final Number
the total minimum number of characters of the resulting string
numberOfChars
)

Pads a CharSequence to a minimum length specified by numberOfChars by adding the space character to the right as many times as needed.

public static String

Returns:

the CharSequence padded to the right as a String
padRight
(final CharSequence
a CharSequence object
self
,
final Number
the total minimum number of characters of the resulting CharSequence
numberOfChars
,
final CharSequence
the characters used for padding
padding
)

Pads a CharSequence to a minimum length specified by numberOfChars, adding the supplied padding CharSequence as many times as needed to the right.

public static String

Returns:

the original toString() of the CharSequence with the object appended
plus
(final CharSequence
a CharSequence
left
,
final Object
any Object
right
)

Appends the String representation of the given operand to this CharSequence.

public static String

Returns:

a String
plus
(final Number
a Number
left
,
final String
a String
right
)

Appends a String to the string representation of this number.

public static String

Returns:

the new string with the object appended
plus
(final String
a String
left
,
final CharSequence
any CharSequence
right
)

Appends the String representation of the given operand to this string.

public static String

Returns:

a String
plus
(final StringBuffer
a StringBuffer
left
,
final String
a String
right
)

Appends a String to this StringBuffer.

public static String

Returns:

a String with a decremented character at the end
previous
(final CharSequence
a CharSequence
self
)

Overloads the -- operator for the class CharSequence.

public static void
putAt(final StringBuffer
a StringBuffer
self
,
final EmptyRange<T extends Comparable<T>>
a Range
range
,
final Object
the object that's toString() will be inserted
value
)

Supports the range subscript operator for StringBuffer.

public static void
putAt(final StringBuffer
a StringBuffer
self
,
final IntRange
a Range
range
,
final Object
the object that's toString() will be inserted
value
)

Supports the range subscript operator for StringBuffer.

public static List<String>

Returns:

a list of lines
readLines
(final CharSequence
a CharSequence object
self
)

Returns the lines of a CharSequence as a List of String.

public static String

Returns:

a String formed from the provided CharSequence after performing all of the replacements
replace
(final CharSequence
a CharSequence
self
,
final Map<CharSequence, CharSequence>
a map of before (key) and after (value) pairs processed in the natural order of the map
replacements
)

Replaces all occurrences of replacement CharSequences (supplied via a map) within a provided CharSequence.

public static String

Returns:

a String formed from the provided CharSequence after performing all of the replacements
replace
(final CharSequence
a CharSequence
self
,
final int
an optimization parameter, set to size after replacements or a little larger to avoid resizing overheads
capacity
,
final Map<CharSequence, CharSequence>
a map of before (key) and after (value) pairs processed in the natural order of the map
replacements
)

Replaces all occurrences of replacement CharSequences (supplied via a map) within a provided CharSequence with control over the internally created StringBuilder's capacity.

public static String

Returns:

the toString() of the CharSequence with content replaced
replaceAll
(final CharSequence
a CharSequence
self
,
final CharSequence
the capturing regex
regex
,
final CharSequence
the string to be substituted for each match
replacement
)

Replaces each substring of this CharSequence that matches the given regular expression with the given replacement.

public static String

Returns:

the toString() of the CharSequence with content replaced
replaceAll
(final CharSequence
a CharSequence
self
,
final CharSequence
the capturing regex
regex
,
final Closure<V>
the closure to apply on each captured group
closure
)

Replaces all occurrences of a captured group by the result of calling a closure on that text.

public static String

Returns:

the toString() of the CharSequence with content replaced
replaceAll
(final CharSequence
the CharSequence that is to be matched
self
,
final Pattern
the regex Pattern to which the CharSequence of interest is to be matched
pattern
,
final CharSequence
the CharSequence to be substituted for the first match
replacement
)

Replaces all substrings of a CharSequence that match the given compiled regular expression with the given replacement.

public static String

Returns:

the toString() of the CharSequence with replaced content
replaceAll
(final CharSequence
a CharSequence
self
,
final Pattern
the capturing regex Pattern
pattern
,
final Closure<V>
the closure to apply on each captured group
closure
)

Replaces all occurrences of a captured group by the result of a closure call on that text.

public static String
replaceFirst(final CharSequence
a CharSequence
self
,
final CharSequence
the capturing regex
regex
,
final CharSequence
the CharSequence to be substituted for each match
replacement
)

Replaces the first substring of this CharSequence that matches the given regular expression with the given replacement.

public static String
replaceFirst(final CharSequence
a CharSequence
self
,
final CharSequence
the capturing regex
regex
,
final Closure<V>
the closure to apply on the first captured group
closure
)

Replaces the first occurrence of a captured group by the result of a closure call on that text.

public static String
replaceFirst(final CharSequence
the CharSequence that is to be matched
self
,
final Pattern
the regex Pattern to which the CharSequence of interest is to be matched
pattern
,
final CharSequence
the CharSequence to be substituted for the first match
replacement
)

Replaces the first substring of a CharSequence that matches the given compiled regular expression with the given replacement.

public static String
replaceFirst(final CharSequence
a CharSequence
self
,
final Pattern
the capturing regex Pattern
pattern
,
final Closure<V>
the closure to apply on the first captured group
closure
)

Replaces the first occurrence of a captured group by the result of a closure call on that text.

public static String

Returns:

a new String with all the characters reversed.
reverse
(final CharSequence
a CharSequence
self
)

Creates a String which is the reverse (backwards) of this CharSequence

public static void
setIndex(final Matcher
a Matcher
self
,
int
the index number
index
)

Sets the position of the given Matcher to the given index.

public static int

Returns:

the length of the CharSequence
size
(final CharSequence
a CharSequence
self
)

Provides the standard Groovy size() method for CharSequence.

public static long

Returns:

the matcher's size (count)
size
(final Matcher
a matcher object
self
)

Provides the standard Groovy size() method for Matcher.

public static int

Returns:

the length of the String
size
(final String
a String
self
)

Deprecated
Provides the standard Groovy size() method for String.
public static int

Returns:

the length of the StringBuffer
size
(final StringBuffer
a StringBuffer
self
)

Deprecated
Provides the standard Groovy size() method for StringBuffer.
public static String[]

Returns:

String[] result of split
split
(final CharSequence
the CharSequence to split
self
)

Splits a CharSequence (with whitespace as delimiter).

public static <T> T

Returns:

the last value returned by the closure
splitEachLine
(final CharSequence
a CharSequence
self
,
final CharSequence
the delimiting regular expression
regex
,
final Closure<T>
a closure
closure
)

Iterates through the given CharSequence line by line, splitting each line using the given regex delimiter.

public static <T> T

Returns:

the last value returned by the closure
splitEachLine
(final CharSequence
a CharSequence
self
,
final Pattern
the regular expression Pattern for the delimiter
pattern
,
final Closure<T>
a closure
closure
)

Iterates through the given CharSequence line by line, splitting each line using the given separator Pattern.

public static boolean

Returns:

true if this CharSequence starts with any specified prefixes.
startsWithAny
(final CharSequence self, final CharSequence...
the prefixes.
prefixes
)

Tests if this CharSequence starts with any specified prefixes.

public static boolean

Returns:

true if the character sequence represented by the argument is a prefix of this CharSequence ignoring the case considerations. false otherwise. Returns false if the argument is null
startsWithIgnoreCase
(final CharSequence
the original CharSequence
self
,
final CharSequence
CharSequence being checked against this
searchString
)

Checks whether this CharSequence starts with the searchString ignoring the case considerations.

public static String

Returns:

the stripped toString() of the CharSequence
stripIndent
(final CharSequence
a CharSequence to strip the leading spaces from
self
)

Strips leading spaces from every line in a CharSequence.

public static String
stripIndent(final CharSequence
The CharSequence to strip the leading spaces from
self
,
final boolean
force groovy behavior to avoid conflicts with Java13's stripIndent
forceGroovyBehavior
)

Same logic as stripIndent(CharSequence) if forceGroovyBehavior is true, otherwise Java 13's stripIndent will be invoked.

public static String

Returns:

the stripped String
stripIndent
(final CharSequence
The CharSequence to strip the characters from
self
,
final int
The number of characters to strip
numChars
)

Strips numChars leading characters from every line in a CharSequence.

private static String
stripIndentFromLine(final String line, final int numChars)

public static String

Returns:

the stripped String
stripMargin
(final CharSequence
The CharSequence to strip the margin from
self
)

Strips leading whitespace/control characters followed by '|' from every line in a CharSequence.

public static String

Returns:

the stripped String
stripMargin
(final CharSequence
The CharSequence to strip the margin from
self
,
final char
Any character that serves as margin delimiter
marginChar
)

Strips leading whitespace/control characters followed by marginChar from every line in a CharSequence.

public static String

Returns:

the stripped CharSequence
stripMargin
(final CharSequence
The CharSequence to strip the margin from
self
,
final CharSequence
Any character that serves as margin delimiter
marginChar
)

Strips leading whitespace/control characters followed by marginChar from every line in a CharSequence.

private static String
stripMarginFromLine(final String line, final char marginChar)

public static CharSequence

Returns:

a CharSequence consisting of the first num chars, or else the whole CharSequence if it has less than num elements.
take
(final CharSequence
the original CharSequence
self
,
final int
the number of chars to take from this CharSequence
num
)

Returns the first num elements from this CharSequence.

public static String

Returns:

a String consisting of the first num chars, or else the whole GString if it has less than num elements.
take
(final GString
the original GString
self
,
final int
the number of chars to take from this GString
num
)

A GString variant of the equivalent CharSequence method.

public static String

Returns:

a String consisting of the first num chars, or else the whole String if it has less than num elements.
take
(final String
the original String
self
,
final int
the number of chars to take from this String
num
)

A String variant of the equivalent CharSequence method.

public static CharSequence

Returns:

CharSequence that is after the given searchString and empty string if it does not exist
takeAfter
(final CharSequence
the original CharSequence
self
,
final CharSequence
CharSequence that is searched in this CharSequence
searchString
)

Returns the CharSequence that exists after the first occurrence of the given searchString in this CharSequence.

public static String

Returns:

String that is after the given searchString and empty string if it does not exist
takeAfter
(final String
the original CharSequence
self
,
final CharSequence
String that is searched in this CharSequence
searchString
)

A String variant of the equivalent CharSequence method takeAfter(CharSequence, CharSequence).

public static String

Returns:

String that is after the given searchString and empty string if it does not exist
takeAfter
(final GString
the original CharSequence
self
,
final CharSequence
CharSequence that is searched in this CharSequence
searchString
)

A GString variant of the equivalent CharSequence method takeAfter(CharSequence, CharSequence).

public static CharSequence

Returns:

CharSequence that is before the given searchString
takeBefore
(final CharSequence
the original CharSequence
self
,
final CharSequence
CharSequence that is searched in this CharSequence
searchString
)

Returns the CharSequence that exists before the first occurrence of the given searchString in this CharSequence.

public static String

Returns:

String that is before the given searchString
takeBefore
(final GString
the original CharSequence
self
,
final String
CharSequence that is searched in this CharSequence
searchString
)

A GString variant of the equivalent CharSequence method takeBefore(CharSequence, CharSequence).

public static String

Returns:

String that is before the given searchString
takeBefore
(final String
the original CharSequence
self
,
final String
CharSequence that is searched in this CharSequence
searchString
)

A String variant of the equivalent CharSequence method takeBefore(CharSequence, CharSequence).

public static CharSequence

Returns:

the CharSequence that is in between the given two CharSequences and empty if the unavailable inputs are given
takeBetween
(final CharSequence
the original CharSequence
self
,
final CharSequence
beginning of search
from
,
final CharSequence
end of search
to
)

Returns the CharSequence that is in between the first occurrence of the given from and to CharSequences and empty if the unavailable inputs are given.

public static String

Returns:

String that is in between the given two CharSequences and empty if the unavailable inputs are given
takeBetween
(final String
the original CharSequence
self
,
final CharSequence
beginning of search
from
,
final CharSequence
end of search
to
)

A String variant of the equivalent CharSequence method takeBetween(CharSequence, CharSequence, CharSequence).

public static String

Returns:

String that is in between the given two CharSequences and empty if the unavailable inputs are given
takeBetween
(final GString
the original CharSequence
self
,
final CharSequence
beginning of search
from
,
final CharSequence
end of search
to
)

A GString variant of the equivalent CharSequence method takeBetween(CharSequence, CharSequence, CharSequence).

public static CharSequence

Returns:

CharSequence between the 2 subsequent enclosure strings
takeBetween
(final CharSequence
Original CharSequence
self
,
final CharSequence
Enclosure CharSequence
enclosure
)

Takes the characters between the first occurrence of the two subsequent enclosure strings.

public static String

Returns:

String between the 2 subsequent enclosure strings
takeBetween
(final String
Original String
self
,
final CharSequence
Enclosure CharSequence
enclosure
)

A String variant of the equivalent CharSequence method takeBetween(CharSequence, CharSequence).

public static String

Returns:

String between the 2 subsequent enclosure strings
takeBetween
(final GString
Original GString
self
,
final CharSequence
Enclosure CharSequence
enclosure
)

A GString variant of the equivalent CharSequence method takeBetween(CharSequence, CharSequence).

public static CharSequence

Returns:

the CharSequence that is in between the given the nth (specified by occurrence) pair of from and to CharSequences and empty if the unavailable inputs are given.
takeBetween
(final CharSequence
the original CharSequence
self
,
final CharSequence
beginning of search
from
,
final CharSequence
end of search
to
,
final int
nth occurrence that is to be returned. 0 represents first one
occurrence
)

Returns the CharSequence that is in between the given the nth (specified by occurrence) pair of from and to CharSequences and empty if the unavailable inputs are given.

public static String

Returns:

the String that is in between the given nth (specified by occurrence) pair of from and to CharSequences and empty if the unavailable inputs are given.
takeBetween
(final String
the original String
self
,
final CharSequence
beginning of search
from
,
final CharSequence
end of search
to
,
final int
nth occurrence that is to be returned. 0 represents first one
occurrence
)

A String variant of the equivalent CharSequence method takeBetween(CharSequence, CharSequence, CharSequence, int).

public static String

Returns:

the String that is in between the given nth (specified by occurrence) pair of from and to CharSequences and empty if the unavailable inputs are given.
takeBetween
(final GString
the original GString
self
,
final CharSequence
beginning of search
from
,
final CharSequence
end of search
to
,
final int
nth occurrence that is to be returned. 0 represents first one
occurrence
)

A GString variant of the equivalent CharSequence method takeBetween(CharSequence, CharSequence, CharSequence, int).

public static CharSequence

Returns:

CharSequence between the nth occurrence of pair of enclosure strings
takeBetween
(final CharSequence
Original CharSequence
self
,
final CharSequence
Enclosure CharSequence
enclosure
,
final int
nth occurrence being returned
occurrence
)

Takes the characters between nth (specified by occurrence) pair of enclosure strings.

public static String

Returns:

String between the nth occurrence of pair of enclosure strings
takeBetween
(final String
Original String
self
,
final CharSequence
Enclosure CharSequence
enclosure
,
int
nth occurrence being returned
occurrence
)

A String variant of the equivalent CharSequence method takeBetween(CharSequence, CharSequence, int).

public static String

Returns:

String between the nth occurrence of pair of enclosure strings
takeBetween
(final GString
Original GString
self
,
final CharSequence
Enclosure CharSequence
enclosure
,
final int
nth occurrence being returned
occurrence
)

A GString variant of the equivalent CharSequence method takeBetween(CharSequence, CharSequence, int).

public static CharSequence

Returns:

a CharSequence consisting of the last num chars, or else the whole CharSequence if it has less than num elements.
takeRight
(final CharSequence
the original CharSequence
self
,
final int
the number of chars to take from this CharSequence from the right
num
)

Returns the last num elements from this CharSequence.

public static String

Returns:

a String consisting of the last num chars, or else the whole CharSequence if it has less than num elements.
takeRight
(final String
the original CharSequence
self
,
final int
the number of chars to take from this CharSequence from the right
num
)

A GString variant of the equivalent CharSequence method takeRight(CharSequence, int).

public static String

Returns:

a String consisting of the last num chars, or else the whole GString if it has less than num elements.
takeRight
(final GString
the original GString
self
,
final int
the number of chars to take from this GString from the right
num
)

A String variant of the equivalent CharSequence method takeRight(CharSequence, int).

public static String

Returns:

a prefix of elements in the CharSequence where each element passed to the given closure evaluates to true
takeWhile
(final CharSequence
the original CharSequence
self
,
final Closure<V>
the closure that must evaluate to true to continue taking elements
condition
)

Returns the longest prefix of this CharSequence where each element passed to the given closure evaluates to true.

public static String

Returns:

a prefix of elements in the GString where each element passed to the given closure evaluates to true
takeWhile
(final GString
the original GString
self
,
final Closure<V>
the closure that must evaluate to true to continue taking elements
condition
)

A GString variant of the equivalent GString method.

public static CharSequence
takeWhile$$bridge(final CharSequence self, final Closure<V> condition)

Deprecated
public static BigDecimal

Returns:

a BigDecimal
toBigDecimal
(final CharSequence
a CharSequence
self
)

Parses a CharSequence into a BigDecimal

public static BigInteger

Returns:

a BigInteger
toBigInteger
(final CharSequence
a CharSequence
self
)

Parses a CharSequence into a BigInteger

public static Boolean

Returns:

The Boolean value
toBoolean
(final String
a String
self
)

Converts the given string into a Boolean object.

public static Character

Returns:

the first Character
toCharacter
(final String
a String
self
)

Converts the given string into a Character object using the first character in the string.

public static Double

Returns:

a Double
toDouble
(final CharSequence
a CharSequence
self
)

Parses a CharSequence into a Double.

public static Float

Returns:

a Float
toFloat
(final CharSequence
a CharSequence
self
)

Parses a CharSequence into a Float.

public static Integer

Returns:

an Integer
toInteger
(final CharSequence
a CharSequence
self
)

Parses a CharSequence into an Integer.

public static List<String>

Returns:

a List of tokens
tokenize
(final CharSequence
a CharSequence
self
)

Tokenizes a CharSequence (with a whitespace as the delimiter).

public static List<String>

Returns:

a List of tokens
tokenize
(final CharSequence
a CharSequence
self
,
final Character
the delimiter
delimiter
)

Tokenizes a CharSequence based on the given character delimiter.

public static List<String>

Returns:

a List of tokens
tokenize
(final CharSequence
a CharSequence
self
,
final CharSequence
the delimiters
delimiters
)

Tokenizes a CharSequence based on the given CharSequence.

public static List<String>

Returns:

a List of characters (a 1-character String)
toList
(final CharSequence
a CharSequence
self
)

Converts the given CharSequence into a List of Strings of one character.

public static Long

Returns:

a Long
toLong
(final CharSequence
a CharSequence
self
)

Parses a CharSequence into a Long

public static Set<String>

Returns:

a Set of unique characters (each a 1-character String)
toSet
(final CharSequence
a CharSequence
self
)

Converts the given CharSequence into a Set of unique Strings of one character.

public static Short

Returns:

a Short
toShort
(final CharSequence
a CharSequence
self
)

Parses a CharSequence into a Short.

public static String

Returns:

The resulting translated String
tr
(final CharSequence
the CharSequence that is to be translated
self
,
final CharSequence
the set of characters to translate from
sourceSet
,
final CharSequence
the set of replacement characters
replacementSet
)

Translates a CharSequence by replacing characters from the sourceSet with characters from replacementSet.

public static String

Returns:

A String containing the uncapitalized toString() of the CharSequence
uncapitalize
(final CharSequence
The CharSequence to uncapitalize
self
)

Convenience method to uncapitalize the first letter of a CharSequence (typically the first letter of a word).

public static String

Returns:

an unexpanded String
unexpand
(final CharSequence
A CharSequence to unexpand
self
)

Replaces sequences of whitespaces with tabs using tabStops of size 8.

public static String

Returns:

an unexpanded String
unexpand
(final CharSequence
A CharSequence to unexpand
self
,
final int
The number of spaces a tab represents
tabStop
)

Replaces sequences of whitespaces with tabs.

public static String

Returns:

an unexpanded String
unexpandLine
(final CharSequence
A line to unexpand
self
,
final int
The number of spaces a tab represents
tabStop
)

Replaces sequences of whitespaces with tabs within a line.

Inherited from org.codehaus.groovy.runtime.DefaultGroovyMethodsSupport:
cloneSimilarCollectioncloneSimilarMapcloseQuietlycloseWithWarningcreateSimilarArraycreateSimilarCollectioncreateSimilarCollectioncreateSimilarCollectioncreateSimilarListcreateSimilarMapcreateSimilarOrDefaultCollectioncreateSimilarQueuecreateSimilarSetnormaliseIndexsameTypesubListBorderssubListBorderstryClosewriteUTF16BomIfRequiredwriteUTF16BomIfRequiredwriteUTF16BomIfRequiredwriteUTF16BomIfRequired