Groovy Documentation

org.codehaus.groovy.grails.support.encoding
[Java] Class CharSequences

java.lang.Object
  org.codehaus.groovy.grails.support.encoding.CharSequences

public class CharSequences
extends java.lang.Object

Utility functions for handling java.lang.CharSequence instances

Authors:
Lari Hotari
Since:
2.3.10


Method Summary
static boolean canUseOriginalForSubSequence(java.lang.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

static java.lang.CharSequence createCharSequence(char[] chars)

static java.lang.CharSequence createCharSequence(char[] chars, int start, int count)

static java.lang.CharSequence createCharSequence(java.lang.CharSequence str, int start, int count)

static java.lang.CharSequence createSingleCharSequence(int c)

static java.lang.CharSequence createSingleCharSequence(char ch)

static void getChars(java.lang.CharSequence csq, int srcBegin, int srcEnd, char[] dst, int dstBegin)

Provides an optimized way to copy CharSequence content to target array.

static void writeCharSequence(java.io.Writer target, java.lang.CharSequence csq, int start, int end)

Writes a CharSequence instance in the most optimal way to the target writer

static void writeCharSequence(java.io.Writer target, java.lang.CharSequence csq)

 
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

canUseOriginalForSubSequence

public static boolean canUseOriginalForSubSequence(java.lang.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


createCharSequence

public static java.lang.CharSequence createCharSequence(char[] chars)


createCharSequence

public static java.lang.CharSequence createCharSequence(char[] chars, int start, int count)


createCharSequence

public static java.lang.CharSequence createCharSequence(java.lang.CharSequence str, int start, int count)


createSingleCharSequence

public static java.lang.CharSequence createSingleCharSequence(int c)


createSingleCharSequence

public static java.lang.CharSequence createSingleCharSequence(char ch)


getChars

public static void getChars(java.lang.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
 
throws:
NullPointerException if dst is null.
throws:
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
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.


writeCharSequence

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


writeCharSequence

public static void writeCharSequence(java.io.Writer target, java.lang.CharSequence csq)


 

Groovy Documentation