### Question:
StringRewriter extends RapidoidThing { public String rewrite(String target, Mapper<String[], String> replacer) { String mask = Str.mask(target, escape); return Str.replace(target, mask, regex, replacer); } StringRewriter(String[] escape, String regex); String rewrite(String target, Mapper<String[], String> replacer); static final String MASK_QUOTES; static final String MASK_DOUBLE_QUOTES; static final String MASK_BACKTICKS; static final String[] ALL_QUOTES; }### Answer:
@Test public void testRewriter() { String[] esc = {StringRewriter.MASK_QUOTES, StringRewriter.MASK_DOUBLE_QUOTES}; StringRewriter rewriter = new StringRewriter(esc, "\\w+"); Mapper<String[], String> replacer = groups -> "<" + groups[0].toUpperCase() + ">"; eq(rewriter.rewrite("", replacer), ""); eq(rewriter.rewrite("a", replacer), "<A>"); eq(rewriter.rewrite("*()", replacer), "*()"); eq(rewriter.rewrite("'x'", replacer), "'x'"); eq(rewriter.rewrite("'x", replacer), "'<X>"); eq(rewriter.rewrite("x'", replacer), "<X>'"); eq(rewriter.rewrite("aa 'b c dd' xy", replacer), "<AA> 'b c dd' <XY>"); eq(rewriter.rewrite("aa \"b c dd\" xy", replacer), "<AA> \"b c dd\" <XY>"); eq(rewriter.rewrite("a-b-c-0-1-2", replacer), "<A>-<B>-<C>-<0>-<1>-<2>"); eq(rewriter.rewrite("a-'b'-c-'0'-1-'2", replacer), "<A>-'b'-<C>-'0'-<1>-'<2>"); }