类 StringInspector
- java.lang.Object
-
- com.mysql.cj.util.StringInspector
-
public class StringInspector extends Object
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.
-
-
构造器概要
构造器 构造器 说明 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.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.
-
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 chargetChar()Returns the character in the current position.intgetPosition()Returns the current position.intincrementPosition()Increments the current position index, by one, taking into consideration the "escaped" status of current character, if the modeSearchMode.ALLOW_BACKSLASH_ESCAPEis present in the default search mode.intincrementPosition(int by)Increments the current position index, by be given number, taking into consideration the "escaped" status of current character, if the modeSearchMode.ALLOW_BACKSLASH_ESCAPEis present in the default search mode.intincrementPosition(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 modeSearchMode.ALLOW_BACKSLASH_ESCAPEis present in the specified search mode.intincrementPosition(Set<SearchMode> searchMode)Increments the current position index, by one, taking into consideration the "escaped" status of current character, if the modeSearchMode.ALLOW_BACKSLASH_ESCAPEis present in the search mode specified.intindexOfIgnoreCase(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.intindexOfIgnoreCase(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.intindexOfIgnoreCase(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.intindexOfNextAlphanumericChar()Returns the position of the next alphanumeric character regardless the default search mode originally specified.intindexOfNextChar()Returns the position of the next valid character.intindexOfNextNonWsChar()Returns the position of the next non-whitespace character regardless the default search mode originally specified.intindexOfNextWsChar()Returns the position of the next whitespace character regardless the default search mode originally specified.voidmark()Marks the current object's state.intmatchesIgnoreCase(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.intmatchesIgnoreCase(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.voidreset()Resets this object's state to previously mark state.voidrestart()Resets this object's state to original values.intsetStartPosition(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 modeSearchMode.ALLOW_BACKSLASH_ESCAPEis present in the default search mode.intsetStopPosition(int pos)Sets the position where the source string processing will stop.List<String>split(String delimiter, boolean trim)Splits the source string by the given delimiter.StringstripCommentsAndHints()Returns a copy of the source string stripped of all comments and hints.
-
-
-
构造器详细资料
-
StringInspector
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.- 参数:
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 ofopeningMarkersthat override the remaining markers, e.g., ifopeningMarkers = "'(",closingMarkers = "')"andoverridingMarkers = "'"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- aSet, ideally anEnumSet, containing the default flags from the enumSearchModethat 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.
-
StringInspector
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.- 参数:
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 ofopeningMarkersthat override the remaining markers, e.g., ifopeningMarkers = "'(",closingMarkers = "')"andoverridingMarkers = "'"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- aSet, ideally anEnumSet, containing the default flags from the enumSearchModethat 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.
-
-
方法详细资料
-
setStartPosition
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 modeSearchMode.ALLOW_BACKSLASH_ESCAPEis present in the default search mode.- 参数:
pos- the position from where the source string will be processed- 返回:
- the previous current position value
-
setStopPosition
public int setStopPosition(int pos)
Sets the position where the source string processing will stop.- 参数:
pos- the position where the source string will stop being processed- 返回:
- the previous stop position value
-
mark
public void mark()
Marks the current object's state. A subsequent call to thereset()method restores the marked state.
-
reset
public void reset()
Resets this object's state to previously mark state.
-
restart
public void restart()
Resets this object's state to original values. Allows to reuse the object from a fresh start.
-
getChar
public char getChar()
Returns the character in the current position.- 返回:
- the character in the current position
-
getPosition
public int getPosition()
Returns the current position.- 返回:
- the current position
-
incrementPosition
public int incrementPosition()
Increments the current position index, by one, taking into consideration the "escaped" status of current character, if the modeSearchMode.ALLOW_BACKSLASH_ESCAPEis present in the default search mode.- 返回:
- the new current position
-
incrementPosition
public int incrementPosition(Set<SearchMode> searchMode)
Increments the current position index, by one, taking into consideration the "escaped" status of current character, if the modeSearchMode.ALLOW_BACKSLASH_ESCAPEis present in the search mode specified.- 参数:
searchMode- the search mode to use in this operation- 返回:
- the new current position
-
incrementPosition
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 modeSearchMode.ALLOW_BACKSLASH_ESCAPEis present in the default search mode.- 参数:
by- the number of positions to increment- 返回:
- the new current position
-
incrementPosition
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 modeSearchMode.ALLOW_BACKSLASH_ESCAPEis present in the specified search mode.- 参数:
by- the number of positions to incrementsearchMode- the search mode to use in this operation- 返回:
- the new current position
-
indexOfNextChar
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.- 返回:
- the position of the next valid character, or the current position if already on a valid character
-
indexOfNextAlphanumericChar
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.- 返回:
- the position of the next valid character, or the current position if already on a valid character
-
indexOfNextNonWsChar
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.- 返回:
- the position of the next valid character, or the current position if already on a valid character
-
indexOfNextWsChar
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.- 返回:
- the position of the next valid character, or the current position if already on a valid character
-
indexOfIgnoreCase
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.- 参数:
searchFor- the sub-string to search for- 返回:
- the position where the sub-string is found, starting from the current position, or -1 if not found
-
indexOfIgnoreCase
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.- 参数:
searchFor- the sub-string to search forsearchMode- the search mode to use in this operation- 返回:
- the position where the sub-string is found, starting from the current position, or -1 if not found
-
indexOfIgnoreCase
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
searchModespecified, when searching for the second and following sub-stringsSearchMode.SKIP_WHITE_SPACEwill be added andSearchMode.SKIP_BETWEEN_MARKERSremoved.- 参数:
searchFor- the sequence of sub-strings to search- 返回:
- the position where the first sub-string is found, starting from the current position, or -1 if not found
-
matchesIgnoreCase
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.- 参数:
toMatch- the sub-string to match- 返回:
- the position where the sub-string match ended, or -1 if not matched
-
matchesIgnoreCase
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
searchModespecified, when matching the second and following sub-stringsSearchMode.SKIP_WHITE_SPACEwill be added andSearchMode.SKIP_BETWEEN_MARKERSremoved.- 参数:
toMatch- the sequence of sub-strings to match- 返回:
- the position where the sequence of sub-strings match ended, or -1 if not matched
-
stripCommentsAndHints
public String stripCommentsAndHints()
Returns a copy of the source string stripped of all comments and hints.- 返回:
- a comments-free string
-
split
public List<String> split(String delimiter, boolean trim)
Splits the source string by the given delimiter. Consecutive delimiters result in empty string parts.- 参数:
delimiter- the characters sequence where to split the source stringtrim- whether each one of the parts should be trimmed or not- 返回:
- a
Listcontaining all the string parts
-
-