xtc.util
Class Utilities

java.lang.Object
  extended by xtc.util.Utilities

public final class Utilities
extends java.lang.Object

Implementation of utilities for language processors, focusing on strings and I/O.

Version:
$Revision: 1.48 $
Author:
Robert Grimm

Field Summary
static int C_ESCAPES
          The escape flags for standard C escapes.
static java.util.regex.Pattern COMMENT_NEWLINE
          The regular expression pattern for newlines surrounded by spaces and optionally followed by stars '*'.
static int ESCAPE_BELL_VT
          Flag for escaping the bell '\a' and vertical tab '\v' characters, which may be escaped in standard C but not in Java.
static int ESCAPE_DOUBLE
          Flag for using doubled escape sequences.
static int ESCAPE_HTML
          Flag for escaping less-than '<' and greater-than '>' signs as HTML entities.
static int ESCAPE_REGEX
          Flag for escaping the '[', '-', and ']' characters used in regular expressions.
static int ESCAPE_UNICODE
          Flag for escaping all characters that neither are printable ASCII characters nor have named escapes using Unicode escapes.
static int FULL_ESCAPES
          The escape flags for Java and regex escapes.
static int FULL_HTML_ESCAPES
          The escape flags for Java, regex, and HTML escapes.
static int JAVA_ESCAPES
          The escape flags for Java escapes.
static int JAVA_HTML_ESCAPES
          The escape flags for Java and HTML escapes.
static java.util.regex.Pattern SPACE_NEWLINE_SPACE
          The regular expression pattern for newlines surrounded by spaces.
static java.util.regex.Pattern WHITE_SPACE
          The regular expression pattern for white space.
 
Method Summary
static void escape(char c, java.lang.Appendable out, int flags)
          Escape the specified character into the specified appendable.
static java.lang.String escape(char c, int flags)
          Escape the specified character.
static void escape(java.lang.String s, java.lang.Appendable out, int flags)
          Escape the specified string into the specified appendable.
static java.lang.String escape(java.lang.String s, int flags)
          Escape the specified string.
static java.lang.String format(java.util.List<?> l)
          Convert the specified list to a human-readable representation.
static java.io.File locate(java.util.List<java.io.File> roots, java.lang.String path)
          Locate the specified file.
static void pump(java.io.Reader in, java.io.Writer out)
          Pump all data from the specified reader to the specified writer.
static java.lang.String split(java.lang.String id, char separator)
          Split the specified identifier.
static java.lang.String toArticle(java.lang.String noun)
          Get the appropriate indefinite article for the specified noun.
static java.lang.String unescape(java.lang.String s)
          Unescape the specified string.
static boolean useBellVTEscapes(int flags)
          Determine whether the escape bell and vertical tabs flag is set.
static boolean useDoubleEscapes(int flags)
          Determine whether the escape double flag is set.
static boolean useHTMLEscapes(int flags)
          Determine whether the escape HTML flag is set.
static boolean useRegexEscapes(int flags)
          Determine whether the escape regex flag is set.
static boolean useUnicodeEscapes(int flags)
          Determine whether the escape Unicode flag is set.
static java.lang.String withoutSpace(java.lang.String s)
          Remove all whitespace from the specified string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

WHITE_SPACE

public static final java.util.regex.Pattern WHITE_SPACE
The regular expression pattern for white space.


SPACE_NEWLINE_SPACE

public static final java.util.regex.Pattern SPACE_NEWLINE_SPACE
The regular expression pattern for newlines surrounded by spaces.


COMMENT_NEWLINE

public static final java.util.regex.Pattern COMMENT_NEWLINE
The regular expression pattern for newlines surrounded by spaces and optionally followed by stars '*'.


ESCAPE_BELL_VT

public static final int ESCAPE_BELL_VT
Flag for escaping the bell '\a' and vertical tab '\v' characters, which may be escaped in standard C but not in Java.

See Also:
Constant Field Values

ESCAPE_DOUBLE

public static final int ESCAPE_DOUBLE
Flag for using doubled escape sequences. Doubled escape sequences will still read as an escape sequence, even if they are included in a program source character or string.

See Also:
Constant Field Values

ESCAPE_REGEX

public static final int ESCAPE_REGEX
Flag for escaping the '[', '-', and ']' characters used in regular expressions.

See Also:
Constant Field Values

ESCAPE_UNICODE

public static final int ESCAPE_UNICODE
Flag for escaping all characters that neither are printable ASCII characters nor have named escapes using Unicode escapes.

See Also:
Constant Field Values

ESCAPE_HTML

public static final int ESCAPE_HTML
Flag for escaping less-than '<' and greater-than '>' signs as HTML entities.

See Also:
Constant Field Values

C_ESCAPES

public static final int C_ESCAPES
The escape flags for standard C escapes.

See Also:
Constant Field Values

JAVA_ESCAPES

public static final int JAVA_ESCAPES
The escape flags for Java escapes.

See Also:
Constant Field Values

JAVA_HTML_ESCAPES

public static final int JAVA_HTML_ESCAPES
The escape flags for Java and HTML escapes.

See Also:
Constant Field Values

FULL_ESCAPES

public static final int FULL_ESCAPES
The escape flags for Java and regex escapes.

See Also:
Constant Field Values

FULL_HTML_ESCAPES

public static final int FULL_HTML_ESCAPES
The escape flags for Java, regex, and HTML escapes.

See Also:
Constant Field Values
Method Detail

locate

public static java.io.File locate(java.util.List<java.io.File> roots,
                                  java.lang.String path)
                           throws java.io.FileNotFoundException
Locate the specified file. This method searches for the specified file, relative to each root in the list of java.io.File objects.

Parameters:
roots - The list of file system roots to search.
path - The (relative) file path.
Returns:
The corresponding file.
Throws:
java.io.FileNotFoundException - Signals that the specified file could not be found.

pump

public static void pump(java.io.Reader in,
                        java.io.Writer out)
                 throws java.io.IOException
Pump all data from the specified reader to the specified writer.

Parameters:
in - The reader.
out - The writer.
Throws:
java.io.IOException - Signals an exceptinal condition during I/O.

withoutSpace

public static java.lang.String withoutSpace(java.lang.String s)
Remove all whitespace from the specified string.

Parameters:
s - The string.
Returns:
The string without whitespace.

useBellVTEscapes

public static boolean useBellVTEscapes(int flags)
Determine whether the escape bell and vertical tabs flag is set.

Parameters:
flags - The escape flags.
Returns:
true if the escape bell and vertical tabs flag is set.
See Also:
ESCAPE_BELL_VT

useDoubleEscapes

public static boolean useDoubleEscapes(int flags)
Determine whether the escape double flag is set.

Parameters:
flags - The escape flags.
Returns:
true if the escape double flag is set.
See Also:
ESCAPE_DOUBLE

useRegexEscapes

public static boolean useRegexEscapes(int flags)
Determine whether the escape regex flag is set.

Parameters:
flags - The escape flags.
Returns:
true if the escape regex flag is set.
See Also:
ESCAPE_REGEX

useUnicodeEscapes

public static boolean useUnicodeEscapes(int flags)
Determine whether the escape Unicode flag is set.

Parameters:
flags - The escape flags.
Returns:
true if the escape Unicode flag is set.
See Also:
ESCAPE_UNICODE

useHTMLEscapes

public static boolean useHTMLEscapes(int flags)
Determine whether the escape HTML flag is set.

Parameters:
flags - The escape flags.
Returns:
true if the escape HTML flag is set.
See Also:
ESCAPE_HTML

escape

public static void escape(char c,
                          java.lang.Appendable out,
                          int flags)
                   throws java.io.IOException
Escape the specified character into the specified appendable.

Parameters:
c - The character.
out - The appendable.
flags - The escape flags.
Throws:
java.io.IOException - Signals an I/O error.

escape

public static void escape(java.lang.String s,
                          java.lang.Appendable out,
                          int flags)
                   throws java.io.IOException
Escape the specified string into the specified appendable.

Parameters:
s - The string.
out - The appendable.
flags - The escape flags.
Throws:
java.io.IOException - Signals an I/O error.

escape

public static java.lang.String escape(char c,
                                      int flags)
Escape the specified character.

Parameters:
c - The character.
flags - The escape flags.
Returns:
The escape character as a string.

escape

public static java.lang.String escape(java.lang.String s,
                                      int flags)
Escape the specified string.

Parameters:
s - The string.
flags - The escape flags.
Returns:
The escaped string.

unescape

public static java.lang.String unescape(java.lang.String s)
Unescape the specified string. This method unescapes basic Java escapes ('\b', '\f', '\n', '\r', '\t', '\"', '\'', and '\\'), the additional standard C escapes ('\a', '\v', and '\?'), standard C's octal escapes, and standard C's and Java's Unicode escapes. To support regex-like character classes, it also unescapes '\-', '\[', and '\]'.

Parameters:
s - The string to unescape.
Returns:
The unescaped string.
Throws:
java.lang.IllegalArgumentException - Signals a malformed string.

format

public static java.lang.String format(java.util.List<?> l)
Convert the specified list to a human-readable representation. This method uses toString() for each element in the specified list to generate a human-readable representation.

Parameters:
l - The list.
Returns:
The human-readable representation.

split

public static java.lang.String split(java.lang.String id,
                                     char separator)
Split the specified identifier. This method splits identifiers using an upper case character for each word component into a string of lower case words separated by the specified separator.

Parameters:
id - The identifier.
separator - The separator.
Returns:
The split identifier.

toArticle

public static java.lang.String toArticle(java.lang.String noun)
Get the appropriate indefinite article for the specified noun.

Parameters:
noun - The noun.
Returns:
The corresponding indefinite article.


Copyright © 2012. All Rights Reserved.