@Test public void testDecorate_UpperCase() { String decorated = StringHelper.decorate( "SELECT * FROM CQLDEMO.MYBOOKS WHERE ID=1122 AND SOME VALUE IS NOT .... FROM", TD, "from", "112", "demo", "not"); assertEquals( "SELECT * +++++FROM-- CQL+++++DEMO--.MYBOOKS WHERE ID=+++++112--2 AND SOME VALUE IS +++++NOT-- .... +++++FROM--", decorated); }
public static String decorate(String toDecorate, StringDecorator decorator, String... keywordsLc) { String prefix = decorator.prefix(); String postfix = decorator.postfix(); int prefixLength = prefix.length(); StringBuilder buf = new StringBuilder(toDecorate); for (String keyword : sortBySize(keywordsLc)) { if (prefix.contains(keyword) || postfix.contains(keyword)) { LOG.debug("Skipping keyword: {} because it's part of decoreator syntax", keyword); continue; } String bufLc = buf.toString().toLowerCase(); int startSearch = 0; int foundIdx = -1; while ((foundIdx = bufLc.indexOf(keyword, startSearch)) >= 0) { if (foundIdx > prefixLength) { String kwWithPref = bufLc.substring(foundIdx - prefixLength, foundIdx); if (prefix.equals(kwWithPref)) { startSearch = foundIdx + kwWithPref.length() + keyword.length() + 1; continue; } } int kwStart = foundIdx; int kwEnd = foundIdx + keyword.length(); String orgKw = buf.substring(kwStart, kwEnd); String decoratedKw = decorator.decorate(orgKw); buf.replace(kwStart, kwEnd, decoratedKw); bufLc = buf.toString().toLowerCase(); startSearch = foundIdx + decoratedKw.length() + 1; } } LOG.trace("Decorated {} to {}", toDecorate, buf); return buf.toString(); }
StringHelper { public static String decorate(String toDecorate, StringDecorator decorator, String... keywordsLc) { String prefix = decorator.prefix(); String postfix = decorator.postfix(); int prefixLength = prefix.length(); StringBuilder buf = new StringBuilder(toDecorate); for (String keyword : sortBySize(keywordsLc)) { if (prefix.contains(keyword) || postfix.contains(keyword)) { LOG.debug("Skipping keyword: {} because it's part of decoreator syntax", keyword); continue; } String bufLc = buf.toString().toLowerCase(); int startSearch = 0; int foundIdx = -1; while ((foundIdx = bufLc.indexOf(keyword, startSearch)) >= 0) { if (foundIdx > prefixLength) { String kwWithPref = bufLc.substring(foundIdx - prefixLength, foundIdx); if (prefix.equals(kwWithPref)) { startSearch = foundIdx + kwWithPref.length() + keyword.length() + 1; continue; } } int kwStart = foundIdx; int kwEnd = foundIdx + keyword.length(); String orgKw = buf.substring(kwStart, kwEnd); String decoratedKw = decorator.decorate(orgKw); buf.replace(kwStart, kwEnd, decoratedKw); bufLc = buf.toString().toLowerCase(); startSearch = foundIdx + decoratedKw.length() + 1; } } LOG.trace("Decorated {} to {}", toDecorate, buf); return buf.toString(); } }
StringHelper { public static String decorate(String toDecorate, StringDecorator decorator, String... keywordsLc) { String prefix = decorator.prefix(); String postfix = decorator.postfix(); int prefixLength = prefix.length(); StringBuilder buf = new StringBuilder(toDecorate); for (String keyword : sortBySize(keywordsLc)) { if (prefix.contains(keyword) || postfix.contains(keyword)) { LOG.debug("Skipping keyword: {} because it's part of decoreator syntax", keyword); continue; } String bufLc = buf.toString().toLowerCase(); int startSearch = 0; int foundIdx = -1; while ((foundIdx = bufLc.indexOf(keyword, startSearch)) >= 0) { if (foundIdx > prefixLength) { String kwWithPref = bufLc.substring(foundIdx - prefixLength, foundIdx); if (prefix.equals(kwWithPref)) { startSearch = foundIdx + kwWithPref.length() + keyword.length() + 1; continue; } } int kwStart = foundIdx; int kwEnd = foundIdx + keyword.length(); String orgKw = buf.substring(kwStart, kwEnd); String decoratedKw = decorator.decorate(orgKw); buf.replace(kwStart, kwEnd, decoratedKw); bufLc = buf.toString().toLowerCase(); startSearch = foundIdx + decoratedKw.length() + 1; } } LOG.trace("Decorated {} to {}", toDecorate, buf); return buf.toString(); }  }
StringHelper { public static String decorate(String toDecorate, StringDecorator decorator, String... keywordsLc) { String prefix = decorator.prefix(); String postfix = decorator.postfix(); int prefixLength = prefix.length(); StringBuilder buf = new StringBuilder(toDecorate); for (String keyword : sortBySize(keywordsLc)) { if (prefix.contains(keyword) || postfix.contains(keyword)) { LOG.debug("Skipping keyword: {} because it's part of decoreator syntax", keyword); continue; } String bufLc = buf.toString().toLowerCase(); int startSearch = 0; int foundIdx = -1; while ((foundIdx = bufLc.indexOf(keyword, startSearch)) >= 0) { if (foundIdx > prefixLength) { String kwWithPref = bufLc.substring(foundIdx - prefixLength, foundIdx); if (prefix.equals(kwWithPref)) { startSearch = foundIdx + kwWithPref.length() + keyword.length() + 1; continue; } } int kwStart = foundIdx; int kwEnd = foundIdx + keyword.length(); String orgKw = buf.substring(kwStart, kwEnd); String decoratedKw = decorator.decorate(orgKw); buf.replace(kwStart, kwEnd, decoratedKw); bufLc = buf.toString().toLowerCase(); startSearch = foundIdx + decoratedKw.length() + 1; } } LOG.trace("Decorated {} to {}", toDecorate, buf); return buf.toString(); }  static String decorate(String toDecorate, StringDecorator decorator, String... keywordsLc); static Optional<InetAddress> toInetAddress(String ip); }
StringHelper { public static String decorate(String toDecorate, StringDecorator decorator, String... keywordsLc) { String prefix = decorator.prefix(); String postfix = decorator.postfix(); int prefixLength = prefix.length(); StringBuilder buf = new StringBuilder(toDecorate); for (String keyword : sortBySize(keywordsLc)) { if (prefix.contains(keyword) || postfix.contains(keyword)) { LOG.debug("Skipping keyword: {} because it's part of decoreator syntax", keyword); continue; } String bufLc = buf.toString().toLowerCase(); int startSearch = 0; int foundIdx = -1; while ((foundIdx = bufLc.indexOf(keyword, startSearch)) >= 0) { if (foundIdx > prefixLength) { String kwWithPref = bufLc.substring(foundIdx - prefixLength, foundIdx); if (prefix.equals(kwWithPref)) { startSearch = foundIdx + kwWithPref.length() + keyword.length() + 1; continue; } } int kwStart = foundIdx; int kwEnd = foundIdx + keyword.length(); String orgKw = buf.substring(kwStart, kwEnd); String decoratedKw = decorator.decorate(orgKw); buf.replace(kwStart, kwEnd, decoratedKw); bufLc = buf.toString().toLowerCase(); startSearch = foundIdx + decoratedKw.length() + 1; } } LOG.trace("Decorated {} to {}", toDecorate, buf); return buf.toString(); }  static String decorate(String toDecorate, StringDecorator decorator, String... keywordsLc); static Optional<InetAddress> toInetAddress(String ip);  }