mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-25 03:11:10 +01:00
Prevent leading and trailing whitespace in group names.
This commit is contained in:
committed by
Greyson Parrelli
parent
9c54e39eae
commit
ab76112f5f
@@ -45,13 +45,44 @@ public final class StringUtil {
|
||||
return true;
|
||||
}
|
||||
|
||||
for (int i = 0; i < value.length(); i++) {
|
||||
return indexOfFirstNonEmptyChar(value) == -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return String without any leading or trailing whitespace.
|
||||
* Accounts for various unicode whitespace characters.
|
||||
*/
|
||||
public static String trimToVisualBounds(@NonNull String value) {
|
||||
int start = indexOfFirstNonEmptyChar(value);
|
||||
|
||||
if (start == -1) {
|
||||
return "";
|
||||
}
|
||||
|
||||
int end = indexOfLastNonEmptyChar(value);
|
||||
|
||||
return value.substring(start, end + 1);
|
||||
}
|
||||
|
||||
private static int indexOfFirstNonEmptyChar(@NonNull String value) {
|
||||
int length = value.length();
|
||||
|
||||
for (int i = 0; i < length; i++) {
|
||||
if (!isVisuallyEmpty(value.charAt(i))) {
|
||||
return false;
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
return -1;
|
||||
}
|
||||
|
||||
private static int indexOfLastNonEmptyChar(@NonNull String value) {
|
||||
for (int i = value.length() - 1; i >= 0; i--) {
|
||||
if (!isVisuallyEmpty(value.charAt(i))) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user