Class CharSequences

java.lang.Object
org.grails.charsequences.CharSequences

public final class CharSequences extends Object
Utility functions for handling java.lang.CharSequence instances
Since:
2.3.10
  • Method Details

    • createCharSequence

      public static CharSequence createCharSequence(char[] chars)
    • createCharSequence

      public static CharSequence createCharSequence(char[] chars, int start, int count)
    • createCharSequence

      public static CharSequence createCharSequence(CharSequence str, int start, int count)
    • canUseOriginalForSubSequence

      public static boolean canUseOriginalForSubSequence(CharSequence str, int start, int count)
      Checks if start == 0 and count == length of CharSequence It does this check only for String, StringBuilder and StringBuffer classes which have a fast way to check length Calculating length on GStringImpl requires building the result which is costly. This helper method is to avoid calling length on other that String, StringBuilder and StringBuffer classes when checking if the input CharSequence instance is already the same as the requested sub sequence
      Parameters:
      str - CharSequence input
      start - start index
      count - length on sub sequence
      Returns:
      true if input is String, StringBuilder or StringBuffer class, start is 0 and count is length of input sequence
    • createSingleCharSequence

      public static CharSequence createSingleCharSequence(int c)
    • createSingleCharSequence

      public static CharSequence createSingleCharSequence(char ch)
    • writeCharSequence

      public static void writeCharSequence(Writer target, CharSequence csq, int start, int end) throws IOException
      Writes a CharSequence instance in the most optimal way to the target writer
      Parameters:
      target - writer
      csq - source CharSequence instance
      start - start/offset index
      end - end index + 1
      Throws:
      IOException
    • writeCharSequence

      public static void writeCharSequence(Writer target, CharSequence csq) throws IOException
      Throws:
      IOException
    • getChars

      public static void getChars(CharSequence csq, int srcBegin, int srcEnd, char[] dst, int dstBegin)
      Provides an optimized way to copy CharSequence content to target array. Uses getChars method available on String, StringBuilder and StringBuffer classes. Characters are copied from the source sequence csq into the destination character array dst. The first character to be copied is at index srcBegin; the last character to be copied is at index srcEnd-1. The total number of characters to be copied is srcEnd-srcBegin. The characters are copied into the subarray of dst starting at index dstBegin and ending at index:

       dstbegin + (srcEnd-srcBegin) - 1
       
      Parameters:
      csq - the source CharSequence instance.
      srcBegin - start copying at this offset.
      srcEnd - stop copying at this offset.
      dst - the array to copy the data into.
      dstBegin - offset into dst.
      Throws:
      NullPointerException - if dst is null.
      IndexOutOfBoundsException - if any of the following is true:
      • srcBegin is negative
      • dstBegin is negative
      • the srcBegin argument is greater than the srcEnd argument.
      • srcEnd is greater than this.length().
      • dstBegin+srcEnd-srcBegin is greater than dst.length