Package app.babylon.text
Class Sentence
java.lang.Object
app.babylon.text.Sentence
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> TfirstIn(SliceParser<T> parser, CharSequence sentence) Finds the first parsed value in a space-separated sentence.static <T> TlastIn(SliceParser<T> parser, String sentence) Finds the last parsed value in a space-separated sentence.static <T> TlastIn(SliceParser<T> parser, String sentence, char separator) Finds the last parsed value in a sentence separated byseparator.static <T> TonlyIn(SliceParser<T> parser, CharSequence sentence) Finds the only parsed value in a space-separated sentence, ornullwhen no value or multiple values are found.
-
Constructor Details
-
Sentence
public Sentence()
-
-
Method Details
-
firstIn
Finds the first parsed value in a space-separated sentence.Parsers with a
parse(CharSequence, int, int)shape bind directly toSliceParser, so callers can scan sentence words without materialising intermediate strings:Currency currency = Sentence.firstIn(Currencys::parse, "pay USD 120 tomorrow"); Currency typed = Sentence.firstIn(TypeParsers.CURRENCY, "pay USD 120 tomorrow");
TypeParserimplementations can be used here too because they extendSliceParser. -
lastIn
Finds the last parsed value in a space-separated sentence.For example, this finds the last currency in a sentence:
Currency currency = Sentence.lastIn(Currencys::parse, "pay USD or EUR tomorrow"); Currency typed = Sentence.lastIn(TypeParsers.CURRENCY, "pay USD or EUR tomorrow");
The parser receives the original sentence plus each word's start and length, avoiding intermediate strings.
-
lastIn
Finds the last parsed value in a sentence separated byseparator.The parser receives the original sentence plus each field's start and length, avoiding intermediate strings.
-
onlyIn
Finds the only parsed value in a space-separated sentence, ornullwhen no value or multiple values are found.The name is short for "find the only currency in this sentence":
Currency currency = Sentence.onlyIn(Currencys::parse, "pay USD tomorrow"); Currency typed = Sentence.onlyIn(TypeParsers.CURRENCY, "pay USD tomorrow");
The parser receives the original sentence plus each word's start and length, avoiding intermediate strings.
-