public final class ScannerUtil extends Object
Modifier and Type | Field and Description |
---|---|
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. |
Modifier and Type | Method and Description |
---|---|
static <T,EX extends Throwable> |
augmentScanningLocation(ProducerWhichThrows<? extends T,? extends EX> delegate,
String prefix) |
static <TT extends Enum<TT>> |
filter(StringScanner<TT> delegate,
Predicate<? super AbstractScanner.Token<TT>> predicate) |
static <TT extends Enum<TT>> |
scanner(StringScanner<TT> stringScanner,
File file,
Charset charset)
Uses a given
StringScanner to scan the contents of a given file. |
static <TT extends Enum<TT>> |
toDocumentScanner(StringScanner<TT> stringScanner,
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 String |
unescape(String s,
int options) |
public static final int UNESCAPE_NUL
"\023"
escapes to '\0', '2', '3'
, otherwise, if 16, it escapes to
'#'
, otherwise, it is an invalid escape sequence.unescape(String, int)
,
Constant Field Valuespublic static final int UNESCAPE_DOUBLE_QUOTE
\"
escapes to a double quote, otherwise it is an invalid escape sequence.unescape(String, int)
,
Constant Field Valuespublic static final int UNESCAPE_SINGLE_QUOTE
\'
escapes to a single quote, otherwise it is an invalid escape sequence.unescape(String, int)
,
Constant Field Valuespublic static final int UNESCAPE_UNICODE
"\uxxxx"
escapes to the unicode character 'xxxx', otherwise it is an
invalid escape sequence.unescape(String, int)
,
Constant Field Valuespublic static final int UNESCAPE_OCTAL
"\123"
escapes to "S", otherwise it is an invalid escape sequence (but see UNESCAPE_NUL
).unescape(String, int)
,
Constant Field Valuespublic static <TT extends Enum<TT>> DocumentScanner<TT> toDocumentScanner(StringScanner<TT> stringScanner, Reader reader)
StringScanner
, which reads from a CharSequence
into a DocumentScanner
,
which reads from a Reader
and thinks in "line numbers" and "column numbers").
IOException
s thrown by the Reader
are wrapped in ScanException
s.
public static <TT extends Enum<TT>> ProducerWhichThrows<AbstractScanner.Token<TT>,ScanException> scanner(StringScanner<TT> stringScanner, File file, Charset charset) throws FileNotFoundException
StringScanner
to scan the contents of a given file.charset
- E.g. Charset.forName(String)
or Charset.defaultCharset()
FileNotFoundException
toDocumentScanner(StringScanner, Reader)
public static <T,EX extends Throwable> ProducerWhichThrows<T,EX> augmentScanningLocation(ProducerWhichThrows<? extends T,? extends EX> delegate, @Nullable String prefix)
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()
methodpublic static <TT extends Enum<TT>> StringScanner<TT> filter(StringScanner<TT> delegate, Predicate<? super AbstractScanner.Token<TT>> predicate)
StringScanner
which produces tokens through a delegate, but only those for which
the predicate returns true
public static String unescape(String s, int options) throws ScanException
ScanException
- s contains control charactersScanException
- \\
is not followed by exactly four hex digitsScanException
- A backslash is not followed by an allowed characterScanException
- s ends in the middle of an escape sequenceUNESCAPE_NUL
,
UNESCAPE_DOUBLE_QUOTE
,
UNESCAPE_SINGLE_QUOTE
,
UNESCAPE_UNICODE
,
UNESCAPE_OCTAL
Copyright © 2018 Arno Unkrig. All rights reserved.