Class GStringImpl
- All Implemented Interfaces:
- Buildable,- GroovyObject,- Writable,- Serializable,- CharSequence,- Comparable
- See Also:
- 
Field SummaryFields inherited from class groovy.lang.GStringEMPTY, EMPTY_OBJECT_ARRAY, EMPTY_STRING_ARRAY
- 
Constructor SummaryConstructorsModifierConstructorDescriptionGStringImpl(Object[] values, String[] strings) Create a new GString with values and strings.protectedGStringImpl(Object[] values, String[] strings, boolean cacheable, String cachedStringLiteral, boolean frozen) Create a new GString with values and strings.
- 
Method SummaryModifier and TypeMethodDescriptionvoidbuild(GroovyObject builder) protected intintcodePointAt(int index) intcodePointBefore(int index) intcodePointCount(int beginIndex, int endIndex) intintbooleanbooleanbooleanbooleanbooleanequalsIgnoreCase(String anotherString) freeze()byte[]voidgetChars(int srcBegin, int srcEnd, char[] dst, int dstBegin) String[]Get the strings of this GString.Object[]intindexOf(int ch) intindexOf(int ch, int fromIndex) intintintern()booleanisBlank()booleanisEmpty()intlastIndexOf(int ch) intlastIndexOf(int ch, int fromIndex) intlastIndexOf(String str) intlastIndexOf(String str, int fromIndex) lines()Returns a stream of lines extracted from this string, separated by line terminators.booleanintoffsetByCodePoints(int index, int codePointOffset) booleanregionMatches(boolean ignoreCase, int toffset, String other, int ooffset, int len) booleanregionMatches(int toffset, String other, int ooffset, int len) repeat(int count) Returns a string whose value is the concatenation of this string repeatedcounttimes.replace(char oldChar, char newChar) replace(CharSequence target, CharSequence replacement) replaceAll(String regex, String replacement) replaceFirst(String regex, String replacement) String[]String[]booleanstartsWith(String prefix) booleanstartsWith(String prefix, int toffset) strip()Returns a string whose value is this string, with all leading and trailing white space removed.Returns a string whose value is this string, with all leading white space removed.Returns a string whose value is this string, with all trailing white space removed.substring(int beginIndex) substring(int beginIndex, int endIndex) char[]toLowerCase(Locale locale) toString()toUpperCase(Locale locale) trim()Writes this object to the given writer.Methods inherited from class groovy.lang.GStringcharAt, compareTo, equals, equals, getBytes, getBytes, getValue, getValueCount, hashCode, invokeMethod, length, negate, plus, subSequenceMethods inherited from class groovy.lang.GroovyObjectSupportgetMetaClass, setMetaClassMethods inherited from class java.lang.Objectclone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.CharSequencechars, codePointsMethods inherited from interface groovy.lang.GroovyObjectgetProperty, setProperty
- 
Constructor Details- 
GStringImplCreate a new GString with values and strings.Each value is prefixed by a string, after the last value an additional String might be used, hence the following constraint is expected to hold: strings.length == values.length || strings.length == values.length + 1.NOTE: The lengths are not checked but using arrays with lengths which violate the above constraint could result in unpredictable behaviour. - Parameters:
- values- the value parts
- strings- the string parts
 
- 
GStringImplprotected GStringImpl(Object[] values, String[] strings, boolean cacheable, String cachedStringLiteral, boolean frozen) Create a new GString with values and strings.Each value is prefixed by a string, after the last value an additional String might be used, hence the following constraint is expected to hold: strings.length == values.length || strings.length == values.length + 1.NOTE: The lengths are not checked but using arrays with lengths which violate the above constraint could result in unpredictable behaviour. - Parameters:
- values- the value parts
- strings- the string parts
- frozen- creates a GStringImpl which is not subject to mutation and hence more amenable to caching
 
 
- 
- 
Method Details- 
plus
- 
writeToDescription copied from interface:WritableWrites this object to the given writer.This is used to defer content creation until the point when it is streamed to the output destination. Oftentimes, content will be defined but not necessarily created (as it may be the case with a Closure definition.) In that case, the output is then 'deferred' to the point when it is serialized to the writer. This class may be used whenever an object should be responsible for creating its own textual representation, but creating the entire output as a single String would be inefficient (such as outputting a multi-gigabyte XML document.) - Specified by:
- writeToin interface- Writable
- Overrides:
- writeToin class- GString
- Parameters:
- out- the Writer to which this Writable should output its data.
- Returns:
- the Writer that was passed
- Throws:
- IOException- if an error occurred while outputting data to the writer
 
- 
build
- 
calcInitialCapacityprotected int calcInitialCapacity()- Overrides:
- calcInitialCapacityin class- GString
 
- 
freeze- Returns:
- returns an equivalent optimised but less mutable version of this GString
 
- 
getStringsGet the strings of this GString.This method returns the same array as used in the constructor. Changing the values will result in changes of the GString. It is generally not recommended to do so. - Specified by:
- getStringsin class- GString
 
- 
getValues
- 
trim
- 
isEmptypublic boolean isEmpty()
- 
linesReturns a stream of lines extracted from this string, separated by line terminators.A line terminator is one of the following: a line feed character "\n"(U+000A), a carriage return character"\r"(U+000D), or a carriage return followed immediately by a line feed"\r\n"(U+000D U+000A).A line is either a sequence of zero or more characters followed by a line terminator, or it is a sequence of one or more characters followed by the end of the string. A line does not include the line terminator. The stream returned by this method contains the lines from this string in the order in which they occur. - Returns:
- the stream of lines extracted from this string
- Since:
- 5.0.0
 
- 
isBlankpublic boolean isBlank()- Returns:
- trueif the string is empty or contains only white space codepoints, otherwise- false
- Since:
- 5.0.0
- See Also:
 
- 
repeatReturns a string whose value is the concatenation of this string repeatedcounttimes.If this string is empty or count is zero then the empty string is returned. - Parameters:
- count- number of times to repeat
- Returns:
- A string composed of this string repeated
          counttimes or the empty string if this string is empty or count is zero
- Throws:
- IllegalArgumentException- if the- countis negative.
- Since:
- 5.0.0
 
- 
stripLeadingReturns a string whose value is this string, with all leading white space removed.If this Stringobject represents an empty string, or if all code points in this string are white space, then an empty string is returned.Otherwise, returns a substring of this string beginning with the first code point that is not a white space up to and including the last code point of this string. This method may be used to trim white space from the beginning of a string. - Returns:
- a string whose value is this string, with all leading white space removed
- Since:
- 5.0.0
- See Also:
 
- 
stripTrailingReturns a string whose value is this string, with all trailing white space removed.If this Stringobject represents an empty string, or if all characters in this string are white space, then an empty string is returned.Otherwise, returns a substring of this string beginning with the first code point of this string up to and including the last code point that is not a white space. This method may be used to trim white space from the end of a string. - Returns:
- a string whose value is this string, with all trailing white space removed
- Since:
- 5.0.0
- See Also:
 
- 
stripReturns a string whose value is this string, with all leading and trailing white space removed.If this Stringobject represents an empty string, or if all code points in this string are white space, then an empty string is returned.Otherwise, returns a substring of this string beginning with the first code point that is not a white space up to and including the last code point that is not a white space. This method may be used to strip white space from the beginning and end of a string. - Returns:
- a string whose value is this string, with all leading and trailing white space removed
- Since:
- 5.0.0
- See Also:
 
- 
codePointAtpublic int codePointAt(int index) 
- 
codePointBeforepublic int codePointBefore(int index) 
- 
codePointCountpublic int codePointCount(int beginIndex, int endIndex) 
- 
offsetByCodePointspublic int offsetByCodePoints(int index, int codePointOffset) 
- 
getCharspublic void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin) 
- 
getBytes
- 
contentEquals
- 
contentEquals
- 
equalsIgnoreCase
- 
compareTo
- 
compareToIgnoreCase
- 
regionMatches
- 
regionMatches
- 
startsWith
- 
startsWith
- 
endsWith
- 
indexOfpublic int indexOf(int ch) 
- 
indexOfpublic int indexOf(int ch, int fromIndex) 
- 
lastIndexOfpublic int lastIndexOf(int ch) 
- 
lastIndexOfpublic int lastIndexOf(int ch, int fromIndex) 
- 
indexOf
- 
indexOf
- 
lastIndexOf
- 
lastIndexOf
- 
substring
- 
substring
- 
concat
- 
replace
- 
matches
- 
contains
- 
replaceFirst
- 
replaceAll
- 
replace
- 
split
- 
split
- 
toLowerCase
- 
toLowerCase
- 
toUpperCase
- 
toUpperCase
- 
toCharArraypublic char[] toCharArray()
- 
intern
- 
toString- Specified by:
- toStringin interface- CharSequence
- Overrides:
- toStringin class- GString
 
 
-