Skip to content

Commit cafdb31

Browse files
QuentinCflaix
authored andcommitted
Changed tab to space conversion
Tabs are not always 4 spaces large. It completes the line to the 4th character.
1 parent d6f6ac3 commit cafdb31

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/main/java/com/gitblit/utils/StringUtils.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ public static String escapeForHtml(String inStr, boolean changeSpace) {
105105
public static String escapeForHtml(String inStr, boolean changeSpace, int tabLength) {
106106
StringBuilder retStr = new StringBuilder();
107107
int i = 0;
108+
int l = 0;
109+
108110
while (i < inStr.length()) {
109111
if (inStr.charAt(i) == '&') {
110112
retStr.append("&amp;");
@@ -117,12 +119,17 @@ public static String escapeForHtml(String inStr, boolean changeSpace, int tabLen
117119
} else if (changeSpace && inStr.charAt(i) == ' ') {
118120
retStr.append("&nbsp;");
119121
} else if (changeSpace && inStr.charAt(i) == '\t') {
120-
for (int j = 0; j < tabLength; j++) {
122+
for (int j = 0; j < tabLength - l; j++) {
121123
retStr.append("&nbsp;");
122124
}
125+
l = -1;
123126
} else {
124127
retStr.append(inStr.charAt(i));
125128
}
129+
130+
l = (l + 1) % tabLength;
131+
if (inStr.charAt(i) == '\n')
132+
l = 0;
126133
i++;
127134
}
128135
return retStr.toString();

0 commit comments

Comments
 (0)