PROTOTYPE
Not reviewed yet: use at your own risk!

satin.common
Class StringUtils

java.lang.Object
  |
  +--satin.common.StringUtils

public abstract class StringUtils
extends java.lang.Object

Miscellaneous string utility functions that weren't included in Java's String class.

Author:
Ed Stauff

Constructor Summary
StringUtils()
           
 
Method Summary
static java.lang.String replace(java.lang.String original, java.lang.String oldStr, java.lang.String newStr)
          Replaces all instances of 'oldStr' in 'original' with 'newStr'.
static java.lang.String toJavaLiteral(char c)
          Converts a char to a Java literal that represents it.
static java.lang.String toJavaLiteral(java.lang.String s)
          Converts a string to a Java literal that represents it.
static java.lang.String wordWrap(java.lang.String input, int maxColumns, java.lang.String prefix)
          Word-wraps a string to fit in the given number of columns.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StringUtils

public StringUtils()
Method Detail

replace

public static java.lang.String replace(java.lang.String original,
                                       java.lang.String oldStr,
                                       java.lang.String newStr)
Replaces all instances of 'oldStr' in 'original' with 'newStr'. If no instances are found, 'original' is returned unchanged.

Parameters:
original
the string to be changed.
oldStr
the sub-string to look for and replace.
newStr
the replacement sub-string.
Returns:
the modified copy of 'original'.

toJavaLiteral

public static java.lang.String toJavaLiteral(java.lang.String s)
Converts a string to a Java literal that represents it. The resulting string is quoted, and all control characters are escaped. This is useful for printing strings in error messages and log files. For example, consider the following code fragment:

String s = "Hello, world!\n" + "\tGoodbye, world!";
System.out.println(s);
System.out.println(StringUtils.toJavaLiteral(s));

This code would produce the following output:

Hello, world!
        Goodbye, world!
"Hello, world!\n\tGoodbye, world!"

This method does not handle Unicode characters.

Parameters:
s
the string to convert
Returns:
a string containing the Java string literal

toJavaLiteral

public static java.lang.String toJavaLiteral(char c)
Converts a char to a Java literal that represents it. The resulting string is quoted, and all control characters are escaped. This method does not handle Unicode characters.

Parameters:
c
the char to convert
Returns:
a string containing the Java string literal

wordWrap

public static java.lang.String wordWrap(java.lang.String input,
                                        int maxColumns,
                                        java.lang.String prefix)
Word-wraps a string to fit in the given number of columns.

Parameters:
input
the string to be word-wrapped.
maxColumns
the maximum number of columns; i.e. the maximum number of characters per line.
prefix
a string to prepend to the beginning of each line, or null.
Revision History

7/23/01 Andrew Griffin - added overloaded toJavaLiteral(char c) (not reviewed yet).

7/18/01 Ed Stauff - added wordWrap (not reviewed yet).

6/26/01 Ed Stauff - added toJavaLiteral (not reviewed yet).

5/31/01 Ed Stauff - made changes to docs per initial code review.

3/26/01 Ed Stauff - improved description of replace.

3/21/01 Ed Stauff - initial version reviewed by automation team.



Generated on 5/9/2001 19:37 from StringUtils.java (PRIVATE SOURCES)