public class StringInspector
extends java.lang.Object
Constructor and Description |
---|
StringInspector(java.lang.String source,
int startingPosition,
java.lang.String openingMarkers,
java.lang.String closingMarkers,
java.lang.String overridingMarkers,
java.util.Set<SearchMode> searchMode)
This object provides string searching and manipulation operations such as finding sub-strings, matching sub-strings or building a comments-free version
of a string.
|
StringInspector(java.lang.String source,
java.lang.String openingMarkers,
java.lang.String closingMarkers,
java.lang.String overridingMarkers,
java.util.Set<SearchMode> searchMode)
This object provides string searching and manipulation operations such as finding sub-strings, matching sub-strings or building a comments-free version
of a string.
|
Modifier and Type | Method and Description |
---|---|
char |
getChar()
Returns the character in the current position.
|
int |
getPosition()
Returns the current position.
|
int |
incrementPosition()
Increments the current position index, by one, taking into consideration the "escaped" status of current character, if the mode
SearchMode.ALLOW_BACKSLASH_ESCAPE is present in the default search mode. |
int |
incrementPosition(int by)
Increments the current position index, by be given number, taking into consideration the "escaped" status of current character, if the mode
SearchMode.ALLOW_BACKSLASH_ESCAPE is present in the default search mode. |
int |
incrementPosition(int by,
java.util.Set<SearchMode> searchMode)
Increments the current position index, by be given number, taking into consideration the "escaped" status of current character, if the mode
SearchMode.ALLOW_BACKSLASH_ESCAPE is present in the specified search mode. |
int |
incrementPosition(java.util.Set<SearchMode> searchMode)
Increments the current position index, by one, taking into consideration the "escaped" status of current character, if the mode
SearchMode.ALLOW_BACKSLASH_ESCAPE is present in the search mode specified. |
int |
indexOfIgnoreCase(java.lang.String... searchFor)
Finds the position of the of the first of a consecutive sequence of strings within the source string, ignoring case, with the option to skip text
delimited by the specified markers or inside comment blocks.
|
int |
indexOfIgnoreCase(java.lang.String searchFor)
Finds the position of the given string within the source string, ignoring case, with the option to skip text delimited by the specified markers or inside
comment blocks.
|
int |
indexOfIgnoreCase(java.lang.String searchFor,
java.util.Set<SearchMode> searchMode)
Finds the position of the given string within the source string, ignoring case, with the option to skip text delimited by the specified markers or inside
comment blocks.
|
int |
indexOfNextAlphanumericChar()
Returns the position of the next alphanumeric character regardless the default search mode originally specified.
|
int |
indexOfNextChar()
Returns the position of the next valid character.
|
int |
indexOfNextNonWsChar()
Returns the position of the next non-whitespace character regardless the default search mode originally specified.
|
int |
indexOfNextWsChar()
Returns the position of the next whitespace character regardless the default search mode originally specified.
|
void |
mark()
Marks the current object's state.
|
int |
matchesIgnoreCase(java.lang.String... toMatch)
Checks if the given consecutive sequence of strings matches the source string counting from the current position, ignoring case, with the option to skip
text delimited by the specified markers or inside comment blocks.
|
int |
matchesIgnoreCase(java.lang.String toMatch)
Checks if the given string matches the source string counting from the current position, ignoring case, with the option to skip text delimited by the
specified markers or inside comment blocks.
|
void |
reset()
Resets this object's state to previously mark state.
|
void |
restart()
Resets this object's state to original values.
|
int |
setStartPosition(int pos)
Sets the position from where the source string will be processed from now on, taking into consideration the "escaped" status of current character, if
the mode
SearchMode.ALLOW_BACKSLASH_ESCAPE is present in the default search mode. |
int |
setStopPosition(int pos)
Sets the position where the source string processing will stop.
|
java.util.List<java.lang.String> |
split(java.lang.String delimiter,
boolean trim)
Splits the source string by the given delimiter.
|
java.lang.String |
stripCommentsAndHints()
Returns a copy of the source string stripped of all comments and hints.
|
public StringInspector(java.lang.String source, java.lang.String openingMarkers, java.lang.String closingMarkers, java.lang.String overridingMarkers, java.util.Set<SearchMode> searchMode)
source
- the source string to processopeningMarkers
- the characters that can delimit the beginning of a quoted text blockclosingMarkers
- the characters that can delimit the end of a of a quoted text block. The length of this parameter must match the length of th previous oneoverridingMarkers
- the subset of openingMarkers
that override the remaining markers, e.g., if openingMarkers = "'("
,
closingMarkers = "')"
and overridingMarkers = "'"
then the block between the outer parenthesis in "start
('max('); end"
is strictly consumed, otherwise the suffix "'); end"
would end up being consumed too in the process of
handling the nested parenthesis.searchMode
- a Set
, ideally an EnumSet
, containing the default flags from the enum SearchMode
that determine the behavior
of the search and manipulation operations. Note that some operation may override the search mode according to their needs, but the default one
is not touched.public StringInspector(java.lang.String source, int startingPosition, java.lang.String openingMarkers, java.lang.String closingMarkers, java.lang.String overridingMarkers, java.util.Set<SearchMode> searchMode)
source
- the source string to processstartingPosition
- the position from where the source string will be processedopeningMarkers
- the characters that can delimit the beginning of a quoted text blockclosingMarkers
- the characters that can delimit the end of a of a quoted text block. The length of this parameter must match the length of th previous oneoverridingMarkers
- the subset of openingMarkers
that override the remaining markers, e.g., if openingMarkers = "'("
,
closingMarkers = "')"
and overridingMarkers = "'"
then the block between the outer parenthesis in "start
('max('); end"
is strictly consumed, otherwise the suffix "'); end"
would end up being consumed too in the process of
handling the nested parenthesis.searchMode
- a Set
, ideally an EnumSet
, containing the default flags from the enum SearchMode
that determine the behavior
of the search and manipulation operations. Note that some operation may override the search mode according to their needs, but the default one
is not touched.public int setStartPosition(int pos)
SearchMode.ALLOW_BACKSLASH_ESCAPE
is present in the default search mode.pos
- the position from where the source string will be processedpublic int setStopPosition(int pos)
pos
- the position where the source string will stop being processedpublic void mark()
reset()
method restores the marked state.public void reset()
public void restart()
public char getChar()
public int getPosition()
public int incrementPosition()
SearchMode.ALLOW_BACKSLASH_ESCAPE
is present in the default search mode.public int incrementPosition(java.util.Set<SearchMode> searchMode)
SearchMode.ALLOW_BACKSLASH_ESCAPE
is present in the search mode specified.searchMode
- the search mode to use in this operationpublic int incrementPosition(int by)
SearchMode.ALLOW_BACKSLASH_ESCAPE
is present in the default search mode.by
- the number of positions to incrementpublic int incrementPosition(int by, java.util.Set<SearchMode> searchMode)
SearchMode.ALLOW_BACKSLASH_ESCAPE
is present in the specified search mode.by
- the number of positions to incrementsearchMode
- the search mode to use in this operationpublic int indexOfNextChar()
public int indexOfNextAlphanumericChar()
public int indexOfNextNonWsChar()
public int indexOfNextWsChar()
public int indexOfIgnoreCase(java.lang.String searchFor)
searchFor
- the sub-string to search forpublic int indexOfIgnoreCase(java.lang.String searchFor, java.util.Set<SearchMode> searchMode)
searchFor
- the sub-string to search forsearchMode
- the search mode to use in this operationpublic int indexOfIgnoreCase(java.lang.String... searchFor)
Independently of the searchMode
specified, when searching for the second and following sub-strings SearchMode.SKIP_WHITE_SPACE
will
be added and SearchMode.SKIP_BETWEEN_MARKERS
removed.
searchFor
- the sequence of sub-strings to searchpublic int matchesIgnoreCase(java.lang.String toMatch)
toMatch
- the sub-string to matchpublic int matchesIgnoreCase(java.lang.String... toMatch)
Independently of the searchMode
specified, when matching the second and following sub-strings SearchMode.SKIP_WHITE_SPACE
will be
added and SearchMode.SKIP_BETWEEN_MARKERS
removed.
toMatch
- the sequence of sub-strings to matchpublic java.lang.String stripCommentsAndHints()
public java.util.List<java.lang.String> split(java.lang.String delimiter, boolean trim)
delimiter
- the characters sequence where to split the source stringtrim
- whether each one of the parts should be trimmed or notList
containing all the string parts