boolean atBeginning = true;
for (int i = 0; i < strings.length; i++) {
String string = strings[i];
- String wrapper = atBeginning ? trimLeading(string) : string;
+ String wrapper = atBeginning ? StringUtil.trimLeading(string) : string;
if (StringUtil.endsWithChar(wrapper, '\n')) {
atBeginning = true;
- wrapper = trimTrailing(wrapper);
+ wrapper = StringUtil.trimTrailing(wrapper);
}
else {
atBeginning = false;
return result;
}
- private String trimLeading(String string) {
- int index = 0;
- while (index < string.length() && Character.isWhitespace(string.charAt(index))) index++;
- return string.substring(index);
- }
- private String trimTrailing(String string) {
- int index = string.length() - 1;
- while (index >= 0 && Character.isWhitespace(string.charAt(index))) index--;
- return string.substring(0, index + 1);
- }
@SuppressWarnings({"HardCodedStringLiteral"})
public String toString() {
if (convertBreaks) {
html = html.replaceAll("<br/?>", "\n\n");
}
-
+
return html.replaceAll("<(.|\n)*?>", "");
}
-
+
@Nullable
public static String toLowerCase(@Nullable final String str) {
return str == null ? null : str.toLowerCase();
@NotNull
public static String convertLineSeparators(@NotNull String text, @NotNull String newSeparator, @Nullable int[] offsetsToKeep,
- boolean keepCarriageReturn)
- {
+ boolean keepCarriageReturn) {
StringBuilder buffer = null;
int intactLength = 0;
final boolean newSeparatorIsSlashN = "\n".equals(newSeparator);
return text;
}
+ @NotNull
+ public static String trimLeading(@NotNull String string) {
+ int index = 0;
+ while (index < string.length() && Character.isWhitespace(string.charAt(index))) index++;
+ return string.substring(index);
+ }
+
+ @NotNull
+ public static String trimTrailing(@NotNull String string) {
+ int index = string.length() - 1;
+ while (index >= 0 && Character.isWhitespace(string.charAt(index))) index--;
+ return string.substring(0, index + 1);
+ }
+
public static boolean startsWithChar(@Nullable CharSequence s, char prefix) {
return s != null && s.length() != 0 && s.charAt(0) == prefix;
}
public static String nullize(final @Nullable String s, boolean nullizeSpaces) {
if (nullizeSpaces) {
if (isEmpty(s)) return null;
- } else {
+ }
+ else {
if (isEmptyOrSpaces(s)) return null;
}
return s;
/**
* Allows to answer if given symbol is white space, tabulation or line feed.
- *
- * @param c symbol to check
- * @return <code>true</code> if given symbol is white space, tabulation or line feed; <code>false</code> otherwise
+ *
+ * @param c symbol to check
+ * @return <code>true</code> if given symbol is white space, tabulation or line feed; <code>false</code> otherwise
*/
public static boolean isWhiteSpace(char c) {
return c == '\n' || c == '\t' || c == ' ';
}
-
+
@NotNull
public static String getThrowableText(@NotNull Throwable aThrowable) {
return ExceptionUtil.getThrowableText(aThrowable);
return true;
}
- public static boolean startsWith(@NotNull CharSequence text, int startIndex,@NotNull CharSequence prefix) {
+
+ public static boolean startsWith(@NotNull CharSequence text, int startIndex, @NotNull CharSequence prefix) {
int l1 = text.length() - startIndex;
int l2 = prefix.length();
if (l1 < l2) return false;
idx += 2;
}
}
-
+
public static String unescapeSlashes(@NotNull final String str) {
final StringBuilder buf = StringBuilderSpinAllocator.alloc();
try {
return buf.toString();
}
finally {
- StringBuilderSpinAllocator.dispose(buf);
+ StringBuilderSpinAllocator.dispose(buf);
}
}
public static void quote(@NotNull final StringBuilder builder) {
quote(builder, '\"');
}
-
+
public static void quote(@NotNull final StringBuilder builder, final char quotingChar) {
builder.insert(0, quotingChar);
builder.append(quotingChar);
private static int naturalCompare(String string1, String string2, boolean caseSensitive) {
final int string1Length = string1.length();
final int string2Length = string2.length();
- for(int i = 0, j = 0; i < string1Length && j < string2Length; i++, j++) {
+ for (int i = 0, j = 0; i < string1Length && j < string2Length; i++, j++) {
char ch1 = string1.charAt(i);
char ch2 = string2.charAt(j);
if ((isDigit(ch1) || ch1 == ' ') && (isDigit(ch2) || ch2 == ' ')) {
return diff;
}
}
- } else {
+ }
+ else {
if (caseSensitive) {
return ch1 - ch2;
- } else {
+ }
+ else {
// similar logic to charsMatch() below
if (ch1 != ch2) {
final int diff1 = Character.toUpperCase(ch1) - Character.toUpperCase(ch2);
}
public static boolean equals(@Nullable CharSequence s1, @Nullable CharSequence s2) {
- if (s1 == null ^ s2 == null) {
+ if (s1 == null ^ s2 == null) {
return false;
}