]> source.dussan.org Git - gitblit.git/commitdiff
Changed tab to space conversion
authorQuentin <quentin@open-to-repair.fr>
Mon, 18 Apr 2016 17:31:42 +0000 (19:31 +0200)
committerFlorian Zschocke <f.zschocke+git@gmail.com>
Tue, 2 Aug 2022 20:10:17 +0000 (22:10 +0200)
Tabs are not always 4 spaces large. It completes the line to the 4th
character.

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

index 442acbbf77e1f5e51aa0d3d304aa018db361361f..7c4eef8bf43646ef538ec0c396986c2ab04689dd 100644 (file)
@@ -105,6 +105,8 @@ public class StringUtils {
        public static String escapeForHtml(String inStr, boolean changeSpace, int tabLength) {\r
                StringBuilder retStr = new StringBuilder();\r
                int i = 0;\r
+               int l = 0;\r
+               \r
                while (i < inStr.length()) {\r
                        if (inStr.charAt(i) == '&') {\r
                                retStr.append("&amp;");\r
@@ -117,12 +119,17 @@ public class StringUtils {
                        } else if (changeSpace && inStr.charAt(i) == ' ') {\r
                                retStr.append("&nbsp;");\r
                        } else if (changeSpace && inStr.charAt(i) == '\t') {\r
-                               for (int j = 0; j < tabLength; j++) {\r
+                               for (int j = 0; j < tabLength - l; j++) {\r
                                        retStr.append("&nbsp;");\r
                                }\r
+                               l = -1;\r
                        } else {\r
                                retStr.append(inStr.charAt(i));\r
                        }\r
+                       \r
+                       l = (l + 1) % tabLength;\r
+                       if (inStr.charAt(i) == '\n')\r
+                               l = 0;\r
                        i++;\r
                }\r
                return retStr.toString();\r