Class WikiScannerUtil
- java.lang.Object
-
- org.xwiki.rendering.wikimodel.impl.WikiScannerUtil
-
public class WikiScannerUtil extends Object
This class contains some utility methods used by scanners.- Since:
- 4.0M1
- Version:
- $Id: 712fba3ebe77aad51abf943a66a44c38eec2025b $
-
-
Constructor Summary
Constructors Constructor Description WikiScannerUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static String
extractSubstring(String str, String open, String close)
Extracts and returns a substring of the given string starting from the given open sequence and finishing by the specified close sequence.static String
extractSubstring(String str, String open, String close, char escape)
Extracts and returns a substring of the given string starting from the given open sequence and finishing by the specified close sequence.static String
extractSubstring(String str, String open, String close, char escape, boolean cleanEscape)
Extracts and returns a substring of the given string starting from the given open sequence and finishing by the specified close sequence.static int
getNextSequence(char[] array, int pos, char[] delimiter, StringBuffer buf)
This method copies to the given buffer all characters from the specified position of the character array to the next delimiter position.static boolean
matchesSequence(char[] array, int arrayPos, char[] sequence)
Indicate if the specified sequence starts from the given position in the character array.static int
skipSequence(char[] array, int arrayPos, char[] sequence)
Skips the specified sequence if it starts from the given position in the character array.static int
splitToPairs(String str, List<WikiParameter> list)
Splits the given string into a set of key-value pairs; all extracted values will be added to the given liststatic int
splitToPairs(String str, List<WikiParameter> list, char escapeChar)
static int
splitToPairs(String str, List<WikiParameter> list, String delimiter)
Splits the given string into a set of key-value pairs; all extracted values will be added to the given liststatic int
splitToPairs(String str, List<WikiParameter> list, String delimiter, String end)
static int
splitToPairs(String str, List<WikiParameter> list, String delimiter, String end, char escapeChar)
Splits the given string into a set of key-value pairs; all extracted values will be added to the given liststatic String
unescape(String str)
Unescapes the given string and returns the result.static String
unescape(String str, char escape)
Unescapes the given string and returns the result.
-
-
-
Method Detail
-
extractSubstring
public static String extractSubstring(String str, String open, String close)
Extracts and returns a substring of the given string starting from the given open sequence and finishing by the specified close sequence. This method unescapes all symbols prefixed by the given escape symbol.- Parameters:
str
- from this string the substring framed by the specified open and close sequence will be returnedopen
- the start substring sequenceclose
- the closing substring sequence- Returns:
- a substring of the given string starting from the given open sequence and finishing by the specified close sequence
-
extractSubstring
public static String extractSubstring(String str, String open, String close, char escape)
Extracts and returns a substring of the given string starting from the given open sequence and finishing by the specified close sequence. This method unescapes all symbols prefixed by the given escape symbol.- Parameters:
str
- from this string the substring framed by the specified open and close sequence will be returnedopen
- the start substring sequenceclose
- the closing substring sequenceescape
- the escape symbol- Returns:
- a substring of the given string starting from the given open sequence and finishing by the specified close sequence
-
extractSubstring
public static String extractSubstring(String str, String open, String close, char escape, boolean cleanEscape)
Extracts and returns a substring of the given string starting from the given open sequence and finishing by the specified close sequence. This method unescapes all symbols prefixed by the given escape symbol.- Parameters:
str
- from this string the substring framed by the specified open and close sequence will be returnedopen
- the start substring sequenceclose
- the closing substring sequenceescape
- the escape symbolcleanEscape
- indicate if the escaping char has to be removed. Useful when the substring use the same escaping that the string.- Returns:
- a substring of the given string starting from the given open sequence and finishing by the specified close sequence
-
getNextSequence
public static int getNextSequence(char[] array, int pos, char[] delimiter, StringBuffer buf)
This method copies to the given buffer all characters from the specified position of the character array to the next delimiter position. This method returns the next position just after the delimiter (or the length of the array if no delimiters was found).- Parameters:
array
- the array of character used as a source of charspos
- the start position in the arraydelimiter
- the delimiter; this method copies all character from the current position to the first delimiter sequencebuf
- the buffer where the content should be appended- Returns:
- the next position just after the delimiter of the end of the sequence
-
matchesSequence
public static boolean matchesSequence(char[] array, int arrayPos, char[] sequence)
Indicate if the specified sequence starts from the given position in the character array.- Parameters:
array
- the array of charactersarrayPos
- the position of the first character in the array; starting from this position the sequence should be skippedsequence
- the sequence of characters to match- Returns:
- true if the sequence is found, false otherwise
-
skipSequence
public static int skipSequence(char[] array, int arrayPos, char[] sequence)
Skips the specified sequence if it starts from the given position in the character array.- Parameters:
array
- the array of charactersarrayPos
- the position of the first character in the array; starting from this position the sequence should be skippedsequence
- the sequence of characters to skip- Returns:
- a new value of the character counter
-
splitToPairs
public static int splitToPairs(String str, List<WikiParameter> list)
Splits the given string into a set of key-value pairs; all extracted values will be added to the given list- Parameters:
str
- the string to splitlist
- to this list all extracted values will be added
-
splitToPairs
public static int splitToPairs(String str, List<WikiParameter> list, char escapeChar)
-
splitToPairs
public static int splitToPairs(String str, List<WikiParameter> list, String delimiter)
Splits the given string into a set of key-value pairs; all extracted values will be added to the given list- Parameters:
str
- the string to splitlist
- to this list all extracted values will be addeddelimiter
- a delimiter for individual key/value pairs
-
splitToPairs
public static int splitToPairs(String str, List<WikiParameter> list, String delimiter, String end)
-
splitToPairs
public static int splitToPairs(String str, List<WikiParameter> list, String delimiter, String end, char escapeChar)
Splits the given string into a set of key-value pairs; all extracted values will be added to the given list- Parameters:
str
- the string to splitlist
- to this list all extracted values will be addeddelimiter
- a delimiter for individual key/value pairsend
- the ending sequence, if null it's not taken into accountescapeChar
- the escaping character- Returns:
- the index where parser stopped
-
unescape
public static String unescape(String str)
Unescapes the given string and returns the result. This method uses the default escape symbol (seeDEFAULT_ESCAPECHAR
).- Parameters:
str
- the string to unescape- Returns:
- an unescaped string
-
-