Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package org.apache.lucene.queryparser.flexible.core.util;

import java.util.BitSet;
import java.util.Locale;

/** CharsSequence with escaped chars information. */
Expand Down Expand Up @@ -89,21 +90,18 @@ public String toStringEscaped() {
* @return a escaped String
*/
public String toStringEscaped(char[] enabledChars) {
// TODO: non efficient implementation, refactor this code
StringBuilder result = new StringBuilder(this.length());
BitSet enabled = new BitSet(1 << 16);
for (char character : enabledChars) {
enabled.set(character);
}

for (int i = 0; i < this.length(); i++) {
if (this.chars[i] == '\\') {
char current = this.chars[i];
if (current == '\\' || (this.wasEscaped[i] && enabled.get(current))) {
result.append('\\');
} else {
for (char character : enabledChars) {
if (this.chars[i] == character && this.wasEscaped[i]) {
result.append('\\');
break;
}
}
}

result.append(this.chars[i]);
result.append(current);
}
return result.toString();
}
Expand Down
Loading