From ec63222411bee7d02cc99635c9dab5a7c460682f Mon Sep 17 00:00:00 2001 From: andreoss Date: Tue, 6 Apr 2021 23:43:04 -0400 Subject: [PATCH] (#1579) Add ctors --- src/main/java/org/cactoos/text/PrefixOf.java | 17 +++++++++++++---- src/main/java/org/cactoos/text/SuffixOf.java | 17 +++++++++++++---- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/cactoos/text/PrefixOf.java b/src/main/java/org/cactoos/text/PrefixOf.java index dcff27b57a..8e3199cd8c 100644 --- a/src/main/java/org/cactoos/text/PrefixOf.java +++ b/src/main/java/org/cactoos/text/PrefixOf.java @@ -43,7 +43,7 @@ public final class PrefixOf extends TextEnvelope { * @param text Text representing the text value * @param boundary String to which text will be split */ - public PrefixOf(final CharSequence text, final String boundary) { + public PrefixOf(final CharSequence text, final CharSequence boundary) { this(new TextOf(text), boundary); } @@ -52,13 +52,22 @@ public PrefixOf(final CharSequence text, final String boundary) { * @param text Text representing the text value * @param boundary String to which text will be split */ - public PrefixOf(final Text text, final String boundary) { + public PrefixOf(final Text text, final CharSequence boundary) { + this(text, new TextOf(boundary)); + } + + /** + * Ctor. + * @param text Text representing the text value + * @param boundary String to which text will be split + */ + public PrefixOf(final Text text, final Text boundary) { super( new Flattened( new Ternary<>( new ScalarOf<>(() -> new Sticky(text)), - (Text t) -> t.asString().indexOf(boundary) >= 0, - t -> new Sub(t, 0, s -> s.indexOf(boundary)), + (Text t) -> t.asString().indexOf(boundary.asString()) >= 0, + t -> new Sub(t, 0, s -> s.indexOf(boundary.asString())), t -> t ) ) diff --git a/src/main/java/org/cactoos/text/SuffixOf.java b/src/main/java/org/cactoos/text/SuffixOf.java index 42acaec477..6ee56bde92 100644 --- a/src/main/java/org/cactoos/text/SuffixOf.java +++ b/src/main/java/org/cactoos/text/SuffixOf.java @@ -24,6 +24,7 @@ package org.cactoos.text; import org.cactoos.Text; +import org.cactoos.scalar.LengthOf; import org.cactoos.scalar.ScalarOf; import org.cactoos.scalar.Ternary; @@ -41,7 +42,7 @@ public final class SuffixOf extends TextEnvelope { * @param text Text representing the text value * @param boundary String after which text will be split */ - public SuffixOf(final String text, final String boundary) { + public SuffixOf(final CharSequence text, final CharSequence boundary) { this(new TextOf(text), boundary); } @@ -50,15 +51,23 @@ public SuffixOf(final String text, final String boundary) { * @param text Text representing the text value * @param boundary String after which text will be split */ - public SuffixOf(final Text text, final String boundary) { + public SuffixOf(final Text text, final CharSequence boundary) { + this(text, new TextOf(boundary)); + } + /** + * Ctor. + * @param text Text representing the text value + * @param boundary String after which text will be split + */ + public SuffixOf(final Text text, final Text boundary) { super( new Flattened( new Ternary<>( new ScalarOf<>(() -> new Sticky(text)), - (Text t) -> t.asString().indexOf(boundary) >= 0, + (Text t) -> t.asString().indexOf(boundary.asString()) >= 0, t -> new Sub( t, - s -> s.indexOf(boundary) + boundary.length() + s -> s.indexOf(boundary.asString()) + new LengthOf(boundary).value().intValue() ), t -> new TextOf("") )