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");
}
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();
}
}