de.unkrig.commons.text.scanner
Class ScannerUtil

java.lang.Object
  extended by de.unkrig.commons.text.scanner.ScannerUtil

public final class ScannerUtil
extends java.lang.Object

Various scanner-related utility methods.


Field Summary
static int UNESCAPE_DOUBLE_QUOTE
          If set, \" escapes to a double quote, otherwise it is an invalid escape sequence.
static int UNESCAPE_NUL
          If set, "\023" escapes to '\0', '2', '3', otherwise, if 16, it escapes to '#', otherwise, it is an invalid escape sequence.
static int UNESCAPE_OCTAL
          If set, "\123" escapes to "S", otherwise it is an invalid escape sequence (but see UNESCAPE_NUL).
static int UNESCAPE_SINGLE_QUOTE
          If set, \' escapes to a single quote, otherwise it is an invalid escape sequence.
static int UNESCAPE_UNICODE
          If set, "\uxxxx" escapes to the unicode character 'xxxx', otherwise it is an invalid escape sequence.
 
Method Summary
static
<T,EX extends java.lang.Throwable>
ProducerWhichThrows<T,EX>
augmentScanningLocation(ProducerWhichThrows<T,EX> delegate, java.lang.String prefix)
           
static
<TT extends java.lang.Enum<TT>>
StringScanner<TT>
filter(StringScanner<TT> delegate, Predicate<AbstractScanner.Token<TT>> predicate)
           
static
<TT extends java.lang.Enum<TT>>
ProducerWhichThrows<AbstractScanner.Token<TT>,ScanException>
scanner(StringScanner<TT> stringScanner, java.io.File file, java.nio.charset.Charset charset)
          Uses a given StringScanner to scan the contents of a given file.
static
<TT extends java.lang.Enum<TT>>
DocumentScanner<TT>
toDocumentScanner(StringScanner<TT> stringScanner, java.io.Reader reader)
          Converts the StringScanner, which reads from a CharSequence into a DocumentScanner, which reads from a Reader and thinks in "line numbers" and "column numbers").
static java.lang.String unescape(java.lang.String s, int options)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

UNESCAPE_NUL

public static final int UNESCAPE_NUL
If set, "\023" escapes to '\0', '2', '3', otherwise, if 16, it escapes to '#', otherwise, it is an invalid escape sequence.

See Also:
unescape(String, int), Constant Field Values

UNESCAPE_DOUBLE_QUOTE

public static final int UNESCAPE_DOUBLE_QUOTE
If set, \" escapes to a double quote, otherwise it is an invalid escape sequence.

See Also:
unescape(String, int), Constant Field Values

UNESCAPE_SINGLE_QUOTE

public static final int UNESCAPE_SINGLE_QUOTE
If set, \' escapes to a single quote, otherwise it is an invalid escape sequence.

See Also:
unescape(String, int), Constant Field Values

UNESCAPE_UNICODE

public static final int UNESCAPE_UNICODE
If set, "\uxxxx" escapes to the unicode character 'xxxx', otherwise it is an invalid escape sequence.

See Also:
unescape(String, int), Constant Field Values

UNESCAPE_OCTAL

public static final int UNESCAPE_OCTAL
If set, "\123" escapes to "S", otherwise it is an invalid escape sequence (but see UNESCAPE_NUL).

See Also:
unescape(String, int), Constant Field Values
Method Detail

toDocumentScanner

public static <TT extends java.lang.Enum<TT>> DocumentScanner<TT> toDocumentScanner(StringScanner<TT> stringScanner,
                                                                                    java.io.Reader reader)
Converts the StringScanner, which reads from a CharSequence into a DocumentScanner, which reads from a Reader and thinks in "line numbers" and "column numbers").

IOExceptions thrown by the Reader are wrapped in ScanExceptions.


scanner

public static <TT extends java.lang.Enum<TT>> ProducerWhichThrows<AbstractScanner.Token<TT>,ScanException> scanner(StringScanner<TT> stringScanner,
                                                                                                                   java.io.File file,
                                                                                                                   java.nio.charset.Charset charset)
                                                                                                       throws java.io.FileNotFoundException
Uses a given StringScanner to scan the contents of a given file.

Parameters:
charset - E.g. Charset.forName(String) or Charset.defaultCharset()
Throws:
java.io.FileNotFoundException
See Also:
toDocumentScanner(StringScanner, Reader)

augmentScanningLocation

public static <T,EX extends java.lang.Throwable> ProducerWhichThrows<T,EX> augmentScanningLocation(ProducerWhichThrows<T,EX> delegate,
                                                                                                   @Nullable
                                                                                                   java.lang.String prefix)
Returns:
A Producer who's Object.toString() method prepends the given prefix, a colon and a space to the string returned by the delegate's Object.toString() method

filter

public static <TT extends java.lang.Enum<TT>> StringScanner<TT> filter(StringScanner<TT> delegate,
                                                                       Predicate<AbstractScanner.Token<TT>> predicate)
Returns:
A StringScanner which produces tokens through a delegate, but only those for which the predicate returns true

unescape

public static java.lang.String unescape(java.lang.String s,
                                        int options)
                                 throws ScanException
Returns:
The input string, unescaped according to the rules defined in JLS7
Throws:
ScanException - s contains control characters
ScanException - \\ is not followed by exactly four hex digits
ScanException - A backslash is not followed by an allowed character
ScanException - s ends in the middle of an escape sequence
See Also:
UNESCAPE_NUL, UNESCAPE_DOUBLE_QUOTE, UNESCAPE_SINGLE_QUOTE, UNESCAPE_UNICODE, UNESCAPE_OCTAL