Top Description Fields Constructors Methods
com.mysql.cj.util

public Class StringInspector

extends Object
Class Inheritance
Imports
java.util.ArrayList, .EnumSet, .List, .Set, com.mysql.cj.Messages

Utility class to inspect a MySQL string, typically a query string. Provides string searching and manipulation operations such as finding sub-strings, matching sub-strings or building a comments-free version of a string. This object keeps internal state that affect the operations, e.g., executing an indexOf operation after another causes the second to start the search form where the previous one stopped.

Field Summary

Modifier and TypeField and Description
private String
private Set<SearchMode>
private boolean
private boolean
private boolean
private boolean
private int
private int
private static final int
private String
private String
private int
private String
private int
private int

Constructor Summary

AccessConstructor and Description
public
StringInspector(String
the source string to process
source
,
String
the characters that can delimit the beginning of a quoted text block
openingMarkers
,
String
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 one
closingMarkers
,
String
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.
overridingMarkers
,
Set<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.
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.

public
StringInspector(String
the source string to process
source
,
int
the position from where the source string will be processed
startingPosition
,
String
the characters that can delimit the beginning of a quoted text block
openingMarkers
,
String
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 one
closingMarkers
,
String
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.
overridingMarkers
,
Set<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.
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.

Method Summary

Modifier and TypeMethod and Description
public char

Returns:

the character in the current position
getChar
()

Returns the character in the current position.

public int

Returns:

the current position
getPosition
()

Returns the current position.

public int

Returns:

the new current position
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.

public int

Returns:

the new current position
incrementPosition
(Set<SearchMode>
the search mode to use in this operation
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.

public int

Returns:

the new current position
incrementPosition
(int
the number of positions to increment
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.

public int

Returns:

the new current position
incrementPosition
(int
the number of positions to increment
by
,
Set<SearchMode>
the search mode to use in this operation
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.

private int

Returns:

the position of the next closing marker corresponding to the opening marker in the current position
indexOfClosingMarker
(Set<SearchMode>
the search mode to use in this operation
searchMode
)

Returns the position of the next closing marker corresponding to the opening marker in the current position.

public int

Returns:

the position where the sub-string is found, starting from the current position, or -1 if not found
indexOfIgnoreCase
(String
the sub-string to search for
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.

public int

Returns:

the position where the sub-string is found, starting from the current position, or -1 if not found
indexOfIgnoreCase
(String
the sub-string to search for
searchFor
,
Set<SearchMode>
the search mode to use in this operation
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.

public int

Returns:

the position where the first sub-string is found, starting from the current position, or -1 if not found
indexOfIgnoreCase
(String...
the sequence of sub-strings to search
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.

public int

Returns:

the position of the next valid character, or the current position if already on a valid character
indexOfNextAlphanumericChar
()

Returns the position of the next alphanumeric character regardless the default search mode originally specified.

public int

Returns:

the position of the next valid character, or the current position if already on a valid character
indexOfNextChar
()

Returns the position of the next valid character.

private int

Returns:

the position of the next valid character, or the current position if already on a valid character
indexOfNextChar
(Set<SearchMode>
the search mode to use in this operation
searchMode
)

Returns the position of the next valid character using the given search mode instead of the default one.

public int

Returns:

the position of the next valid character, or the current position if already on a valid character
indexOfNextNonWsChar
()

Returns the position of the next non-whitespace character regardless the default search mode originally specified.

public int

Returns:

the position of the next valid character, or the current position if already on a valid character
indexOfNextWsChar
()

Returns the position of the next whitespace character regardless the default search mode originally specified.

public void
mark()

Marks the current object's state.

public int

Returns:

the position where the sub-string match ended, or -1 if not matched
matchesIgnoreCase
(String
the sub-string to match
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.

public int

Returns:

the position where the sequence of sub-strings match ended, or -1 if not matched
matchesIgnoreCase
(String...
the sequence of sub-strings to match
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.

public void
reset()

Resets this object's state to previously mark state.

private void
resetEscaped()

Checks if the current character is escaped by analyzing previous characters, as long as the search mode SearchMode#ALLOW_BACKSLASH_ESCAPE is present in the default search mode.

public void
restart()

Resets this object's state to original values.

public int

Returns:

the previous current position value
setStartPosition
(int
the position from where the source string will be processed
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.

public int

Returns:

the previous stop position value
setStopPosition
(int
the position where the source string will stop being processed
pos
)

Sets the position where the source string processing will stop.

public List<String>

Returns:

a List containing all the string parts
split
(String
the characters sequence where to split the source string
delimiter
,
boolean
whether each one of the parts should be trimmed or not
trim
)

Splits the source string by the given delimiter.

public String

Returns:

a comments-free string
stripCommentsAndHints
()

Returns a copy of the source string stripped of all comments and hints.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

closingMarkersback to summary
private String closingMarkers
defaultSearchModeback to summary
private Set<SearchMode> defaultSearchMode
escapedback to summary
private boolean escaped
inMysqlBlockback to summary
private boolean inMysqlBlock
markedEscapeback to summary
private boolean markedEscape
markedInMysqlBlockback to summary
private boolean markedInMysqlBlock
markedPosback to summary
private int markedPos
markedStopAtback to summary
private int markedStopAt
NON_COMMENTS_MYSQL_VERSION_REF_LENGTHback to summary
private static final int NON_COMMENTS_MYSQL_VERSION_REF_LENGTH
openingMarkersback to summary
private String openingMarkers
overridingMarkersback to summary
private String overridingMarkers
posback to summary
private int pos
sourceback to summary
private String source
srcLenback to summary
private int srcLen
stopAtback to summary
private int stopAt

Constructor Detail

StringInspectorback to summary
public StringInspector(String source, String openingMarkers, String closingMarkers, String overridingMarkers, 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.

Parameters
source:String

the source string to process

openingMarkers:String

the characters that can delimit the beginning of a quoted text block

closingMarkers:String

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 one

overridingMarkers:String

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:Set<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.

StringInspectorback to summary
public StringInspector(String source, int startingPosition, String openingMarkers, String closingMarkers, String overridingMarkers, 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.

Parameters
source:String

the source string to process

startingPosition:int

the position from where the source string will be processed

openingMarkers:String

the characters that can delimit the beginning of a quoted text block

closingMarkers:String

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 one

overridingMarkers:String

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:Set<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.

Method Detail

getCharback to summary
public char getChar()

Returns the character in the current position.

Returns:char

the character in the current position

getPositionback to summary
public int getPosition()

Returns the current position.

Returns:int

the current position

incrementPositionback to summary
public 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.

Returns:int

the new current position

incrementPositionback to summary
public int incrementPosition(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.

Parameters
searchMode:Set<SearchMode>

the search mode to use in this operation

Returns:int

the new current position

incrementPositionback to summary
public 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.

Parameters
by:int

the number of positions to increment

Returns:int

the new current position

incrementPositionback to summary
public int incrementPosition(int by, 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.

Parameters
by:int

the number of positions to increment

searchMode:Set<SearchMode>

the search mode to use in this operation

Returns:int

the new current position

indexOfClosingMarkerback to summary
private int indexOfClosingMarker(Set<SearchMode> searchMode)

Returns the position of the next closing marker corresponding to the opening marker in the current position. If the current position is not an opening marker, then -1 is returned instead.

Parameters
searchMode:Set<SearchMode>

the search mode to use in this operation

Returns:int

the position of the next closing marker corresponding to the opening marker in the current position

indexOfIgnoreCaseback to summary
public int indexOfIgnoreCase(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.

Parameters
searchFor:String

the sub-string to search for

Returns:int

the position where the sub-string is found, starting from the current position, or -1 if not found

indexOfIgnoreCaseback to summary
public int indexOfIgnoreCase(String searchFor, 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.

Parameters
searchFor:String

the sub-string to search for

searchMode:Set<SearchMode>

the search mode to use in this operation

Returns:int

the position where the sub-string is found, starting from the current position, or -1 if not found

indexOfIgnoreCaseback to summary
public int indexOfIgnoreCase(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.

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.

Parameters
searchFor:String[]

the sequence of sub-strings to search

Returns:int

the position where the first sub-string is found, starting from the current position, or -1 if not found

indexOfNextAlphanumericCharback to summary
public int indexOfNextAlphanumericChar()

Returns the position of the next alphanumeric character regardless the default search mode originally specified. This method does not increment the current position automatically, i.e., if already positioned in a valid character then repeated calls return always the same index. If the character in the current position matches one of the prefixes that determine a skipping block, then the position marker advances to the first alphanumeric character after the block to skip.

Returns:int

the position of the next valid character, or the current position if already on a valid character

indexOfNextCharback to summary
public int indexOfNextChar()

Returns the position of the next valid character. This method does not increment the current position automatically, i.e., if already positioned in a valid character then repeated calls return always the same index. If the character in the current position matches one of the prefixes that determine a skipping block, then the position marker advances to the first character after the block to skip.

Returns:int

the position of the next valid character, or the current position if already on a valid character

indexOfNextCharback to summary
private int indexOfNextChar(Set<SearchMode> searchMode)

Returns the position of the next valid character using the given search mode instead of the default one. This method does not increment the current position automatically, i.e., if already positioned in a valid character then repeated calls return always the same index. If the character in the current position matches one of the prefixes that determine a skipping block, then the position marker advances to the first character after the block to skip.

Parameters
searchMode:Set<SearchMode>

the search mode to use in this operation

Returns:int

the position of the next valid character, or the current position if already on a valid character

indexOfNextNonWsCharback to summary
public int indexOfNextNonWsChar()

Returns the position of the next non-whitespace character regardless the default search mode originally specified. This method does not increment the current position automatically, i.e., if already positioned in a valid character then repeated calls return always the same index. If the character in the current position matches one of the prefixes that determine a skipping block, then the position marker advances to the first non-whitespace character after the block to skip.

Returns:int

the position of the next valid character, or the current position if already on a valid character

indexOfNextWsCharback to summary
public int indexOfNextWsChar()

Returns the position of the next whitespace character regardless the default search mode originally specified. This method does not increment the current position automatically, i.e., if already positioned in a valid character then repeated calls return always the same index. If the character in the current position matches one of the prefixes that determine a skipping block, then the position marker advances to the first whitespace character after the block to skip.

Returns:int

the position of the next valid character, or the current position if already on a valid character

markback to summary
public void mark()

Marks the current object's state. A subsequent call to the reset() method restores the marked state.

matchesIgnoreCaseback to summary
public int matchesIgnoreCase(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.

Parameters
toMatch:String

the sub-string to match

Returns:int

the position where the sub-string match ended, or -1 if not matched

matchesIgnoreCaseback to summary
public int matchesIgnoreCase(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.

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.

Parameters
toMatch:String[]

the sequence of sub-strings to match

Returns:int

the position where the sequence of sub-strings match ended, or -1 if not matched

resetback to summary
public void reset()

Resets this object's state to previously mark state.

resetEscapedback to summary
private void resetEscaped()

Checks if the current character is escaped by analyzing previous characters, as long as the search mode SearchMode#ALLOW_BACKSLASH_ESCAPE is present in the default search mode.

restartback to summary
public void restart()

Resets this object's state to original values. Allows to reuse the object from a fresh start.

setStartPositionback to summary
public 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.

Parameters
pos:int

the position from where the source string will be processed

Returns:int

the previous current position value

setStopPositionback to summary
public int setStopPosition(int pos)

Sets the position where the source string processing will stop.

Parameters
pos:int

the position where the source string will stop being processed

Returns:int

the previous stop position value

splitback to summary
public List<String> split(String delimiter, boolean trim)

Splits the source string by the given delimiter. Consecutive delimiters result in empty string parts.

Parameters
delimiter:String

the characters sequence where to split the source string

trim:boolean

whether each one of the parts should be trimmed or not

Returns:List<String>

a List containing all the string parts

stripCommentsAndHintsback to summary
public String stripCommentsAndHints()

Returns a copy of the source string stripped of all comments and hints.

Returns:String

a comments-free string