The current implementation is O(n^2) because StringBuilder.insert copies the remaining buffer contents for each escape.