20 package net.sf.gridarta.utils;
22 import java.util.Arrays;
23 import java.util.regex.Pattern;
24 import org.jetbrains.annotations.NotNull;
25 import org.jetbrains.annotations.Nullable;
123 return PATTERN_TRAILING_WHITESPACE.matcher(str).replaceFirst(
"");
132 return PATTERN_MULTI_LINE_TRAILING_WHITESPACE.matcher(str).replaceAll(
"");
144 return str.length() <= 0 ?
"" : str.endsWith(
"\n") ? str : str +
"\n";
159 public static CharSequence
diffTextString(@NotNull
final CharSequence base, @NotNull
final String str,
final boolean ignoreValues) {
160 for (
final String line : PATTERN_END_OF_LINE.split(base, 0)) {
161 if (ignoreValues ? line.startsWith(str) : line.equals(str)) {
178 public static String
getAttribute(@NotNull
final CharSequence attributes, @NotNull
final String attributeName) {
179 final String str = attributeName +
" ";
180 for (
final String line : PATTERN_END_OF_LINE.split(attributes, 0)) {
181 if (line.startsWith(str)) {
182 return line.substring(str.length());
194 public static String
sortLines(@NotNull
final CharSequence
string) {
195 final String[] lines = PATTERN_NEWLINE.split(
string, -1);
197 final StringBuilder sb =
new StringBuilder();
198 for (
final String line : lines) {
199 sb.append(line).append(
'\n');
201 return sb.toString();
Utility class for string manipulation.
static final Pattern PATTERN_EQUAL
The pattern that matches a single equal sign ("=").
static String removeTrailingWhitespace(@NotNull final CharSequence str)
Removes trailing whitespace from a string.
static final Pattern PATTERN_SPACE
The pattern that matches a single space.
static final Pattern PATTERN_NEWLINE
The pattern that matches a single newline ("\n").
static CharSequence ensureTrailingNewline(@NotNull final String str)
Returns a given string which ends with a trailing newline character; empty strings remain empty...
static final Pattern PATTERN_SPACES
The pattern that matches a non-empty sequence of spaces.
static String getAttribute(@NotNull final CharSequence attributes, @NotNull final String attributeName)
Returns an attribute line from a set of attribute definitions.
static String removeTrailingWhitespaceFromLines(@NotNull final CharSequence str)
Removes trailing whitespace from all lines of a string.
static CharSequence diffTextString(@NotNull final CharSequence base, @NotNull final String str, final boolean ignoreValues)
Helper function for 'diffArchText()': Looks for occurrence of the attribute 'str' in 'base' and if fo...
StringUtils()
Private constructor to prevent instantiation.
static final Pattern PATTERN_COMMA
The pattern that matches a single comma (",").
static final Pattern PATTERN_WHITESPACE
Pattern to match whitespace excluding NL and CR.
static final Pattern PATTERN_BACKSLASH
The pattern that matches a single backslash ("\").
static final Pattern PATTERN_END_OF_LINE
The pattern to match end of line characters separating lines.
static final Pattern PATTERN_MULTI_LINE_TRAILING_WHITESPACE
Pattern to match trailing whitespace in a multi line string.
static final Pattern PATTERN_TRAILING_WHITESPACE
Pattern to match trailing whitespace.
static final Pattern PATTERN_COLON
The pattern that matches a single colon (":").
static final Pattern PATTERN_WHITESPACE_NEWLINE
Pattern to match whitespace including NL and CR.
static String sortLines(@NotNull final CharSequence string)
Sorts newline separated lines in a string.
static final Pattern PATTERN_SLASH
The pattern that matches a single slash ("/").