X-Git-Url: http://www2.svjatoslav.eu/gitweb/?p=sixth.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Feu%2Fsvjatoslav%2Fsixth%2Fcore%2Fdocument%2FUtils.java;h=4883d1de8d9d710c98b5cf6b3f153d1f4aa6be5b;hp=406e7efac2246a7f44dcb81e4d16241a41042267;hb=168cf05300cec2bb4c0607711b752609976b2901;hpb=1f96525468e7f76c1ce817a8a7b22c93a39e40b4 diff --git a/src/main/java/eu/svjatoslav/sixth/core/document/Utils.java b/src/main/java/eu/svjatoslav/sixth/core/document/Utils.java index 406e7ef..4883d1d 100644 --- a/src/main/java/eu/svjatoslav/sixth/core/document/Utils.java +++ b/src/main/java/eu/svjatoslav/sixth/core/document/Utils.java @@ -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"); @@ -20,4 +22,35 @@ public class Utils { return sb.toString(); } + public static boolean isBlank(String s){ + 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(); + } + }