Class WikiScannerUtil


  • public class WikiScannerUtil
    extends Object
    This class contains some utility methods used by scanners.
    Since:
    4.0M1
    Version:
    $Id: 712fba3ebe77aad51abf943a66a44c38eec2025b $
    • Constructor Detail

      • WikiScannerUtil

        public WikiScannerUtil()
    • 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 returned
        open - the start substring sequence
        close - 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 returned
        open - the start substring sequence
        close - the closing substring sequence
        escape - 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 returned
        open - the start substring sequence
        close - the closing substring sequence
        escape - the escape symbol
        cleanEscape - 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 chars
        pos - the start position in the array
        delimiter - the delimiter; this method copies all character from the current position to the first delimiter sequence
        buf - 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 characters
        arrayPos - the position of the first character in the array; starting from this position the sequence should be skipped
        sequence - 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 characters
        arrayPos - the position of the first character in the array; starting from this position the sequence should be skipped
        sequence - 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 split
        list - to this list all extracted values will be added
      • 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 split
        list - to this list all extracted values will be added
        delimiter - a delimiter for individual key/value pairs
      • 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 split
        list - to this list all extracted values will be added
        delimiter - a delimiter for individual key/value pairs
        end - the ending sequence, if null it's not taken into account
        escapeChar - 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 (see DEFAULT_ESCAPECHAR).
        Parameters:
        str - the string to unescape
        Returns:
        an unescaped string
      • unescape

        public static String unescape​(String str,
                                      char escape)
        Unescapes the given string and returns the result.
        Parameters:
        str - the string to unescape
        escape - the symbol used to escape characters
        Returns:
        an unescaped string