summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorQuentin <quentin@open-to-repair.fr>2016-04-18 19:31:42 +0200
committerFlorian Zschocke <f.zschocke+git@gmail.com>2022-08-02 22:10:17 +0200
commitcafdb31692aea6a5a8792d99720acdd4746a19fb (patch)
tree5c373ecc0573aa2dbf76b6eb77db64d06a9d127c
parentd6f6ac3d3f214ff648aa92e4c5c6d8500db6b244 (diff)
downloadgitblit-cafdb31692aea6a5a8792d99720acdd4746a19fb.tar.gz
gitblit-cafdb31692aea6a5a8792d99720acdd4746a19fb.zip
Changed tab to space conversion
Tabs are not always 4 spaces large. It completes the line to the 4th character.
-rw-r--r--src/main/java/com/gitblit/utils/StringUtils.java9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/main/java/com/gitblit/utils/StringUtils.java b/src/main/java/com/gitblit/utils/StringUtils.java
index 442acbbf..7c4eef8b 100644
--- a/src/main/java/com/gitblit/utils/StringUtils.java
+++ b/src/main/java/com/gitblit/utils/StringUtils.java
@@ -105,6 +105,8 @@ public class StringUtils {
public static String escapeForHtml(String inStr, boolean changeSpace, int tabLength) {
StringBuilder retStr = new StringBuilder();
int i = 0;
+ int l = 0;
+
while (i < inStr.length()) {
if (inStr.charAt(i) == '&') {
retStr.append("&amp;");
@@ -117,12 +119,17 @@ public class StringUtils {
} else if (changeSpace && inStr.charAt(i) == ' ') {
retStr.append("&nbsp;");
} else if (changeSpace && inStr.charAt(i) == '\t') {
- for (int j = 0; j < tabLength; j++) {
+ for (int j = 0; j < tabLength - l; j++) {
retStr.append("&nbsp;");
}
+ l = -1;
} else {
retStr.append(inStr.charAt(i));
}
+
+ l = (l + 1) % tabLength;
+ if (inStr.charAt(i) == '\n')
+ l = 0;
i++;
}
return retStr.toString();