|
Groovy Documentation | |||||||
FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.codehaus.groovy.runtime.DefaultGroovyMethodsSupport
org.codehaus.groovy.runtime.StringGroovyMethods
public class StringGroovyMethods extends DefaultGroovyMethodsSupport
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.
Method Summary | |
---|---|
static boolean
|
asBoolean(java.lang.CharSequence string)
Coerce a string (an instance of CharSequence) to a boolean value. |
static boolean
|
asBoolean(java.util.regex.Matcher matcher)
Coerce a Matcher instance to a boolean value. |
static java.lang.Object
|
asType(java.lang.CharSequence self, java.lang.Class c)
|
static java.lang.Object
|
asType(GString self, java.lang.Class c)
Converts the GString to a File, or delegates to the default DefaultGroovyMethods.asType |
static java.lang.Object
|
asType(java.lang.String self, java.lang.Class c)
|
static java.util.regex.Pattern
|
bitwiseNegate(java.lang.CharSequence self)
Turns a CharSequence into a regular expression Pattern |
static java.util.regex.Pattern
|
bitwiseNegate(java.lang.String self)
Turns a String into a regular expression Pattern |
static java.lang.CharSequence
|
capitalize(java.lang.CharSequence self)
Convenience method to capitalize the first letter of a CharSequence. |
static java.lang.String
|
capitalize(java.lang.String self)
Convenience method to capitalize the first letter of a string (typically the first letter of a word). |
static java.lang.CharSequence
|
center(java.lang.CharSequence self, java.lang.Number numberOfChars)
Pad 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. |
static java.lang.CharSequence
|
center(java.lang.CharSequence self, java.lang.Number numberOfChars, java.lang.CharSequence 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. |
static java.lang.String
|
center(java.lang.String self, java.lang.Number numberOfChars)
Pad a String to a minimum length specified by numberOfChars by adding the space character around it as many times as needed so that it remains centered. |
static java.lang.String
|
center(java.lang.String self, java.lang.Number numberOfChars, java.lang.String padding)
Pad a String to a minimum length specified by numberOfChars, appending the supplied padding String around the original as many times as needed keeping it centered. |
static java.lang.String
|
collectReplacements(java.lang.String orig, Closure transform)
Iterate through this String a character at a time collecting either the original character or a transformed replacement String. |
static boolean
|
contains(java.lang.CharSequence self, java.lang.CharSequence text)
Provide an implementation of contains() like java.util.Collection#contains(Object) to make CharSequences more polymorphic. |
static boolean
|
contains(java.lang.String self, java.lang.String text)
Provide an implementation of contains() like java.util.Collection#contains(Object) to make Strings more polymorphic. |
static int
|
count(java.lang.CharSequence self, java.lang.CharSequence text)
Count the number of occurrences of a sub CharSequence. |
static int
|
count(java.lang.String self, java.lang.String text)
Count the number of occurrences of a substring. |
static java.lang.CharSequence
|
denormalize(java.lang.CharSequence self)
Return a CharSequence with lines (separated by LF, CR/LF, or CR) terminated by the platform specific line separator. |
static java.lang.String
|
denormalize(java.lang.String self)
Return a String with lines (separated by LF, CR/LF, or CR) terminated by the platform specific line separator. |
static java.lang.CharSequence
|
drop(java.lang.CharSequence self, int num)
Drops the given number of chars from the head of this CharSequence if they are available. |
static java.lang.CharSequence
|
dropWhile(java.lang.CharSequence self, Closure condition)
Create 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. |
static java.lang.Object
|
eachLine(java.lang.CharSequence self, Closure closure)
Iterates through this CharSequence line by line. |
static java.lang.Object
|
eachLine(java.lang.CharSequence self, int firstLine, Closure closure)
|
static java.lang.Object
|
eachLine(java.lang.String self, Closure closure)
|
static java.lang.Object
|
eachLine(java.lang.String self, int firstLine, Closure closure)
|
static java.lang.String
|
eachMatch(java.lang.CharSequence self, java.lang.CharSequence regex, Closure closure)
Process each regex group matched substring of the given CharSequence. |
static java.lang.String
|
eachMatch(java.lang.CharSequence self, java.util.regex.Pattern pattern, Closure closure)
|
static java.lang.String
|
eachMatch(java.lang.String self, java.util.regex.Pattern pattern, Closure closure)
|
static java.lang.String
|
eachMatch(java.lang.String self, java.lang.String regex, Closure closure)
Expands all tabs into spaces with tabStops of size 8. |
static java.lang.CharSequence
|
expand(java.lang.CharSequence self)
|
static java.lang.CharSequence
|
expand(java.lang.CharSequence self, int tabStop)
Expands all tabs into spaces with tabStops of size 8. |
static java.lang.String
|
expand(java.lang.String self)
|
static java.lang.String
|
expand(java.lang.String self, int tabStop)
|
static java.lang.CharSequence
|
expandLine(java.lang.CharSequence self, int tabStop)
Expands all tabs into spaces. |
static java.lang.String
|
expandLine(java.lang.String self, int tabStop)
|
static java.lang.CharSequence
|
find(java.lang.CharSequence self, java.lang.CharSequence regex)
|
static java.lang.CharSequence
|
find(java.lang.CharSequence self, java.lang.CharSequence regex, Closure closure)
Finds the first occurrence of a compiled regular expression Pattern within a CharSequence. |
static java.lang.CharSequence
|
find(java.lang.CharSequence self, java.util.regex.Pattern pattern)
|
static java.lang.CharSequence
|
find(java.lang.CharSequence self, java.util.regex.Pattern pattern, Closure closure)
|
static java.lang.String
|
find(java.lang.String self, java.util.regex.Pattern pattern)
|
static java.lang.String
|
find(java.lang.String self, java.util.regex.Pattern pattern, Closure closure)
|
static java.lang.String
|
find(java.lang.String self, java.lang.String regex)
Finds the first occurrence of a regular expression String within a String. |
static java.lang.String
|
find(java.lang.String self, java.lang.String regex, Closure closure)
Returns a (possibly empty) list of all occurrences of a regular expression (in CharSequence format) found within a CharSequence. |
static java.util.List
|
findAll(java.lang.CharSequence self, java.lang.CharSequence regex)
|
static java.util.List
|
findAll(java.lang.CharSequence self, java.lang.CharSequence regex, Closure closure)
Returns a (possibly empty) list of all occurrences of a regular expression (in Pattern format) found within a CharSequence. |
static java.util.List
|
findAll(java.lang.CharSequence self, java.util.regex.Pattern pattern)
|
static java.util.List
|
findAll(java.lang.CharSequence self, java.util.regex.Pattern pattern, Closure closure)
|
static java.util.List
|
findAll(java.lang.String self, java.util.regex.Pattern pattern)
|
static java.util.List
|
findAll(java.lang.String self, java.util.regex.Pattern pattern, Closure closure)
Finds all occurrences of a compiled regular expression Pattern within a String. |
static java.util.List
|
findAll(java.lang.String self, java.lang.String regex)
|
static java.util.List
|
findAll(java.lang.String self, java.lang.String regex, Closure closure)
|
static java.lang.CharSequence
|
getAt(java.lang.CharSequence self, java.util.Collection indices)
|
static java.lang.CharSequence
|
getAt(java.lang.CharSequence text, EmptyRange range)
Support the range subscript operator for CharSequence or StringBuffer with EmptyRange |
static java.lang.CharSequence
|
getAt(java.lang.CharSequence text, int index)
Support the range subscript operator for CharSequence or StringBuffer with IntRange |
static java.lang.CharSequence
|
getAt(java.lang.CharSequence text, IntRange range)
Support the range subscript operator for CharSequence |
static java.lang.CharSequence
|
getAt(java.lang.CharSequence text, Range range)
|
static java.util.List
|
getAt(java.util.regex.Matcher self, java.util.Collection indices)
Select a List of values from a Matcher using a Collection to identify the indices to be selected. |
static java.lang.Object
|
getAt(java.util.regex.Matcher matcher, int idx)
|
static java.lang.String
|
getAt(java.lang.String self, java.util.Collection indices)
Support the range subscript operator for String with EmptyRange |
static java.lang.String
|
getAt(java.lang.String text, EmptyRange range)
Support the subscript operator for String. |
static java.lang.String
|
getAt(java.lang.String text, int index)
Support the range subscript operator for String with IntRange |
static java.lang.String
|
getAt(java.lang.String text, IntRange range)
Support the range subscript operator for String |
static java.lang.String
|
getAt(java.lang.String text, Range range)
|
static char[]
|
getChars(java.lang.CharSequence self)
Converts the given CharSequence into an array of characters. |
static char[]
|
getChars(java.lang.String self)
Find the number of Strings matched to the given Matcher. |
static int
|
getCount(java.util.regex.Matcher matcher)
|
static boolean
|
hasGroup(java.util.regex.Matcher matcher)
Check whether a Matcher contains a group or not. |
static boolean
|
isAllWhitespace(java.lang.CharSequence self)
True if a String only contains whitespace characters. |
static boolean
|
isAllWhitespace(java.lang.String self)
Determine if a CharSequence can be parsed as a BigDecimal. |
static boolean
|
isBigDecimal(java.lang.CharSequence self)
Determine if a String can be parsed into a BigDecimal. |
static boolean
|
isBigDecimal(java.lang.String self)
|
static boolean
|
isBigInteger(java.lang.CharSequence self)
Determine if a String can be parsed into a BigInteger. |
static boolean
|
isBigInteger(java.lang.String self)
|
static boolean
|
isCase(java.lang.CharSequence caseValue, java.lang.Object switchValue)
'Case' implementation for a GString, which simply calls the equivalent method for String. |
static boolean
|
isCase(GString caseValue, java.lang.Object switchValue)
|
static boolean
|
isCase(java.util.regex.Pattern caseValue, java.lang.Object switchValue)
|
static boolean
|
isCase(java.lang.String caseValue, java.lang.Object switchValue)
Determine if a CharSequence can be parsed as a Double. |
static boolean
|
isDouble(java.lang.CharSequence self)
Determine if a String can be parsed into a Double. |
static boolean
|
isDouble(java.lang.String self)
|
static boolean
|
isFloat(java.lang.CharSequence self)
Determine if a String can be parsed into a Float. |
static boolean
|
isFloat(java.lang.String self)
|
static boolean
|
isInteger(java.lang.CharSequence self)
Determine if a String can be parsed into an Integer. |
static boolean
|
isInteger(java.lang.String self)
|
static boolean
|
isLong(java.lang.CharSequence self)
Determine if a String can be parsed into a Long. |
static boolean
|
isLong(java.lang.String self)
|
static boolean
|
isNumber(java.lang.CharSequence self)
Determine if a String can be parsed into a Number. |
static boolean
|
isNumber(java.lang.String self)
Returns an java.util.Iterator which traverses each match. |
static java.util.Iterator
|
iterator(java.util.regex.Matcher matcher)
|
static java.lang.StringBuilder
|
leftShift(java.lang.CharSequence self, java.lang.Object value)
Overloads the left shift operator to provide an easy way to append multiple objects as string representations to a CharSequence. |
static java.lang.StringBuffer
|
leftShift(java.lang.String self, java.lang.Object value)
|
static java.lang.StringBuffer
|
leftShift(java.lang.StringBuffer self, java.lang.Object value)
|
static java.lang.StringBuilder
|
leftShift(java.lang.StringBuilder self, java.lang.Object value)
|
static boolean
|
matches(java.lang.CharSequence self, java.util.regex.Pattern pattern)
|
static boolean
|
matches(java.lang.String self, java.util.regex.Pattern pattern)
|
static boolean
|
matchesPartially(java.util.regex.Matcher matcher)
Given a matcher that matches a string against a pattern, this method returns true when the string matches the pattern or if a longer string, could match the pattern. |
static java.lang.CharSequence
|
minus(java.lang.CharSequence self, java.lang.Object target)
|
static java.lang.String
|
minus(java.lang.String self, java.lang.Object target)
|
static java.lang.CharSequence
|
multiply(java.lang.CharSequence self, java.lang.Number factor)
Repeat a String a certain number of times. |
static java.lang.String
|
multiply(java.lang.String self, java.lang.Number factor)
|
static java.lang.CharSequence
|
next(java.lang.CharSequence self)
This method is called by the ++ operator for the class String. |
static java.lang.String
|
next(java.lang.String self)
|
static java.lang.CharSequence
|
normalize(java.lang.CharSequence self)
Return a String with linefeeds and carriage returns normalized to linefeeds. |
static java.lang.String
|
normalize(java.lang.String self)
|
static java.lang.CharSequence
|
padLeft(java.lang.CharSequence self, java.lang.Number numberOfChars)
Pad a CharSequence to a minimum length specified by numberOfChars by adding the space character to the left as many times as needed. |
static java.lang.CharSequence
|
padLeft(java.lang.CharSequence self, java.lang.Number numberOfChars, java.lang.CharSequence padding)
|
static java.lang.String
|
padLeft(java.lang.String self, java.lang.Number numberOfChars)
|
static java.lang.String
|
padLeft(java.lang.String self, java.lang.Number numberOfChars, java.lang.String padding)
Pad a CharSequence to a minimum length specified by numberOfChars by adding the space character to the right as many times as needed. |
static java.lang.CharSequence
|
padRight(java.lang.CharSequence self, java.lang.Number numberOfChars)
Pad a CharSequence to a minimum length specified by numberOfChars, adding the supplied padding CharSequence as many times as needed to the right. |
static java.lang.CharSequence
|
padRight(java.lang.CharSequence self, java.lang.Number numberOfChars, java.lang.CharSequence padding)
|
static java.lang.String
|
padRight(java.lang.String self, java.lang.Number numberOfChars)
|
static java.lang.String
|
padRight(java.lang.String self, java.lang.Number numberOfChars, java.lang.String padding)
Appends the String representation of the given operand to this string. |
static java.lang.CharSequence
|
plus(java.lang.CharSequence left, java.lang.Object value)
Appends a String to the string representation of this number. |
static java.lang.String
|
plus(java.lang.Number value, java.lang.String right)
|
static java.lang.String
|
plus(java.lang.String left, java.lang.Object value)
|
static java.lang.String
|
plus(java.lang.StringBuffer left, java.lang.String value)
|
static java.lang.CharSequence
|
previous(java.lang.CharSequence self)
|
static java.lang.String
|
previous(java.lang.String self)
|
static void
|
putAt(java.lang.StringBuffer self, EmptyRange range, java.lang.Object value)
Support the range subscript operator for StringBuffer. |
static void
|
putAt(java.lang.StringBuffer self, IntRange range, java.lang.Object value)
|
static java.util.List
|
readLines(java.lang.CharSequence self)
|
static java.util.List
|
readLines(java.lang.String self)
|
static java.lang.CharSequence
|
replaceAll(java.lang.CharSequence self, java.lang.CharSequence regex, java.lang.CharSequence replacement)
|
static java.lang.CharSequence
|
replaceAll(java.lang.CharSequence self, java.lang.CharSequence regex, Closure closure)
|
static java.lang.CharSequence
|
replaceAll(java.lang.CharSequence self, java.util.regex.Pattern pattern, java.lang.CharSequence replacement)
|
static java.lang.String
|
replaceAll(java.lang.CharSequence self, java.util.regex.Pattern pattern, Closure closure)
|
static java.lang.String
|
replaceAll(java.lang.String self, java.util.regex.Pattern pattern, Closure closure)
|
static java.lang.String
|
replaceAll(java.lang.String self, java.util.regex.Pattern pattern, java.lang.String replacement)
|
static java.lang.String
|
replaceAll(java.lang.String self, java.lang.String regex, Closure closure)
Replaces the first substring of this CharSequence that matches the given regular expression with the given replacement. |
static java.lang.String
|
replaceFirst(java.lang.CharSequence self, java.lang.CharSequence regex, java.lang.CharSequence replacement)
|
static java.lang.String
|
replaceFirst(java.lang.CharSequence self, java.lang.CharSequence regex, Closure closure)
|
static java.lang.CharSequence
|
replaceFirst(java.lang.CharSequence self, java.util.regex.Pattern pattern, java.lang.CharSequence replacement)
|
static java.lang.String
|
replaceFirst(java.lang.CharSequence self, java.util.regex.Pattern pattern, Closure closure)
|
static java.lang.String
|
replaceFirst(java.lang.String self, java.util.regex.Pattern pattern, Closure closure)
|
static java.lang.String
|
replaceFirst(java.lang.String self, java.util.regex.Pattern pattern, java.lang.String replacement)
|
static java.lang.String
|
replaceFirst(java.lang.String self, java.lang.String regex, Closure closure)
Creates a new CharSequence which is the reverse (backwards) of this string |
static java.lang.CharSequence
|
reverse(java.lang.CharSequence self)
|
static java.lang.String
|
reverse(java.lang.String self)
|
static void
|
setIndex(java.util.regex.Matcher matcher, int idx)
|
static int
|
size(java.lang.CharSequence text)
Provide the standard Groovy |
static long
|
size(java.util.regex.Matcher self)
|
static int
|
size(java.lang.String text)
|
static int
|
size(java.lang.StringBuffer buffer)
|
static java.lang.CharSequence[]
|
split(java.lang.CharSequence self)
|
static java.lang.String[]
|
split(GString self)
|
static java.lang.String[]
|
split(java.lang.String self)
|
static java.lang.Object
|
splitEachLine(java.lang.CharSequence self, java.lang.CharSequence regex, Closure closure)
Iterates through the given CharSequence line by line, splitting each line using the given separator Pattern. |
static java.lang.Object
|
splitEachLine(java.lang.CharSequence self, java.util.regex.Pattern pattern, Closure closure)
Iterates through the given String line by line, splitting each line using the given separator Pattern. |
static java.lang.Object
|
splitEachLine(java.lang.String self, java.util.regex.Pattern pattern, Closure closure)
|
static java.lang.Object
|
splitEachLine(java.lang.String self, java.lang.String regex, Closure closure)
|
static java.lang.CharSequence
|
stripIndent(java.lang.CharSequence self)
|
static java.lang.CharSequence
|
stripIndent(java.lang.CharSequence self, int numChars)
|
static java.lang.String
|
stripIndent(java.lang.String self)
|
static java.lang.String
|
stripIndent(java.lang.String self, int numChars)
|
static java.lang.CharSequence
|
stripMargin(java.lang.CharSequence self)
|
static java.lang.CharSequence
|
stripMargin(java.lang.CharSequence self, char marginChar)
|
static java.lang.String
|
stripMargin(java.lang.CharSequence self, java.lang.CharSequence marginChar)
|
static java.lang.String
|
stripMargin(java.lang.String self)
|
static java.lang.String
|
stripMargin(java.lang.String self, char marginChar)
|
static java.lang.String
|
stripMargin(java.lang.String self, java.lang.String marginChar)
|
static java.lang.CharSequence
|
take(java.lang.CharSequence self, int num)
Returns the longest prefix of this CharSequence where each element passed to the given closure evaluates to true. |
static java.lang.CharSequence
|
takeWhile(java.lang.CharSequence self, Closure condition)
Parse a CharSequence into a BigDecimal |
static java.math.BigDecimal
|
toBigDecimal(java.lang.CharSequence self)
Parse a CharSequence into a BigInteger |
static java.math.BigDecimal
|
toBigDecimal(java.lang.String self)
|
static java.math.BigInteger
|
toBigInteger(java.lang.CharSequence self)
|
static java.math.BigInteger
|
toBigInteger(java.lang.String self)
|
static java.lang.Boolean
|
toBoolean(java.lang.String self)
|
static java.lang.Character
|
toCharacter(java.lang.String self)
Parse a String into a Double |
static java.lang.Double
|
toDouble(java.lang.CharSequence self)
|
static java.lang.Double
|
toDouble(java.lang.String self)
|
static java.lang.Float
|
toFloat(java.lang.CharSequence self)
|
static java.lang.Float
|
toFloat(java.lang.String self)
|
static java.lang.Integer
|
toInteger(java.lang.CharSequence self)
|
static java.lang.Integer
|
toInteger(java.lang.String self)
|
static java.util.List
|
toList(java.lang.CharSequence self)
Parse a CharSequence into a Long |
static java.util.List
|
toList(java.lang.String self)
Parse a String into a Long |
static java.lang.Long
|
toLong(java.lang.CharSequence self)
Converts the given CharSequence into a Set of unique CharSequence of one character. |
static java.lang.Long
|
toLong(java.lang.String self)
|
static java.util.Set
|
toSet(java.lang.CharSequence self)
Parse a CharSequence into a Short |
static java.util.Set
|
toSet(java.lang.String self)
Parse a String into a Short |
static java.lang.Short
|
toShort(java.lang.CharSequence self)
|
static java.lang.Short
|
toShort(java.lang.String self)
|
static java.util.List
|
tokenize(java.lang.CharSequence self)
Tokenize a CharSequence based on the given CharSequence delimiter. |
static java.util.List
|
tokenize(java.lang.CharSequence self, java.lang.Character token)
Tokenize a String (with a whitespace as the delimiter). |
static java.util.List
|
tokenize(java.lang.CharSequence self, java.lang.CharSequence token)
|
static java.util.List
|
tokenize(java.lang.String self)
|
static java.util.List
|
tokenize(java.lang.String self, java.lang.Character token)
Converts the given CharSequence into a List of CharSequence of one character. |
static java.util.List
|
tokenize(java.lang.String self, java.lang.String token)
Converts the given String into a List of strings of one character. |
static java.lang.CharSequence
|
tr(java.lang.CharSequence self, java.lang.CharSequence sourceSet, java.lang.CharSequence replacementSet)
|
static java.lang.String
|
tr(java.lang.String self, java.lang.String sourceSet, java.lang.String replacementSet)
Replaces sequences of whitespaces with tabs using tabStops of size 8. |
static java.lang.CharSequence
|
unexpand(java.lang.CharSequence self)
Replaces sequences of whitespaces with tabs using tabStops of size 8. |
static java.lang.CharSequence
|
unexpand(java.lang.CharSequence self, int tabStop)
Replaces sequences of whitespaces with tabs. |
static java.lang.String
|
unexpand(java.lang.String self)
|
static java.lang.String
|
unexpand(java.lang.String self, int tabStop)
Replaces sequences of whitespaces with tabs within a line. |
static java.lang.CharSequence
|
unexpandLine(java.lang.CharSequence self, int tabStop)
Replaces sequences of whitespaces with tabs within a line. |
static java.lang.String
|
unexpandLine(java.lang.String self, int tabStop)
|
Methods inherited from class java.lang.Object | |
---|---|
java.lang.Object#wait(long, int), java.lang.Object#wait(long), java.lang.Object#wait(), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll() |
Method Detail |
---|
public static boolean asBoolean(java.lang.CharSequence string)
string
- the character sequence
public static boolean asBoolean(java.util.regex.Matcher matcher)
matcher
- the matcher
public static java.lang.Object asType(java.lang.CharSequence self, java.lang.Class c)
Provides a method to perform custom 'dynamic' type conversion
to the given class using the as
operator.
self
- a CharSequencec
- the desired class
@SuppressWarnings("unchecked") public static java.lang.Object asType(GString self, java.lang.Class c)
self
- a GStringc
- the desired class
@SuppressWarnings("unchecked") public static java.lang.Object asType(java.lang.String self, java.lang.Class c)
Provides a method to perform custom 'dynamic' type conversion
to the given class using the as
operator.
'123' as Double
By default, the following types are supported:
self
- a Stringc
- the desired class
public static java.util.regex.Pattern bitwiseNegate(java.lang.CharSequence self)
self
- a String to convert into a regular expression
public static java.util.regex.Pattern bitwiseNegate(java.lang.String self)
self
- a String to convert into a regular expression
public static java.lang.CharSequence capitalize(java.lang.CharSequence self)
self
- The CharSequence to capitalize
public static java.lang.String capitalize(java.lang.String self)
assert 'h'.capitalize() == 'H' assert 'hello'.capitalize() == 'Hello' assert 'hello world'.capitalize() == 'Hello world' assert 'Hello World' == 'hello world'.split(' ').collect{ it.capitalize() }.join(' ')
self
- The string to capitalize
public static java.lang.CharSequence center(java.lang.CharSequence self, java.lang.Number numberOfChars)
self
- a CharSequence objectnumberOfChars
- the total minimum number of characters of the resulting CharSequence
public static java.lang.CharSequence center(java.lang.CharSequence self, java.lang.Number numberOfChars, java.lang.CharSequence padding)
self
- a CharSequence objectnumberOfChars
- the total minimum number of characters of the resulting CharSequencepadding
- the characters used for padding
public static java.lang.String center(java.lang.String self, java.lang.Number numberOfChars)
['A', 'BB', 'CCC', 'DDDD'].each{ println '|' + it.center(6) + '|' }will produce output like:
| A | | BB | | CCC | | DDDD |
self
- a String objectnumberOfChars
- the total minimum number of characters of the resulting string
public static java.lang.String center(java.lang.String self, java.lang.Number numberOfChars, java.lang.String padding)
['A', 'BB', 'CCC', 'DDDD'].each{ println '|' + it.center(6, '+') + '|' }will produce output like:
|++A+++| |++BB++| |+CCC++| |+DDDD+|
self
- a String objectnumberOfChars
- the total minimum number of characters of the resulting stringpadding
- the characters used for padding
public static java.lang.String collectReplacements(java.lang.String orig, Closure transform)
assert "Groovy".collectReplacements{ it == 'o' ? '_O_' : null } == 'Gr_O__O_vy' assert "B&W".collectReplacements{ it == '&' ? '&' : null } == 'B&W'
orig
- the original String
public static boolean contains(java.lang.CharSequence self, java.lang.CharSequence text)
self
- a CharSequencetext
- the CharSequence to look for
public static boolean contains(java.lang.String self, java.lang.String text)
self
- a Stringtext
- a String to look for
public static int count(java.lang.CharSequence self, java.lang.CharSequence text)
self
- a CharSequencetext
- a sub CharSequence
public static int count(java.lang.String self, java.lang.String text)
self
- a Stringtext
- a substring
public static java.lang.CharSequence denormalize(java.lang.CharSequence self)
self
- a CharSequence object
public static java.lang.String denormalize(java.lang.String self)
self
- a String object
public static java.lang.CharSequence drop(java.lang.CharSequence self, int num)
def text = "Groovy" assert text.drop( 0 ) == 'Groovy' assert text.drop( 2 ) == 'oovy' assert text.drop( 7 ) == ''
self
- the original CharSequencenum
- the number of characters to drop from this iteratornum
ones,
or else an empty String, if this CharSequence has less than num
characters.
public static java.lang.CharSequence dropWhile(java.lang.CharSequence self, Closure condition)
def text = "Groovy" assert text.dropWhile{ false } == 'Groovy' assert text.dropWhile{ true } == '' assert text.dropWhile{ it < 'Z' } == 'roovy' assert text.dropWhile{ it != 'v' } == 'vy'
self
- the original CharSequencecondition
- the closure that while continuously evaluating to true will cause us to drop elements from
the front of the original CharSequence
public static java.lang.Object eachLine(java.lang.CharSequence self, Closure closure)
self
- a CharSequenceclosure
- a closure
public static java.lang.Object eachLine(java.lang.CharSequence self, int firstLine, Closure closure)
public static java.lang.Object eachLine(java.lang.String self, Closure closure)
public static java.lang.Object eachLine(java.lang.String self, int firstLine, Closure closure)
public static java.lang.String eachMatch(java.lang.CharSequence self, java.lang.CharSequence regex, Closure closure)
self
- the source CharSequenceregex
- a Regex CharSequenceclosure
- a closure with one parameter or as much parameters as groups
public static java.lang.String eachMatch(java.lang.CharSequence self, java.util.regex.Pattern pattern, Closure closure)
public static java.lang.String eachMatch(java.lang.String self, java.util.regex.Pattern pattern, Closure closure)
public static java.lang.String eachMatch(java.lang.String self, java.lang.String regex, Closure closure)
self
- A CharSequence to expand
public static java.lang.CharSequence expand(java.lang.CharSequence self)
public static java.lang.CharSequence expand(java.lang.CharSequence self, int tabStop)
self
- A String to expand
public static java.lang.String expand(java.lang.String self)
public static java.lang.String expand(java.lang.String self, int tabStop)
public static java.lang.CharSequence expandLine(java.lang.CharSequence self, int tabStop)
self
- A line to expandtabStop
- The number of spaces a tab represents
public static java.lang.String expandLine(java.lang.String self, int tabStop)
public static java.lang.CharSequence find(java.lang.CharSequence self, java.lang.CharSequence regex)
public static java.lang.CharSequence find(java.lang.CharSequence self, java.lang.CharSequence regex, Closure closure)
self
- a CharSequencepattern
- the compiled regex Pattern
public static java.lang.CharSequence find(java.lang.CharSequence self, java.util.regex.Pattern pattern)
public static java.lang.CharSequence find(java.lang.CharSequence self, java.util.regex.Pattern pattern, Closure closure)
public static java.lang.String find(java.lang.String self, java.util.regex.Pattern pattern)
public static java.lang.String find(java.lang.String self, java.util.regex.Pattern pattern, Closure closure)
public static java.lang.String find(java.lang.String self, java.lang.String regex)
For example, if the regex doesn't match the result is null:
assert null == "New York, NY".find(/\d{5}/)
If it does match, we get the matching string back:
assert "10292" == "New York, NY 10292-0098".find(/\d{5}/)
If we have capture groups in our expression, we still get back the full match
assert "10292-0098" == "New York, NY 10292-0098".find(/(\d{5})-?(\d{4})/)
self
- a Stringregex
- the capturing regex
public static java.lang.String find(java.lang.String self, java.lang.String regex, Closure closure)
self
- a CharSequenceregex
- the capturing regex CharSequence
public static java.util.List findAll(java.lang.CharSequence self, java.lang.CharSequence regex)
public static java.util.List findAll(java.lang.CharSequence self, java.lang.CharSequence regex, Closure closure)
self
- a CharSequencepattern
- the compiled regex Pattern
public static java.util.List findAll(java.lang.CharSequence self, java.util.regex.Pattern pattern)
public static java.util.List findAll(java.lang.CharSequence self, java.util.regex.Pattern pattern, Closure closure)
public static java.util.List findAll(java.lang.String self, java.util.regex.Pattern pattern)
public static java.util.List findAll(java.lang.String self, java.util.regex.Pattern pattern, Closure closure)
For example, if the pattern doesn't match, it returns an empty list:
assert [] == "foo".findAll(~/(\w*) Fish/) { match, firstWord -> return firstWord }
Any regular expression matches are passed to the closure, if there are no capture groups, there will be one parameter for the match:
assert ["couldn't", "wouldn't"] == "I could not, would not, with a fox.".findAll(~/.ould/) { match -> "${match}n't"}
If there are capture groups, the first parameter will be the match followed by one parameter for each capture group:
def orig = "There's a Wocket in my Pocket" assert ["W > Wocket", "P > Pocket"] == orig.findAll(~/(.)ocket/) { match, firstLetter -> "$firstLetter > $match" }
self
- a Stringpattern
- the compiled regex Patternclosure
- will be passed the full match plus each of the capturing groups
public static java.util.List findAll(java.lang.String self, java.lang.String regex)
public static java.util.List findAll(java.lang.String self, java.lang.String regex, Closure closure)
public static java.lang.CharSequence getAt(java.lang.CharSequence self, java.util.Collection indices)
public static java.lang.CharSequence getAt(java.lang.CharSequence text, EmptyRange range)
text
- a CharSequencerange
- an EmptyRange
public static java.lang.CharSequence getAt(java.lang.CharSequence text, int index)
text
- a CharSequencerange
- an IntRange
public static java.lang.CharSequence getAt(java.lang.CharSequence text, IntRange range)
text
- a CharSequencerange
- a Range
public static java.lang.CharSequence getAt(java.lang.CharSequence text, Range range)
public static java.util.List getAt(java.util.regex.Matcher self, java.util.Collection indices)
self
- a Matcherindices
- a Collection of indices
public static java.lang.Object getAt(java.util.regex.Matcher matcher, int idx)
public static java.lang.String getAt(java.lang.String self, java.util.Collection indices)
text
- a Stringrange
- an EmptyRange
public static java.lang.String getAt(java.lang.String text, EmptyRange range)
text
- a Stringindex
- the index of the Character to get
public static java.lang.String getAt(java.lang.String text, int index)
text
- a Stringrange
- an IntRange
public static java.lang.String getAt(java.lang.String text, IntRange range)
text
- a Stringrange
- a Range
public static java.lang.String getAt(java.lang.String text, Range range)
public static char[] getChars(java.lang.CharSequence self)
self
- a CharSequence
public static char[] getChars(java.lang.String self)
matcher
- a Matcher
public static int getCount(java.util.regex.Matcher matcher)
public static boolean hasGroup(java.util.regex.Matcher matcher)
matcher
- a Matchertrue
if matcher contains at least one group.
public static boolean isAllWhitespace(java.lang.CharSequence self)
self
- The String to check the characters in
public static boolean isAllWhitespace(java.lang.String self)
self
- a CharSequence
public static boolean isBigDecimal(java.lang.CharSequence self)
self
- a String
public static boolean isBigDecimal(java.lang.String self)
public static boolean isBigInteger(java.lang.CharSequence self)
self
- a String
public static boolean isBigInteger(java.lang.String self)
public static boolean isCase(java.lang.CharSequence caseValue, java.lang.Object switchValue)
caseValue
- the case valueswitchValue
- the switch value
public static boolean isCase(GString caseValue, java.lang.Object switchValue)
public static boolean isCase(java.util.regex.Pattern caseValue, java.lang.Object switchValue)
public static boolean isCase(java.lang.String caseValue, java.lang.Object switchValue)
self
- a CharSequence
public static boolean isDouble(java.lang.CharSequence self)
self
- a String
public static boolean isDouble(java.lang.String self)
public static boolean isFloat(java.lang.CharSequence self)
self
- a String
public static boolean isFloat(java.lang.String self)
public static boolean isInteger(java.lang.CharSequence self)
self
- a String
public static boolean isInteger(java.lang.String self)
public static boolean isLong(java.lang.CharSequence self)
self
- a String
public static boolean isLong(java.lang.String self)
public static boolean isNumber(java.lang.CharSequence self)
self
- a String
public static boolean isNumber(java.lang.String self)
matcher
- a Matcher object
public static java.util.Iterator iterator(java.util.regex.Matcher matcher)
public static java.lang.StringBuilder leftShift(java.lang.CharSequence self, java.lang.Object value)
self
- a CharSequencevalue
- an Object
public static java.lang.StringBuffer leftShift(java.lang.String self, java.lang.Object value)
public static java.lang.StringBuffer leftShift(java.lang.StringBuffer self, java.lang.Object value)
public static java.lang.StringBuilder leftShift(java.lang.StringBuilder self, java.lang.Object value)
public static boolean matches(java.lang.CharSequence self, java.util.regex.Pattern pattern)
public static boolean matches(java.lang.String self, java.util.regex.Pattern pattern)
public static boolean matchesPartially(java.util.regex.Matcher matcher)
def emailPattern = /\w+@\w+\.\w{2,}/ def matcher = "john@doe" =~ emailPattern assert matcher.matchesPartially() matcher = "john@doe.com" =~ emailPattern assert matcher.matchesPartially() matcher = "john@@" =~ emailPattern assert !matcher.matchesPartially()
matcher
- the Matcher
public static java.lang.CharSequence minus(java.lang.CharSequence self, java.lang.Object target)
public static java.lang.String minus(java.lang.String self, java.lang.Object target)
public static java.lang.CharSequence multiply(java.lang.CharSequence self, java.lang.Number factor)
self
- a String to be repeatedfactor
- the number of times the String should be repeated
public static java.lang.String multiply(java.lang.String self, java.lang.Number factor)
public static java.lang.CharSequence next(java.lang.CharSequence self)
self
- a String
public static java.lang.String next(java.lang.String self)
public static java.lang.CharSequence normalize(java.lang.CharSequence self)
self
- a String object
public static java.lang.String normalize(java.lang.String self)
public static java.lang.CharSequence padLeft(java.lang.CharSequence self, java.lang.Number numberOfChars)
self
- a CharSequence objectnumberOfChars
- the total minimum number of characters of the resulting CharSequence
public static java.lang.CharSequence padLeft(java.lang.CharSequence self, java.lang.Number numberOfChars, java.lang.CharSequence padding)
public static java.lang.String padLeft(java.lang.String self, java.lang.Number numberOfChars)
public static java.lang.String padLeft(java.lang.String self, java.lang.Number numberOfChars, java.lang.String padding)
self
- a CharSequence objectnumberOfChars
- the total minimum number of characters of the resulting string
public static java.lang.CharSequence padRight(java.lang.CharSequence self, java.lang.Number numberOfChars)
self
- a CharSequence objectnumberOfChars
- the total minimum number of characters of the resulting CharSequencepadding
- the characters used for padding
public static java.lang.CharSequence padRight(java.lang.CharSequence self, java.lang.Number numberOfChars, java.lang.CharSequence padding)
public static java.lang.String padRight(java.lang.String self, java.lang.Number numberOfChars)
public static java.lang.String padRight(java.lang.String self, java.lang.Number numberOfChars, java.lang.String padding)
left
- a CharSequencevalue
- any Object
public static java.lang.CharSequence plus(java.lang.CharSequence left, java.lang.Object value)
value
- a Numberright
- a String
public static java.lang.String plus(java.lang.Number value, java.lang.String right)
public static java.lang.String plus(java.lang.String left, java.lang.Object value)
public static java.lang.String plus(java.lang.StringBuffer left, java.lang.String value)
public static java.lang.CharSequence previous(java.lang.CharSequence self)
public static java.lang.String previous(java.lang.String self)
public static void putAt(java.lang.StringBuffer self, EmptyRange range, java.lang.Object value)
self
- a StringBufferrange
- a Rangevalue
- the object that's toString() will be inserted
public static void putAt(java.lang.StringBuffer self, IntRange range, java.lang.Object value)
public static java.util.List readLines(java.lang.CharSequence self)
public static java.util.List readLines(java.lang.String self)
public static java.lang.CharSequence replaceAll(java.lang.CharSequence self, java.lang.CharSequence regex, java.lang.CharSequence replacement)
public static java.lang.CharSequence replaceAll(java.lang.CharSequence self, java.lang.CharSequence regex, Closure closure)
public static java.lang.CharSequence replaceAll(java.lang.CharSequence self, java.util.regex.Pattern pattern, java.lang.CharSequence replacement)
public static java.lang.String replaceAll(java.lang.CharSequence self, java.util.regex.Pattern pattern, Closure closure)
public static java.lang.String replaceAll(java.lang.String self, java.util.regex.Pattern pattern, Closure closure)
public static java.lang.String replaceAll(java.lang.String self, java.util.regex.Pattern pattern, java.lang.String replacement)
public static java.lang.String replaceAll(java.lang.String self, java.lang.String regex, Closure closure)
self
- a CharSequenceregex
- the capturing regexreplacement
- the capturing regex
public static java.lang.String replaceFirst(java.lang.CharSequence self, java.lang.CharSequence regex, java.lang.CharSequence replacement)
public static java.lang.String replaceFirst(java.lang.CharSequence self, java.lang.CharSequence regex, Closure closure)
public static java.lang.CharSequence replaceFirst(java.lang.CharSequence self, java.util.regex.Pattern pattern, java.lang.CharSequence replacement)
public static java.lang.String replaceFirst(java.lang.CharSequence self, java.util.regex.Pattern pattern, Closure closure)
public static java.lang.String replaceFirst(java.lang.String self, java.util.regex.Pattern pattern, Closure closure)
public static java.lang.String replaceFirst(java.lang.String self, java.util.regex.Pattern pattern, java.lang.String replacement)
public static java.lang.String replaceFirst(java.lang.String self, java.lang.String regex, Closure closure)
self
- a CharSequence
public static java.lang.CharSequence reverse(java.lang.CharSequence self)
public static java.lang.String reverse(java.lang.String self)
public static void setIndex(java.util.regex.Matcher matcher, int idx)
public static int size(java.lang.CharSequence text)
size()
method for CharSequence
.
text
- a CharSequence
public static long size(java.util.regex.Matcher self)
public static int size(java.lang.String text)
public static int size(java.lang.StringBuffer buffer)
public static java.lang.CharSequence[] split(java.lang.CharSequence self)
public static java.lang.String[] split(GString self)
public static java.lang.String[] split(java.lang.String self)
public static java.lang.Object splitEachLine(java.lang.CharSequence self, java.lang.CharSequence regex, Closure closure)
self
- a CharSequencepattern
- the regular expression Pattern for the delimiterclosure
- a closure
public static java.lang.Object splitEachLine(java.lang.CharSequence self, java.util.regex.Pattern pattern, Closure closure)
self
- a Stringpattern
- the regular expression Pattern for the delimiterclosure
- a closure
public static java.lang.Object splitEachLine(java.lang.String self, java.util.regex.Pattern pattern, Closure closure)
public static java.lang.Object splitEachLine(java.lang.String self, java.lang.String regex, Closure closure)
Strip leading spaces from every line in a CharSequence. The line with the least number of leading spaces determines the number to remove. Lines only containing whitespace are ignored when calculating the number of leading spaces to strip.
self
- The CharSequence to strip the leading spaces from
public static java.lang.CharSequence stripIndent(java.lang.CharSequence self)
public static java.lang.CharSequence stripIndent(java.lang.CharSequence self, int numChars)
public static java.lang.String stripIndent(java.lang.String self)
public static java.lang.String stripIndent(java.lang.String self, int numChars)
public static java.lang.CharSequence stripMargin(java.lang.CharSequence self)
public static java.lang.CharSequence stripMargin(java.lang.CharSequence self, char marginChar)
public static java.lang.String stripMargin(java.lang.CharSequence self, java.lang.CharSequence marginChar)
public static java.lang.String stripMargin(java.lang.String self)
public static java.lang.String stripMargin(java.lang.String self, char marginChar)
public static java.lang.String stripMargin(java.lang.String self, java.lang.String marginChar)
public static java.lang.CharSequence take(java.lang.CharSequence self, int num)
def text = "Groovy" assert text.takeWhile{ it < 'A' } == '' assert text.takeWhile{ it < 'Z' } == 'G' assert text.takeWhile{ it != 'v' } == 'Groo' assert text.takeWhile{ it < 'z' } == 'Groovy'
self
- the original CharSequencecondition
- the closure that must evaluate to true to
continue taking elements
public static java.lang.CharSequence takeWhile(java.lang.CharSequence self, Closure condition)
self
- a CharSequence
public static java.math.BigDecimal toBigDecimal(java.lang.CharSequence self)
self
- a CharSequence
public static java.math.BigDecimal toBigDecimal(java.lang.String self)
public static java.math.BigInteger toBigInteger(java.lang.CharSequence self)
public static java.math.BigInteger toBigInteger(java.lang.String self)
public static java.lang.Boolean toBoolean(java.lang.String self)
public static java.lang.Character toCharacter(java.lang.String self)
self
- a String
public static java.lang.Double toDouble(java.lang.CharSequence self)
public static java.lang.Double toDouble(java.lang.String self)
public static java.lang.Float toFloat(java.lang.CharSequence self)
public static java.lang.Float toFloat(java.lang.String self)
public static java.lang.Integer toInteger(java.lang.CharSequence self)
public static java.lang.Integer toInteger(java.lang.String self)
public static java.util.List toList(java.lang.CharSequence self)
self
- a CharSequence
public static java.util.List toList(java.lang.String self)
self
- a String
public static java.lang.Long toLong(java.lang.CharSequence self)
self
- a CharSequence
public static java.lang.Long toLong(java.lang.String self)
public static java.util.Set toSet(java.lang.CharSequence self)
self
- a CharSequence
public static java.util.Set toSet(java.lang.String self)
self
- a String
public static java.lang.Short toShort(java.lang.CharSequence self)
public static java.lang.Short toShort(java.lang.String self)
public static java.util.List tokenize(java.lang.CharSequence self)
self
- a CharSequencetoken
- the delimiter
public static java.util.List tokenize(java.lang.CharSequence self, java.lang.Character token)
self
- a String
public static java.util.List tokenize(java.lang.CharSequence self, java.lang.CharSequence token)
* @see java.util.StringTokenizer#StringTokenizer(String, String) public static java.util.List tokenize(java.lang.String self)
public static java.util.List tokenize(java.lang.String self, java.lang.Character token)
self
- a CharSequence
} public static java.util.List tokenize(java.lang.String self, java.lang.String token)
self
- a String
public static java.lang.CharSequence tr(java.lang.CharSequence self, java.lang.CharSequence sourceSet, java.lang.CharSequence replacementSet)
public static java.lang.String tr(java.lang.String self, java.lang.String sourceSet, java.lang.String replacementSet)
self
- A CharSequence to unexpand
public static java.lang.CharSequence unexpand(java.lang.CharSequence self)
self
- A String to unexpand
public static java.lang.CharSequence unexpand(java.lang.CharSequence self, int tabStop)
self
- A String to unexpandtabStop
- The number of spaces a tab represents
public static java.lang.String unexpand(java.lang.String self)
public static java.lang.String unexpand(java.lang.String self, int tabStop)
self
- A line to unexpandtabStop
- The number of spaces a tab represents
public static java.lang.CharSequence unexpandLine(java.lang.CharSequence self, int tabStop)
self
- A line to unexpandtabStop
- The number of spaces a tab represents
public static java.lang.String unexpandLine(java.lang.String self, int tabStop)
Groovy Documentation