Skip to content

Commit

Permalink
(yegor256#1704) Fix bug related to 80-character limit
Browse files Browse the repository at this point in the history
  • Loading branch information
fabriciofx committed Jan 18, 2024
1 parent bd221db commit c3f3b2f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
16 changes: 8 additions & 8 deletions src/main/java/org/cactoos/text/Multiline.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,14 @@ public Multiline(final Text text, final int limit) {
Multiline.SPLIT_REGEX
);
final StringBuilder lines = new StringBuilder();
final StringBuilder word = new StringBuilder(0);
final StringBuilder line = new StringBuilder(0);
int length = 0;
for (int idx = 0; idx < words.length; ++idx) {
word.setLength(0);
word.append(words[idx]);
line.setLength(0);
line.append(words[idx]);
final int size = Multiline.SPACE.length()
+ word.length();
if (length + size > limit) {
+ line.length();
if (length + size > limit + 1) {
if (idx > 0) {
lines.append(Multiline.NEW_LINE);
}
Expand All @@ -123,10 +123,10 @@ public Multiline(final Text text, final int limit) {
&& length + size + words[idx + 1].length()
<= limit
) {
word.append(Multiline.SPACE);
line.append(Multiline.SPACE);
}
lines.append(word);
length = length + word.length();
lines.append(line);
length = length + line.length();
}
return new IteratorOf<>(
lines.toString().split(Multiline.NEW_LINE)
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/org/cactoos/text/MultilineTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ void multilineTextBiggerThanDefaultLimit() {
new Joined(
" ",
"The quick brown fox jumps over the lazy",
"black dog and after that returned to "
"black dog and after that returned to the"
),
new TextOf("the cave")
new TextOf("cave")
)
)
).affirm();
Expand Down

0 comments on commit c3f3b2f

Please sign in to comment.