-package eu.svjatoslav.sixth.core.document;
-
-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");
-
- StringBuilder sb = new StringBuilder();
-
- if (lines.length >0 ) sb.append(lines[0]);
-
- for (int i = 1; i< lines.length; i++) {
- sb.append("\n");
- sb.append(new String2(" ").repeat(indent).toString());
- sb.append(lines[i]);
- }
-
- 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();
- }
-
-}