Class GStringUtil

java.lang.Object
org.codehaus.groovy.runtime.GStringUtil

public final class GStringUtil extends Object
This class is primarily intended for INTERNAL USE. Use at your own risk.
  • Method Details

    • plusImpl

      public static GString plusImpl(Object[] thisValues, Object[] thatValues, String[] thisStrings, String[] thatStrings)
      Returns a new GStringImpl that concatenates the left and right parts. The input arrays are not modified. Values are copied left then right. When thisStrings is longer than thisValues, 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 GString
      thatValues - values from the right GString
      thisStrings - strings from the left GString
      thatStrings - strings from the right GString
      Returns:
      a GString holding the combined values and strings
    • writeToImpl

      public static Writer writeToImpl(Writer out, Object[] vs, String[] ss) throws IOException
      Writes each string in ss, and, when vs has an element at the same index, that value. A Closure value with no parameters is called and FormatHelper.write(Writer, Object) writes the call's result. A closure with one parameter is called with out and its result is not written. Any other value, including null, is passed to FormatHelper.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 text
      vs - the interpolated values
      ss - the literal strings
      Returns:
      out
      Throws:
      IOException - if a write fails
    • buildImpl

      public static void buildImpl(GroovyObject builder, Object[] vs, String[] ss)
      Yields each string, and each following value, through builder. For every string, and for a value at the same index when one exists, the property mkp is read and then yield is invoked with that string or value. The property read's result is discarded.
      Parameters:
      builder - the builder that receives mkp and yield
      vs - the interpolated values
      ss - the literal strings
    • calcInitialCapacityImpl

      public static int calcInitialCapacityImpl(Object[] vs, String[] ss)
      Estimates a buffer size from the literal strings. Sums ss[i].length(). When ss is non-empty, adds vs.length times the greater of that sum divided by ss.length (integer division) and 8. Returns the greater of 120% of that total, truncated to int, and 16. Value contents are not inspected. An empty ss yields 16.
      Parameters:
      vs - values, used only for vs.length
      ss - literal strings whose lengths are summed
      Returns:
      the estimated capacity, at least 16