String (String s, QuoteFlag quoteFlag, String escapingCarets) { StringBuilder sb = new StringBuilder().append(Q); quoteFlag.toggle(); int lastPos = 0; Matcher m = WIN_CARET_SPECIAL.matcher(s); while (m.find()) { quoteFlag.update(s, lastPos, m.start()); sb.append(s, lastPos, m.start()); if (!quoteFlag.enabled) sb.append(escapingCarets); sb.append(m.group()); lastPos = m.end(); } quoteFlag.update(s, lastPos, s.length()); sb.append(s, lastPos, s.length()); quoteFlag.toggle(); return sb.append(Q).toString(); }