@Test public void randomized() throws Exception { Random r = new Random(1); String set = "abc*\'\"<> "; for (int i = 0; i < 10000; i++) { highlight(sb(randomString(r, set)), of(randomString(r, set))); } }
static String highlight(StringBuilder text, Set<String> searchToken) { Set<String> tokens = tokenize(searchToken); String escaped = encodeIllegalXMLCharacters(text.toString()); BitSet highlight = new BitSet(); for (String token : tokens) { highlight(escaped, highlight, token); } StringBuilder excerpt = new StringBuilder(EXCERPT_BEGIN); boolean strong = false; for (int i = 0; i < escaped.length(); i++) { if (highlight.get(i) && !strong) { strong = true; excerpt.append("<strong>"); } else if (!highlight.get(i) && strong) { strong = false; excerpt.append("</strong>"); } excerpt.append(escaped.charAt(i)); } if (strong) { excerpt.append("</strong>"); } excerpt.append(EXCERPT_END); return excerpt.toString(); }
SimpleExcerptProvider { static String highlight(StringBuilder text, Set<String> searchToken) { Set<String> tokens = tokenize(searchToken); String escaped = encodeIllegalXMLCharacters(text.toString()); BitSet highlight = new BitSet(); for (String token : tokens) { highlight(escaped, highlight, token); } StringBuilder excerpt = new StringBuilder(EXCERPT_BEGIN); boolean strong = false; for (int i = 0; i < escaped.length(); i++) { if (highlight.get(i) && !strong) { strong = true; excerpt.append("<strong>"); } else if (!highlight.get(i) && strong) { strong = false; excerpt.append("</strong>"); } excerpt.append(escaped.charAt(i)); } if (strong) { excerpt.append("</strong>"); } excerpt.append(EXCERPT_END); return excerpt.toString(); } }
SimpleExcerptProvider { static String highlight(StringBuilder text, Set<String> searchToken) { Set<String> tokens = tokenize(searchToken); String escaped = encodeIllegalXMLCharacters(text.toString()); BitSet highlight = new BitSet(); for (String token : tokens) { highlight(escaped, highlight, token); } StringBuilder excerpt = new StringBuilder(EXCERPT_BEGIN); boolean strong = false; for (int i = 0; i < escaped.length(); i++) { if (highlight.get(i) && !strong) { strong = true; excerpt.append("<strong>"); } else if (!highlight.get(i) && strong) { strong = false; excerpt.append("</strong>"); } excerpt.append(escaped.charAt(i)); } if (strong) { excerpt.append("</strong>"); } excerpt.append(EXCERPT_END); return excerpt.toString(); } private  SimpleExcerptProvider(); }
SimpleExcerptProvider { static String highlight(StringBuilder text, Set<String> searchToken) { Set<String> tokens = tokenize(searchToken); String escaped = encodeIllegalXMLCharacters(text.toString()); BitSet highlight = new BitSet(); for (String token : tokens) { highlight(escaped, highlight, token); } StringBuilder excerpt = new StringBuilder(EXCERPT_BEGIN); boolean strong = false; for (int i = 0; i < escaped.length(); i++) { if (highlight.get(i) && !strong) { strong = true; excerpt.append("<strong>"); } else if (!highlight.get(i) && strong) { strong = false; excerpt.append("</strong>"); } excerpt.append(escaped.charAt(i)); } if (strong) { excerpt.append("</strong>"); } excerpt.append(EXCERPT_END); return excerpt.toString(); } private  SimpleExcerptProvider(); static int indexOfIgnoreCase(String str, String searchStr, int startPos); }
SimpleExcerptProvider { static String highlight(StringBuilder text, Set<String> searchToken) { Set<String> tokens = tokenize(searchToken); String escaped = encodeIllegalXMLCharacters(text.toString()); BitSet highlight = new BitSet(); for (String token : tokens) { highlight(escaped, highlight, token); } StringBuilder excerpt = new StringBuilder(EXCERPT_BEGIN); boolean strong = false; for (int i = 0; i < escaped.length(); i++) { if (highlight.get(i) && !strong) { strong = true; excerpt.append("<strong>"); } else if (!highlight.get(i) && strong) { strong = false; excerpt.append("</strong>"); } excerpt.append(escaped.charAt(i)); } if (strong) { excerpt.append("</strong>"); } excerpt.append(EXCERPT_END); return excerpt.toString(); } private  SimpleExcerptProvider(); static int indexOfIgnoreCase(String str, String searchStr, int startPos);  }