Package org.grails.charsequences
Class CharSequences
java.lang.Object
org.grails.charsequences.CharSequences
Utility functions for handling java.lang.CharSequence instances
- Since:
- 2.3.10
-
Method Summary
Modifier and TypeMethodDescriptionstatic booleancanUseOriginalForSubSequence(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.static CharSequencecreateCharSequence(char[] chars) static CharSequencecreateCharSequence(char[] chars, int start, int count) static CharSequencecreateCharSequence(CharSequence str, int start, int count) static CharSequencecreateSingleCharSequence(char ch) static CharSequencecreateSingleCharSequence(int c) static voidgetChars(CharSequence csq, int srcBegin, int srcEnd, char[] dst, int dstBegin) Provides an optimized way to copy CharSequence content to target array.static voidwriteCharSequence(Writer target, CharSequence csq) static voidwriteCharSequence(Writer target, CharSequence csq, int start, int end) Writes a CharSequence instance in the most optimal way to the target writer
-
Method Details
-
createCharSequence
-
createCharSequence
-
createCharSequence
-
canUseOriginalForSubSequence
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 inputstart- start indexcount- 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
-
createSingleCharSequence
-
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- writercsq- source CharSequence instancestart- start/offset indexend- end index + 1- Throws:
IOException
-
writeCharSequence
- Throws:
IOException
-
getChars
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 sequencecsqinto the destination character arraydst. The first character to be copied is at indexsrcBegin; the last character to be copied is at indexsrcEnd-1. The total number of characters to be copied issrcEnd-srcBegin. The characters are copied into the subarray ofdststarting at indexdstBeginand 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 intodst.- Throws:
NullPointerException- ifdstisnull.IndexOutOfBoundsException- if any of the following is true:srcBeginis negativedstBeginis negative- the
srcBeginargument is greater than thesrcEndargument. srcEndis greater thanthis.length().dstBegin+srcEnd-srcBeginis greater thandst.length
-