mirror of
https://github.com/java-diff-utils/java-diff-utils.git
synced 2026-03-13 10:11:17 +08:00
Fix the wrap method in StringUtills. Now it wraps correctly the long texts.
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package difflib;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
public class StringUtills {
|
||||
|
||||
@@ -44,10 +46,23 @@ public class StringUtills {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrap the text with the given column width
|
||||
* @param line the text
|
||||
* @param columnWidth the given column
|
||||
* @return the wrapped text
|
||||
*/
|
||||
public static String wrapText(String line, int columnWidth) {
|
||||
if (line.length() > columnWidth) {
|
||||
return line.subSequence(0, columnWidth) + "<br>" + line.substring(columnWidth);
|
||||
int lenght = line.length();
|
||||
int delimiter = "<br>".length();
|
||||
int widthIndex = columnWidth;
|
||||
|
||||
for (int count = 0; lenght > widthIndex; count++) {
|
||||
line = line.subSequence(0, widthIndex + delimiter * count) + "<br>"
|
||||
+ line.substring(widthIndex + delimiter * count);
|
||||
widthIndex += columnWidth;
|
||||
}
|
||||
|
||||
return line;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user