org.jboss.lang
Class StringRedirects

java.lang.Object
  extended by org.jboss.lang.StringRedirects

public class StringRedirects
extends Object

Contains methods added to java.lang.String in 1.5. Strings in 1.4 don't know about surrogate pairs and the difference between code points and chars, so for now just treat characters as if they were code points.


Constructor Summary
StringRedirects()
           
 
Method Summary
static JBossStringBuilder appendCodePoint(JBossStringBuilder builder, int codePoint)
           
static StringBuffer appendCodePoint(StringBuffer buffer, int codePoint)
           
static int codePointAt(JBossStringBuilder builder, int index)
           
static int codePointAt(StringBuffer buffer, int index)
           
static int codePointAt(String string, int index)
          Returns the character (Unicode code point) at the specified index.
static int codePointBefore(JBossStringBuilder builder, int index)
           
static int codePointBefore(StringBuffer buffer, int index)
           
static int codePointBefore(String string, int index)
          Returns the character (Unicode code point) just before the specified index.
static int codePointCount(JBossStringBuilder builder, int beginIndex, int endIndex)
           
static int codePointCount(StringBuffer buffer, int beginIndex, int endIndex)
           
static int codePointCount(String string, int beginIndex, int endIndex)
          Returns the number of code points between in the specified range.
static boolean contains(String string, CharSequence s)
          Whether the string contains the character sequence
static int offsetByCodePoints(JBossStringBuilder builder, int index, int codePointOffset)
           
static int offsetByCodePoints(StringBuffer buffer, int index, int codePointOffset)
           
static int offsetByCodePoints(String string, int index, int codePointOffset)
          Returns the index within this String that is offset from the given index by codePointOffset code points.
static String quoteReplacement(String string)
          Quote the replacement string
static String replace(String string, CharSequence target, CharSequence replacement)
          Replace a character sequence
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StringRedirects

public StringRedirects()
Method Detail

replace

public static String replace(String string,
                             CharSequence target,
                             CharSequence replacement)
Replace a character sequence

Parameters:
string - the string
target - the string to replace
replacement - the replacement text
Returns:
the result

contains

public static boolean contains(String string,
                               CharSequence s)
Whether the string contains the character sequence

Parameters:
string - the string
s - the character sequence
Returns:
true when it contains the sequence

quoteReplacement

public static String quoteReplacement(String string)
Quote the replacement string

Parameters:
string - the quoted string

codePointAt

public static int codePointAt(String string,
                              int index)
Returns the character (Unicode code point) at the specified index. Since java 1.4 doesn't know about code points, just returns the character value.

Parameters:
string - the string to examine
index - the code point index
Returns:
the code point
Throws:
IndexOutOfBoundsException - if the index argument is less than zero or beyond the end of the string

codePointBefore

public static int codePointBefore(String string,
                                  int index)
Returns the character (Unicode code point) just before the specified index. Since java 1.4 doesn't know about code points, just returns the character value.

Parameters:
string - the string to examine
index - the code point index
Returns:
the code point
Throws:
IndexOutOfBoundsException - if the index argument is less than one or beyond the end of the string

codePointCount

public static int codePointCount(String string,
                                 int beginIndex,
                                 int endIndex)
Returns the number of code points between in the specified range. Since java 1.4 doesn't know about code points, just returns character count.

Parameters:
string - the string to examine
beginIndex - the code point index to start at
endIndex - the code point index to end at
Returns:
the code point difference
Throws:
IndexOutOfBoundsException - if the beginIndex is negative, or endIndex is larger than the length of this String, or beginIndex is larger than endIndex.

offsetByCodePoints

public static int offsetByCodePoints(String string,
                                     int index,
                                     int codePointOffset)
Returns the index within this String that is offset from the given index by codePointOffset code points. Since java 1.4 doesn't know about code points, just returns character index.

Parameters:
string - the string to examine
index - the index to be offset
codePointOffset - the offset in code points
Returns:
the index within the string
Throws:
IndexOutOfBoundsException - if index is negative or larger then the length of this String, or if codePointOffset is positive and the substring starting with index has fewer than codePointOffset code points, or if codePointOffset is negative and the substring before index has fewer than the absolute value of codePointOffset code points.

appendCodePoint

public static StringBuffer appendCodePoint(StringBuffer buffer,
                                           int codePoint)

codePointAt

public static int codePointAt(StringBuffer buffer,
                              int index)

codePointBefore

public static int codePointBefore(StringBuffer buffer,
                                  int index)

codePointCount

public static int codePointCount(StringBuffer buffer,
                                 int beginIndex,
                                 int endIndex)

offsetByCodePoints

public static int offsetByCodePoints(StringBuffer buffer,
                                     int index,
                                     int codePointOffset)

appendCodePoint

public static JBossStringBuilder appendCodePoint(JBossStringBuilder builder,
                                                 int codePoint)

codePointAt

public static int codePointAt(JBossStringBuilder builder,
                              int index)

codePointBefore

public static int codePointBefore(JBossStringBuilder builder,
                                  int index)

codePointCount

public static int codePointCount(JBossStringBuilder builder,
                                 int beginIndex,
                                 int endIndex)

offsetByCodePoints

public static int offsetByCodePoints(JBossStringBuilder builder,
                                     int index,
                                     int codePointOffset)


Copyright © 2005-2007 JBoss, a division of Red Hat, Inc. All Rights Reserved.