Skip to content

Commit

Permalink
(yegor256#1462) Use text.Mapped
Browse files Browse the repository at this point in the history
  • Loading branch information
andreoss committed Oct 16, 2020
1 parent 637ecf4 commit a5ebafd
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/main/java/org/cactoos/text/Replaced.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ public final class Replaced extends TextEnvelope {
public Replaced(
final Text text,
final String find,
final String replace) {
final String replace
) {
this(text, () -> Pattern.compile(find), matcher -> replace);
}

Expand Down Expand Up @@ -81,12 +82,13 @@ public Replaced(
public Replaced(
final Text text,
final Scalar<Pattern> regex,
final Func<Matcher, String> func) {
final Func<Matcher, String> func
) {
super(
new TextOf(
() -> {
new Mapped(
str -> {
final StringBuffer buffer = new StringBuffer();
final Matcher matcher = regex.value().matcher(text.asString());
final Matcher matcher = regex.value().matcher(str);
while (matcher.find()) {
matcher.appendReplacement(
buffer,
Expand All @@ -95,7 +97,8 @@ public Replaced(
}
matcher.appendTail(buffer);
return buffer.toString();
}
},
text
)
);
}
Expand Down

0 comments on commit a5ebafd

Please sign in to comment.