Misc fixes:
[sixth.git] / src / main / java / eu / svjatoslav / sixth / core / document / Utils.java
index 00166ef..4883d1d 100644 (file)
@@ -4,6 +4,8 @@ import eu.svjatoslav.commons.string.String2;
 
 public class Utils {
 
+    public static final char[] whitespace = new char[]{'\n', '\r', ' ', '\t'};
+
     public static String addIndentExceptFirstLine(String input, int indent) {
         String[] lines = input.split("\\r?\\n");
 
@@ -21,7 +23,34 @@ public class Utils {
     }
 
     public static boolean isBlank(String s){
-        return s.trim().length() == 0;
+        for (char c : s.toCharArray())
+            if (!isWhitespaceChar(c)) return false;
+
+        return true;
+    }
+
+    /**
+     * @return line indent in characters or -1 if line is blank or empty
+     */
+    public static int getLineIndent(String line){
+        for (int i = 0; i < line.length(); i++) {
+            if (!isWhitespaceChar(line.charAt(i)))
+                return i;
+        }
+        return -1;
+    }
+
+    public static boolean isWhitespaceChar(char c){
+        for (char whitespaceChar : whitespace)
+            if (whitespaceChar == c) return true;
+
+        return false;
+    }
+
+    public static String removePrefix(String string, int charsToRemove){
+        String2 s = new String2(string);
+        s.trimPrefix(charsToRemove);
+        return s.toString();
     }
 
 }