Object TemplateUtil

  • All Implemented Interfaces:

    
    public class TemplateUtil
    
                        

    SQL template parsing and merging. When parsing. (1) Ignore text in quotes to avoid errors (2) Judge character boundaries to avoid truncation

    Since:

    2019-06-20

    Author:

    trydofor

    • Constructor Detail

    • Method Detail

      • replace

         final String replace(String txt, String sub, String rpl, String qto, Boolean bnd)

        Parse and merge are done directly

        Parameters:
        txt - text
        sub - string to find
        rpl - string to replace
        qto - quotation mark character, default '
        bnd - whether to check boundaries, default check
      • replace

         final String replace(String txt, Map<String, String> rep, String qto, Boolean bnd)

        Parse and merge are done directly

        Parameters:
        txt - text
        rep - map of find and replace
        qto - quotation mark character, default '
        bnd - whether to check boundaries, default check
      • parse

         final SortedMap<Integer, Pair<Integer, String>> parse(String txt, List<String> tkn, String qto, Boolean bnd)

        Parse the start and end coordinates of multiple tokens in the text (case-insensitive). Containment relationships between multiple tokens are handled, i.e. two coordinates are crossed and the later one is rounded off until there is no crossing.

        Parameters:
        txt - text
        tkn - single token
        qto - quotation mark character, default '
        bnd - whether to check boundaries, default check
      • parse

         final SortedMap<Integer, Integer> parse(String txt, String tkn, String qto, Boolean bnd)

        Parse the start and end coordinates of single token in the text (case-insensitive).

        Parameters:
        txt - text
        tkn - single token
        qto - quotation mark character, default '
        bnd - whether to check boundaries, default check
      • maskQuote

         final String maskQuote(String txt, String qto)

        Replace all the chars inside the quotes with an equal number of spaces, by char, not byte.

        Parameters:
        txt - text
        qto - quotation mark character, default '
      • findQuoteEnd

         final Integer findQuoteEnd(String txt, Integer idx)

        Find the end index corresponding to the current quote character. Handles the \ escape case.

        Parameters:
        txt - text
        idx - index of the start quote
      • isBoundary

         final Boolean isBoundary(String txt, Integer idx, Boolean dollar)

        Whether is a character boundary. Consecutive [A-Z0-9_] and non-ASCII characters are considered consecutive.

        Parameters:
        txt - text
        idx - index of starting
        dollar - whether $ is the boundary
      • isBoundary

         final Boolean isBoundary(String txt, String sub, Boolean dollar)

        Whether the sub-string is complete in the text (case-insensitive).

        Parameters:
        txt - text
        sub - substring
        dollar - whether $ is the boundary