Package org.codehaus.groovy.runtime
Class GStringUtil
java.lang.Object
org.codehaus.groovy.runtime.GStringUtil
This class is primarily intended for INTERNAL USE. Use at your own risk.
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidbuildImpl(GroovyObject builder, Object[] vs, String[] ss) Yields each string, and each following value, throughbuilder.static intcalcInitialCapacityImpl(Object[] vs, String[] ss) Estimates a buffer size from the literal strings.static GStringReturns a newGStringImplthat concatenates the left and right parts.static WriterwriteToImpl(Writer out, Object[] vs, String[] ss) Writes each string inss, and, whenvshas an element at the same index, that value.
-
Method Details
-
plusImpl
public static GString plusImpl(Object[] thisValues, Object[] thatValues, String[] thisStrings, String[] thatStrings) Returns a newGStringImplthat concatenates the left and right parts. The input arrays are not modified. Values are copied left then right. WhenthisStringsis longer thanthisValues, the last left string is concatenated with the first right string and the remaining right strings follow, so the boundary does not insert an empty value. Otherwise the right strings are copied in full.- Parameters:
thisValues- values from the left GStringthatValues- values from the right GStringthisStrings- strings from the left GStringthatStrings- strings from the right GString- Returns:
- a GString holding the combined values and strings
-
writeToImpl
Writes each string inss, and, whenvshas an element at the same index, that value. AClosurevalue with no parameters is called andFormatHelper.write(Writer, Object)writes the call's result. A closure with one parameter is called withoutand its result is not written. Any other value, includingnull, is passed toFormatHelper.write(Writer, Object). Returns the same writer.A closure value that takes more than one parameter is rejected.
- Parameters:
out- the writer that receives the textvs- the interpolated valuesss- the literal strings- Returns:
out- Throws:
IOException- if a write fails
-
buildImpl
Yields each string, and each following value, throughbuilder. For every string, and for a value at the same index when one exists, the propertymkpis read and thenyieldis invoked with that string or value. The property read's result is discarded.- Parameters:
builder- the builder that receivesmkpandyieldvs- the interpolated valuesss- the literal strings
-
calcInitialCapacityImpl
Estimates a buffer size from the literal strings. Sumsss[i].length(). Whenssis non-empty, addsvs.lengthtimes the greater of that sum divided byss.length(integer division) and 8. Returns the greater of 120% of that total, truncated toint, and 16. Value contents are not inspected. An emptyssyields 16.- Parameters:
vs- values, used only forvs.lengthss- literal strings whose lengths are summed- Returns:
- the estimated capacity, at least 16
-