Object TemplateUtil
-
- All Implemented Interfaces:
public class TemplateUtilSQL 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
trydofor
-
-
Field Summary
Fields Modifier and Type Field Description public final static TemplateUtilINSTANCE
-
Method Summary
Modifier and Type Method Description final Stringreplace(String txt, String sub, String rpl, String qto, Boolean bnd)Parse and merge are done directly final Stringreplace(String txt, Map<String, String> rep, String qto, Boolean bnd)Parse and merge are done directly final Stringmerge(String txt, SortedMap<Integer, Integer> idx, String tbl)Merge the sql segment with new table final Stringmerge(String txt, SortedMap<Integer, Pair<Integer, String>> idx, Map<String, String> map)Merge template with multiple token 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). 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). final StringmaskQuote(String txt, String qto)Replace all the chars inside the quotes with an equal number of spaces, by char, not byte. final IntegerfindQuoteEnd(String txt, Integer idx)Find the end index corresponding to the current quote character. final BooleanisBoundary(String txt, Integer idx, Boolean dollar)Whether is a character boundary. final BooleanisBoundary(String txt, String sub, Boolean dollar)Whether the sub-string is complete in the text (case-insensitive). -
-
Method Detail
-
replace
final String replace(String txt, String sub, String rpl, String qto, Boolean bnd)
Parse and merge are done directly
- Parameters:
txt- textsub- string to findrpl- string to replaceqto- 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- textrep- map of find and replaceqto- quotation mark character, default'bnd- whether to check boundaries, default check
-
merge
final String merge(String txt, SortedMap<Integer, Integer> idx, String tbl)
Merge the sql segment with new table
- Parameters:
txt- textidx- parsed indexes<index1,index2>tbl- new table
-
merge
final String merge(String txt, SortedMap<Integer, Pair<Integer, String>> idx, Map<String, String> map)
Merge template with multiple token
- Parameters:
txt- textidx- parsed indexes<index1, Pair<index2, token>>map- map of find and replace<token, value>token is case-sensitive
-
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- texttkn- single tokenqto- 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- texttkn- single tokenqto- 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- textqto- 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- textidx- 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- textidx- index of startingdollar- 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- textsub- substringdollar- whether$is the boundary
-
-
-
-