Skip to content

Commit 75be10f

Browse files
committed
StringUtils::getLeadingWhitespace
1 parent 6a2c992 commit 75be10f

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/main/java/org/variantsync/diffdetective/util/StringUtils.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,17 @@ public static String prettyPrintNestedCollections(final Collection<?> collection
4848
public static String clamp(int maxlen, String s) {
4949
return s.substring(0, Math.min(s.length(), maxlen));
5050
}
51+
52+
/**
53+
* @return the longest prefix of the given string that contains only of whitespace
54+
*/
55+
public static String getLeadingWhitespace(String s) {
56+
if (s == null) return null;
57+
if (s.isEmpty()) return "";
58+
int i = 0;
59+
while (i < s.length() && Character.isWhitespace(s.charAt(i))) {
60+
++i;
61+
}
62+
return s.substring(0, i);
63+
}
5164
}

0 commit comments

Comments
 (0)