|
UC Berkeley Group for User Interface Research Updated November 17, 2000 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--edu.berkeley.guir.lib.util.StringLib
Various String utilities and routines for manipulating Strings, as well as laying them out and rendering them on screen.
Basically, everytime I needed a String utility that didn't exist, I went ahead and wrote it up, placing it in here. There's lots of stuff here.
The methods here can be roughly grouped into six categories:
This software is distributed under the Berkeley Software License.
Revisions: - GUIRLib-v1.0-1.0.0, Apr 19 1997, JH Created class - GUIRLib-v1.2-1.0.0, Jun 22 2000, JH Touched for GUIRLib release - GUIRLib-v1.3-1.0.0, Aug 11 2000, JH Touched for GUIRLib release - GUIRLib-v1.4-1.0.0, Aug 31 2000, JH Touched for GUIRLib release
Field Summary | |
static int |
DEFAULT_FOLD_LENGTH
The maximum number of characters per line. |
static int |
foldLength
How many spaces to fold on. |
static String |
foldtokens
What characters to fold lines on. |
static String |
SPACES
81 space characters. |
Method Summary | |
static String |
align(String str,
char ch)
Align text in a String into two columns. |
static boolean |
containsChars(String str,
char[] chars)
See if a given String contains any of the specified characters. |
static boolean |
containsChars(String str,
String strChars)
See if a given String contains any of the specified characters. |
static int |
countNumOfChar(char chSearch,
String strLine)
Count the number of occurrences of a character in a String. |
static int |
countNumOfString(String strSearch,
String strLine)
Count the number of occurrences of a String in a String. |
static String |
fold(Object obj1,
Object obj2)
|
static String |
fold(String strText,
int numCols)
See fold(). |
static String |
fold(String strPrefix,
String strText)
See fold(). |
static String |
fold(String strPrefix,
String strText,
int numCols)
See fold(). |
static String |
fold(String strPrefix,
String strText,
String eoln,
int numCols)
Fold the text around to the next line correctly. |
static String |
getBarredLine(char ch)
Repeat the character 80 times and return it as a String. |
static String |
getBarredLine(String strText,
char ch)
Given a String like "example" and a char like '=', return |
static int |
getMaxNumCols(String str)
After laying out the String into rows, count the number of characters in the longest line. |
static int |
getMaxNumCols(String str,
int numCols)
After laying out the String into rows, count the number of characters in the longest line. |
static int |
getMaxNumCols(String str,
String eoln)
After laying out the String into rows, count the number of characters in the longest line. |
static int |
getMaxNumCols(String str,
String eoln,
int numCols)
After laying out the String into rows, count the number of characters in the longest line. |
static int |
getNumRows(String str)
Count the number of rows this String fills up, based on where the carriage returns '\n' are. |
static int |
getNumRows(String str,
int numCols)
Count the number of rows this String fills up, taking into account that it may have a column limit (ie max num of chars per line). |
static String |
getSegmentType(int val)
Given a segment type (in PathIterator , return a String with the
kind of segment. |
static String |
indent(String str,
int spaces)
Indent the String by pushing all of the rows of the String the specified number of spaces. |
static char |
interpretEscapeSequence(String str)
Given a String containing an escape sequence, interpret what it is. |
static String |
interpretString(String str)
Given a String literally containing escape sequences (including unicode ones), convert it into a String with the interpreted escape sequences in place. |
boolean |
isDecimalNumber(String str)
See if a given String is a decimal number or not. |
static void |
main(String[] argv)
|
static String |
padAtEnd(String str,
int len)
Pad this String at the end so that it is at least the specified length. |
static String |
padAtFront(String str,
int len)
Pad this String at the front so that it is at least the specified length. |
static String |
removeSubstring(char chFrom,
char chTo,
String strLine)
Remove all characters from a String starting from the first location of one character to the first location of another character. |
static String |
replaceSubstring(String str,
String strSearch,
String strReplace)
Given a String, find all instances of the specified substring and replace it with the specified String. |
static String |
reverseInterpretEscapeSequence(byte b)
Convert non-printing characters into their escape sequence equivalents. |
static String |
reverseInterpretEscapeSequence(char ch)
Convert non-printing characters into their escape sequence equivalents. |
static String |
reverseInterpretString(String str)
Convert all non-printing characters in the specified String into their escape sequence equivalents. |
static void |
setFoldLength(int val)
Set the number of spaces to fold on. |
static void |
setFoldTokens(String tokens)
Set the tokens to fold text on. |
static String |
spaces(int len)
Return a String full of spaces, up to 80. |
static String |
toString(BasicStroke bstk)
Convert a BasicStroke object into a String. |
static String |
toString(boolean[] array)
Turn this array into something suitable for printing. |
static String |
toString(byte[] array)
Turn this array into something suitable for printing. |
static String |
toString(char[] array)
Turn this array into something suitable for printing. |
static String |
toString(double[] array)
Turn this array into something suitable for printing. |
static String |
toString(Ellipse2D ellipse)
Print out an ellipse. |
static String |
toString(Enumeration enum)
Turn this Enumeration into something suitable for printing. |
static String |
toString(float[] array)
Turn this array into something suitable for printing. |
static String |
toString(int[] array)
Turn this array into something suitable for printing. |
static String |
toString(Iterator it)
Turn this Iterator into something suitable for printing. |
static String |
toString(long[] array)
Turn this array into something suitable for printing. |
static String |
toString(MouseEvent evt)
|
static String |
toString(Object obj)
|
static String |
toString(Object[] array)
Turn this array into something suitable for printing. |
static String |
toString(PathIterator it)
Convert a path iterator into a human readable string. |
static String |
toString(Polygon poly)
This is because polygon is stupid. |
static String |
toString(Rectangle2D rect)
Print out a Rectangle decently. |
static String |
toString(short[] array)
Turn this array into something suitable for printing. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static int DEFAULT_FOLD_LENGTH
public static String SPACES
public static String foldtokens
public static int foldLength
Method Detail |
public static void setFoldTokens(String tokens)
tokens
- is a String containing each of the characters to fold on.public static void setFoldLength(int val)
val
- is the number of spaces to fold on.public static String padAtFront(String str, int len)
public static String padAtEnd(String str, int len)
public static int getNumRows(String str)
str
- is the String whose rows we will count.getNumRows(java.lang.String, int)
public static int getNumRows(String str, int numCols)
str
- is the String whose rows we will count.numCols
- is the number of columns (chars / row) to layout on.getNumRows(java.lang.String)
public static int getMaxNumCols(String str, String eoln)
str
- is the String whose max columns we will count.eoln
- specifies what the end-of-line is. Should be either
"\n" or "\r\n".public static int getMaxNumCols(String str, String eoln, int numCols)
str
- is the String whose max columns we will count.eoln
- specifies what the end-of-line is. Should be either
"\n" or "\r\n".numCols
- is the number of columns (chars / row) to layout on.getMaxNumCols(java.lang.String, java.lang.String)
public static int getMaxNumCols(String str)
str
- is the String whose max columns we will count.getMaxNumCols(java.lang.String, java.lang.String)
public static int getMaxNumCols(String str, int numCols)
str
- is the String whose max columns we will count.numCols
- is the number of columns (chars / row) to layout on.getMaxNumCols(java.lang.String, java.lang.String)
public static String fold(Object obj1, Object obj2)
strPrefix
- is the description line.strText
- is the text to fold.setFoldTokens(java.lang.String)
,
fold(java.lang.String, java.lang.String, java.lang.String, int)
public static String fold(String strText, int numCols)
strText
- is the text to fold.numCols
- is the max number of characters per line.setFoldTokens(java.lang.String)
,
setFoldLength(int)
,
fold(java.lang.String, java.lang.String, java.lang.String, int)
public static String fold(String strPrefix, String strText, int numCols)
strPrefix
- is the description line to prepend to every new line.strText
- is the text to fold.numCols
- is the max number of characters per line.setFoldTokens(java.lang.String)
,
setFoldLength(int)
,
fold(java.lang.String, java.lang.String, java.lang.String, int)
public static String fold(String strPrefix, String strText)
strPrefix
- is the description line to prepend to every new line.strText
- is the text to fold.setFoldTokens(java.lang.String)
,
setFoldLength(int)
,
fold(java.lang.String, java.lang.String, java.lang.String, int)
public static String fold(String strPrefix, String strText, String eoln, int numCols)
Estragon: Would you like a radish? It would help pass the time.
strPrefix
- is the description line to prepend to every new line.strText
- is the text to fold.eoln
- is the end-of-line character to append.numCols
- is the max number of characters per line.setFoldTokens(java.lang.String)
public static final String align(String str, char ch)
Date: 08/02/1999 Name: John Occupation: Programmer Address: blah...into...
Date: 08/02/1999 Name: John Occupation: Programmer Address: blah
public static boolean containsChars(String str, String strChars)
str
- is the String to look through.strChars
- is the set of characters to look for in str.public static boolean containsChars(String str, char[] chars)
str
- is the String to look through.chars
- is the set of characters to look for in str.public boolean isDecimalNumber(String str)
str
- is the String to check.public static String interpretString(String str)
For example, given the String "\r\n" which has 4 characters, convert it into a String containing the interpreted meanings of '\r' and '\n' with 2 characters.
str
- is the String containing the escape sequences to interpret.public static char interpretEscapeSequence(String str)
str
- is a String containing an escape sequence.public static String reverseInterpretString(String str)
str
- is the String that might contain some escape characters.public static String reverseInterpretEscapeSequence(byte b)
b
- is a byte that might be an escape sequence character.public static String reverseInterpretEscapeSequence(char ch)
ch
- is the character that might be an escape sequence character.public static int countNumOfChar(char chSearch, String strLine)
chSearch
- is the character to search for.strLine
- is the String to search through.public static int countNumOfString(String strSearch, String strLine)
strSearch
- is the String to search for.strLine
- is the String to search through.public static String getBarredLine(char ch)
public static String getBarredLine(String strText, char ch)
=== example =========...where the line is exactly 80 chars long.
public static String spaces(int len)
len
- is the number of spaces to return.public static String removeSubstring(char chFrom, char chTo, String strLine)
chFrom
- is the character to start deleting from.chTo
- is the character to end deleting.strLine
- is the String to remove characters from.public static String replaceSubstring(String str, String strSearch, String strReplace)
str
- is the String to search through.strSearch
- is the non-empty String to search for.strReplace
- is the String to replace strSearch with.public static String indent(String str, int spaces)
str
- is the String to push over.spaces
- is the number of spaces to indent.public static final String toString(Object obj)
public static final String toString(MouseEvent evt)
public static final String toString(Iterator it)
public static final String toString(Enumeration enum)
public static final String toString(Object[] array)
public static final String toString(boolean[] array)
public static final String toString(char[] array)
public static final String toString(byte[] array)
public static final String toString(short[] array)
public static final String toString(int[] array)
public static final String toString(long[] array)
public static final String toString(float[] array)
public static final String toString(double[] array)
public static final String toString(Rectangle2D rect)
public static final String toString(Polygon poly)
public static final String toString(Ellipse2D ellipse)
public static String getSegmentType(int val)
PathIterator
, return a String with the
kind of segment.public static final String toString(PathIterator it)
public static final String toString(BasicStroke bstk)
public static void main(String[] argv) throws Exception
|
Copyright Information | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |