Skip to content
This repository was archived by the owner on Nov 12, 2019. It is now read-only.

Commit 10a2d85

Browse files
author
dm.naumenko@gmail.com
committed
Fix the wrap method in StringUtills. Now it wraps correctly the long texts.
git-svn-id: http://java-diff-utils.googlecode.com/svn/trunk@5 d8d7d024-a22d-11de-b755-fd640f38fa9d
1 parent 32d6a50 commit 10a2d85

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

src/difflib/StringUtills.java

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package difflib;
22

3-
import java.util.*;
3+
import java.util.Iterator;
4+
import java.util.LinkedList;
5+
import java.util.List;
46

57
public class StringUtills {
68

@@ -44,10 +46,23 @@ public static List<String> wrapText(List<String> list, int columnWidth) {
4446
return result;
4547
}
4648

49+
/**
50+
* Wrap the text with the given column width
51+
* @param line the text
52+
* @param columnWidth the given column
53+
* @return the wrapped text
54+
*/
4755
public static String wrapText(String line, int columnWidth) {
48-
if (line.length() > columnWidth) {
49-
return line.subSequence(0, columnWidth) + "<br>" + line.substring(columnWidth);
56+
int lenght = line.length();
57+
int delimiter = "<br>".length();
58+
int widthIndex = columnWidth;
59+
60+
for (int count = 0; lenght > widthIndex; count++) {
61+
line = line.subSequence(0, widthIndex + delimiter * count) + "<br>"
62+
+ line.substring(widthIndex + delimiter * count);
63+
widthIndex += columnWidth;
5064
}
65+
5166
return line;
5267
}
5368
}

0 commit comments

Comments
 (0)