Gridarta Editor
net.sf.gridarta.utils.StringUtils Class Reference

Utility class for string manipulation. More...

+ Collaboration diagram for net.sf.gridarta.utils.StringUtils:

Static Public Member Functions

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 found, returns the full line where 'str' occurs in base. More...
 
static CharSequence ensureTrailingNewline (@NotNull final String str)
 Returns a given string which ends with a trailing newline character; empty strings remain empty. More...
 
static String getAttribute (@NotNull final CharSequence attributes, @NotNull final String attributeName)
 Returns an attribute line from a set of attribute definitions. More...
 
static String removeTrailingWhitespace (@NotNull final CharSequence str)
 Removes trailing whitespace from a string. More...
 
static String removeTrailingWhitespaceFromLines (@NotNull final CharSequence str)
 Removes trailing whitespace from all lines of a string. More...
 
static String sortLines (@NotNull final CharSequence string)
 Sorts newline separated lines in a string. More...
 

Static Public Attributes

static final Pattern PATTERN_BACKSLASH = Pattern.compile("\\\\")
 The pattern that matches a single backslash ("\"). More...
 
static final Pattern PATTERN_COLON = Pattern.compile(":")
 The pattern that matches a single colon (":"). More...
 
static final Pattern PATTERN_COMMA = Pattern.compile(",")
 The pattern that matches a single comma (","). More...
 
static final Pattern PATTERN_END_OF_LINE = Pattern.compile("\\s*\n")
 The pattern to match end of line characters separating lines. More...
 
static final Pattern PATTERN_EQUAL = Pattern.compile("=")
 The pattern that matches a single equal sign ("="). More...
 
static final Pattern PATTERN_NEWLINE = Pattern.compile("\n")
 The pattern that matches a single newline ("\n"). More...
 
static final Pattern PATTERN_SLASH = Pattern.compile("/")
 The pattern that matches a single slash ("/"). More...
 
static final Pattern PATTERN_SPACE = Pattern.compile(" ")
 The pattern that matches a single space. More...
 
static final Pattern PATTERN_SPACES = Pattern.compile(" +")
 The pattern that matches a non-empty sequence of spaces. More...
 
static final Pattern PATTERN_WHITESPACE = Pattern.compile("[\\x00-\\x09\\x0b\\x20]+")
 Pattern to match whitespace excluding NL and CR. More...
 
static final Pattern PATTERN_WHITESPACE_NEWLINE = Pattern.compile("[\\x00-\\x0b\\x0d\\x20]+")
 Pattern to match whitespace including NL and CR. More...
 

Private Member Functions

 StringUtils ()
 Private constructor to prevent instantiation. More...
 

Static Private Attributes

static final Pattern PATTERN_MULTI_LINE_TRAILING_WHITESPACE = Pattern.compile("(?m)[\\x00-\\x09\\x0b\\x20]+$")
 Pattern to match trailing whitespace in a multi line string. More...
 
static final Pattern PATTERN_TRAILING_WHITESPACE = Pattern.compile("[\\x00-\\x09\\x0b\\x20]+$")
 Pattern to match trailing whitespace. More...
 

Detailed Description

Utility class for string manipulation.

Author
Andreas Kirschbaum

Definition at line 31 of file StringUtils.java.

Constructor & Destructor Documentation

◆ StringUtils()

net.sf.gridarta.utils.StringUtils.StringUtils ( )
private

Private constructor to prevent instantiation.

Definition at line 114 of file StringUtils.java.

Member Function Documentation

◆ diffTextString()

static CharSequence net.sf.gridarta.utils.StringUtils.diffTextString ( @NotNull final CharSequence  base,
@NotNull final String  str,
final boolean  ignoreValues 
)
static

Helper function for 'diffArchText()': Looks for occurrence of the attribute 'str' in 'base' and if found, returns the full line where 'str' occurs in base.

Only occurrences of 'str' at the beginning of a new line are counted as valid. If not found, null is returned.

Parameters
basefull text to search
strstring (attribute) to look for
ignoreValuesif true, lines are matched against 'str' only till the first space (" ")
Returns
the text that differs

Definition at line 159 of file StringUtils.java.

Referenced by net.sf.gridarta.model.io.AttributeListUtils.diffArchTextKeys(), net.sf.gridarta.model.io.AttributeListUtils.diffArchTextValues(), and net.sf.gridarta.utils.StringUtilsTest.testDiffTextString().

+ Here is the caller graph for this function:

◆ ensureTrailingNewline()

static CharSequence net.sf.gridarta.utils.StringUtils.ensureTrailingNewline ( @NotNull final String  str)
static

Returns a given string which ends with a trailing newline character; empty strings remain empty.

If the input strings ends in a newline character or if it is empty, it is returned; else a newline character is appended first.

Parameters
strthe input string
Returns
the string with a trailing newline character

Definition at line 143 of file StringUtils.java.

Referenced by net.sf.gridarta.model.baseobject.AbstractBaseObject< G, A, R, G >.setMsgText(), and net.sf.gridarta.utils.StringUtilsTest.testEnsureTrailingNewline().

+ Here is the caller graph for this function:

◆ getAttribute()

static String net.sf.gridarta.utils.StringUtils.getAttribute ( @NotNull final CharSequence  attributes,
@NotNull final String  attributeName 
)
static

Returns an attribute line from a set of attribute definitions.

If the set contains more than one instance of

attributeName

, only the first instance is returned.

Parameters
attributesthe attribute set to search
attributeNamethe attribute name to search for
Returns
the set of attribute value or
null
if the attribute was not found

Definition at line 178 of file StringUtils.java.

Referenced by net.sf.gridarta.utils.StringUtilsTest.testGetAttribute().

+ Here is the caller graph for this function:

◆ removeTrailingWhitespace()

static String net.sf.gridarta.utils.StringUtils.removeTrailingWhitespace ( @NotNull final CharSequence  str)
static

◆ removeTrailingWhitespaceFromLines()

◆ sortLines()

static String net.sf.gridarta.utils.StringUtils.sortLines ( @NotNull final CharSequence  string)
static

Sorts newline separated lines in a string.

Parameters
stringthe string to sort
Returns
the sorted string

Definition at line 194 of file StringUtils.java.

Referenced by net.sf.gridarta.model.baseobject.GameObjectText.setObjectText().

+ Here is the caller graph for this function:

Member Data Documentation

◆ PATTERN_BACKSLASH

final Pattern net.sf.gridarta.utils.StringUtils.PATTERN_BACKSLASH = Pattern.compile("\\\\")
static

The pattern that matches a single backslash ("\").

Definition at line 85 of file StringUtils.java.

Referenced by net.sf.gridarta.model.io.PathManagerUtils.path().

◆ PATTERN_COLON

final Pattern net.sf.gridarta.utils.StringUtils.PATTERN_COLON = Pattern.compile(":")
static

◆ PATTERN_COMMA

◆ PATTERN_END_OF_LINE

◆ PATTERN_EQUAL

final Pattern net.sf.gridarta.utils.StringUtils.PATTERN_EQUAL = Pattern.compile("=")
static

◆ PATTERN_MULTI_LINE_TRAILING_WHITESPACE

final Pattern net.sf.gridarta.utils.StringUtils.PATTERN_MULTI_LINE_TRAILING_WHITESPACE = Pattern.compile("(?m)[\\x00-\\x09\\x0b\\x20]+$")
staticprivate

Pattern to match trailing whitespace in a multi line string.

Definition at line 55 of file StringUtils.java.

◆ PATTERN_NEWLINE

◆ PATTERN_SLASH

final Pattern net.sf.gridarta.utils.StringUtils.PATTERN_SLASH = Pattern.compile("/")
static

◆ PATTERN_SPACE

final Pattern net.sf.gridarta.utils.StringUtils.PATTERN_SPACE = Pattern.compile(" ")
static

◆ PATTERN_SPACES

◆ PATTERN_TRAILING_WHITESPACE

final Pattern net.sf.gridarta.utils.StringUtils.PATTERN_TRAILING_WHITESPACE = Pattern.compile("[\\x00-\\x09\\x0b\\x20]+$")
staticprivate

Pattern to match trailing whitespace.

Definition at line 49 of file StringUtils.java.

◆ PATTERN_WHITESPACE

◆ PATTERN_WHITESPACE_NEWLINE

final Pattern net.sf.gridarta.utils.StringUtils.PATTERN_WHITESPACE_NEWLINE = Pattern.compile("[\\x00-\\x0b\\x0d\\x20]+")
static

Pattern to match whitespace including NL and CR.

Definition at line 43 of file StringUtils.java.

Referenced by net.sf.gridarta.model.archetypetype.ArchetypeTypeSetParser.parseAttributeOrder().


The documentation for this class was generated from the following file: