Package app.babylon.text
Interface SliceParser<T>
- Type Parameters:
T- the parsed value type
- All Superinterfaces:
Function<CharSequence,T>
- All Known Subinterfaces:
TypeParser<T>
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
Parses a slice of character data without requiring callers to materialize a
String or create a CharSequence view first.
Any method with the same shape can bind directly as a method reference. For
example, Currencys.parse(CharSequence, int, int) can be used wherever
a SliceParser<Currency> is expected:
Currency currency = Sentence.firstIn(Currencys::parse, "pay USD 120 tomorrow");
-
Method Summary
Modifier and TypeMethodDescriptiondefault Tstatic <T> SliceParser<T> from(Function<CharSequence, T> parser) Adapts an existing whole-sequence parser.default TParses the whole character sequence.parse(CharSequence s, int start, int end) Parses a slice ofs.
-
Method Details
-
parse
Parses a slice ofs.- Parameters:
s- the source charactersstart- the first character in the sliceend- one past the last character in the slice- Returns:
- the parsed value, or
nullwhen parsing fails
-
parse
Parses the whole character sequence. -
apply
- Specified by:
applyin interfaceFunction<CharSequence,T>
-
from
Adapts an existing whole-sequence parser. This compatibility path may create aCharSequence.subSequence(int, int)view for sliced inputs; parsers that can consume start/end bounds directly should implementparse(CharSequence, int, int)instead.
-