ice.util.alg
Class CharKit

java.lang.Object
  extended byice.util.alg.CharKit

public class CharKit
extends Object

All char-array methods operates on half open intervals [begin, end), that is they access array only at indexes i such that begin <= i < end.


Constructor Summary
CharKit()
           
 
Method Summary
static void asciiToLowerCase(char[] array, int begin, int end)
          Convert all occurences of 'A'..'Z' into corresponding 'a'..'z'
static void asciiToUpperCase(char[] array, int begin, int end)
          Convert all occurences of 'a'..'z' into corresponding 'A'..'Z'
static boolean equals(String str, char[] array, int begin, int end)
           
static boolean equalsIgnoreAsciiCase(String str, char[] array, int begin, int end)
           
static boolean equalsIgnoreAsciiCase(String str1, String str2)
           
static int indexOf(int ch, char[] array, int begin, int end)
           
static long parseInt(char[] array, int begin, int end)
          If array[begin..end) represents a signed decimal integer, return it as low 32 bits of the result, otherwise return -1L
static long parseInt(String s)
          If s represents a signed decimal integer, return it as low 32 bits of the result, otherwise return -1L
static long parseInt(String s, int begin, int end)
          If s[begin..end) represents a signed decimal integer, return it as low 32 bits of the result, otherwise return -1L
static char[] replace(char from, char[] to, char[] array, int begin, int end)
          Convert all occurences of 'from' into corresponding 'to'.
static void replace(char from, char to, char[] array, int begin, int end)
          Convert all occurences of 'from' into corresponding 'to'
static int skipAny(String set, char[] array, int begin, int end)
          Search for first occurrence of any character not from set
static int skipWhileNot(String set, char[] array, int begin, int end)
          Search for first occurrence of any character from set
static String[] split(int separator, String str)
           
static String[] split(int separator, String str, boolean skipEmpty)
           
static boolean startsWith(char[] array, int begin, int end, String prefix)
           
static boolean startsWithIgnoreAsciiCase(char[] array, int begin, int end, String prefix)
           
static boolean startsWithIgnoreAsciiCase(String str, String prefix)
           
static String toLowerCase(String s)
          Optimized version of s.toLowerCase()
static String toString(char[] array, int begin, int end)
           
static int trimEnd(char[] array, int begin, int end)
          Search for last non-ascii-space character, that is a character with value > ' ' or value > ' '.
static int trimEnd(String str, int begin, int end)
          Search for last non-ascii-space character, that is a character with value > ' ' or value > ' '.
static int trimStart(char[] array, int begin, int end)
          Search for first non-ascii-space character, that is a character with value > ' ' or value > ' '.
static int trimStart(String str, int begin, int end)
          Search for first non-ascii-space character, that is a character with value > ' ' or value > ' '.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CharKit

public CharKit()
Method Detail

indexOf

public static int indexOf(int ch,
                          char[] array,
                          int begin,
                          int end)

skipWhileNot

public static int skipWhileNot(String set,
                               char[] array,
                               int begin,
                               int end)
Search for first occurrence of any character from set

Returns:
index of first character that belongs to set or end Usage example: look for white space separated tokens in buf[begin..end) String spaces = "\n\r\t "; int token_beg = begin, token_end; for (;;) { token_beg = CharKit.skipAny(spaces, buf, token_beg, end); if (token_beg == end) { break; } // Here buf[token_beg] is not space, look for token end after it token_end = CharKit.skipWhileNot(spaces, buf, token_beg + 1, end); // Now buf[token_beg..token_end) are token chars processToken(buf, token_beg, token_end); }

skipAny

public static int skipAny(String set,
                          char[] array,
                          int begin,
                          int end)
Search for first occurrence of any character not from set

Returns:
index of first character that does not belong to set or end

trimStart

public static int trimStart(char[] array,
                            int begin,
                            int end)
Search for first non-ascii-space character, that is a character with value > ' ' or value > ' '.

Returns:
index of first non-ascii-space character or end if all characters are spaces

trimEnd

public static int trimEnd(char[] array,
                          int begin,
                          int end)
Search for last non-ascii-space character, that is a character with value > ' ' or value > ' '.

Returns:
index of last non-ascii-space character or begin if all characters are spaces

trimStart

public static int trimStart(String str,
                            int begin,
                            int end)
Search for first non-ascii-space character, that is a character with value > ' ' or value > ' '.

Returns:
index of first non-ascii-space character or end if all characters are spaces

trimEnd

public static int trimEnd(String str,
                          int begin,
                          int end)
Search for last non-ascii-space character, that is a character with value > ' ' or value > ' '.

Returns:
index of last non-ascii-space character or begin if all characters are spaces

asciiToLowerCase

public static void asciiToLowerCase(char[] array,
                                    int begin,
                                    int end)
Convert all occurences of 'A'..'Z' into corresponding 'a'..'z'


asciiToUpperCase

public static void asciiToUpperCase(char[] array,
                                    int begin,
                                    int end)
Convert all occurences of 'a'..'z' into corresponding 'A'..'Z'


replace

public static void replace(char from,
                           char to,
                           char[] array,
                           int begin,
                           int end)
Convert all occurences of 'from' into corresponding 'to'


replace

public static char[] replace(char from,
                             char[] to,
                             char[] array,
                             int begin,
                             int end)
Convert all occurences of 'from' into corresponding 'to'. Note that 'to' can be multiple characters

Returns:
new array with the converted

equals

public static boolean equals(String str,
                             char[] array,
                             int begin,
                             int end)

equalsIgnoreAsciiCase

public static boolean equalsIgnoreAsciiCase(String str,
                                            char[] array,
                                            int begin,
                                            int end)

equalsIgnoreAsciiCase

public static boolean equalsIgnoreAsciiCase(String str1,
                                            String str2)

startsWith

public static boolean startsWith(char[] array,
                                 int begin,
                                 int end,
                                 String prefix)

startsWithIgnoreAsciiCase

public static boolean startsWithIgnoreAsciiCase(char[] array,
                                                int begin,
                                                int end,
                                                String prefix)

startsWithIgnoreAsciiCase

public static boolean startsWithIgnoreAsciiCase(String str,
                                                String prefix)

toString

public static String toString(char[] array,
                              int begin,
                              int end)

toLowerCase

public static String toLowerCase(String s)
Optimized version of s.toLowerCase()


parseInt

public static long parseInt(char[] array,
                            int begin,
                            int end)
If array[begin..end) represents a signed decimal integer, return it as low 32 bits of the result, otherwise return -1L


parseInt

public static long parseInt(String s)
If s represents a signed decimal integer, return it as low 32 bits of the result, otherwise return -1L


parseInt

public static long parseInt(String s,
                            int begin,
                            int end)
If s[begin..end) represents a signed decimal integer, return it as low 32 bits of the result, otherwise return -1L


split

public static String[] split(int separator,
                             String str)

split

public static String[] split(int separator,
                             String str,
                             boolean skipEmpty)