mirror of
https://github.com/nosqlbench/nosqlbench.git
synced 2025-02-25 18:55:28 -06:00
rollback escaping support in template, as it is global
This commit is contained in:
parent
6e027ed3b7
commit
0405eb74fb
@ -94,7 +94,7 @@ public class Template implements LongFunction<String> {
|
||||
pos = m.end();
|
||||
}
|
||||
String partial = template.substring(pos);
|
||||
partial = unescape(partial);
|
||||
// partial = unescape(partial);
|
||||
literals.add(partial);
|
||||
if (literals.size() != funcCount + 1) {
|
||||
throw new RuntimeException("The number of {} place holders in '" + template + "' should equal the number of functions.");
|
||||
@ -105,28 +105,28 @@ public class Template implements LongFunction<String> {
|
||||
}
|
||||
}
|
||||
|
||||
// for testing
|
||||
public String unescape(String partial) {
|
||||
StringBuilder unescaped = new StringBuilder();
|
||||
try {
|
||||
Pattern escapes = Pattern.compile("\\\\.");
|
||||
Matcher m = escapes.matcher(partial);
|
||||
int pos = 0;
|
||||
|
||||
while (m.find()) {
|
||||
String prefix = partial.substring(pos,m.start());
|
||||
unescaped.append(prefix);
|
||||
String segment = partial.substring(m.start(),m.end());
|
||||
unescaped.append(segment.substring(1));
|
||||
pos = m.end();
|
||||
}
|
||||
unescaped.append(partial.substring(pos));
|
||||
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return unescaped.toString();
|
||||
}
|
||||
// // for testing
|
||||
// public String unescape(String partial) {
|
||||
// StringBuilder unescaped = new StringBuilder();
|
||||
// try {
|
||||
// Pattern escapes = Pattern.compile("\\\\.");
|
||||
// Matcher m = escapes.matcher(partial);
|
||||
// int pos = 0;
|
||||
//
|
||||
// while (m.find()) {
|
||||
// String prefix = partial.substring(pos,m.start());
|
||||
// unescaped.append(prefix);
|
||||
// String segment = partial.substring(m.start(),m.end());
|
||||
// unescaped.append(segment.substring(1));
|
||||
// pos = m.end();
|
||||
// }
|
||||
// unescaped.append(partial.substring(pos));
|
||||
//
|
||||
// } catch (Exception e) {
|
||||
// throw new RuntimeException(e);
|
||||
// }
|
||||
// return unescaped.toString();
|
||||
// }
|
||||
|
||||
@Override
|
||||
public String apply(long value) {
|
||||
|
@ -52,25 +52,25 @@ public class TemplateTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnescaping() {
|
||||
String escaped="front \\' back";
|
||||
LongFunction<String> func = String::valueOf;
|
||||
Template template = new Template("{} extra", func);
|
||||
String unescaped = template.unescape(escaped);
|
||||
assertThat(unescaped).isEqualTo("front ' back");
|
||||
|
||||
String unescaped2= template.unescape("\\' one \\' two \\'");
|
||||
assertThat(unescaped2).isEqualTo("' one ' two '");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBackslashUnescaping() {
|
||||
String escaped="front \\\\\" back";
|
||||
LongFunction<String> func = String::valueOf;
|
||||
Template template = new Template("{} extra", func);
|
||||
String unescaped = template.unescape(escaped);
|
||||
assertThat(unescaped).isEqualTo("front \\\" back");
|
||||
|
||||
}
|
||||
// @Test
|
||||
// public void testUnescaping() {
|
||||
// String escaped="front \\' back";
|
||||
// LongFunction<String> func = String::valueOf;
|
||||
// Template template = new Template("{} extra", func);
|
||||
// String unescaped = template.unescape(escaped);
|
||||
// assertThat(unescaped).isEqualTo("front ' back");
|
||||
//
|
||||
// String unescaped2= template.unescape("\\' one \\' two \\'");
|
||||
// assertThat(unescaped2).isEqualTo("' one ' two '");
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void testBackslashUnescaping() {
|
||||
// String escaped="front \\\\\" back";
|
||||
// LongFunction<String> func = String::valueOf;
|
||||
// Template template = new Template("{} extra", func);
|
||||
// String unescaped = template.unescape(escaped);
|
||||
// assertThat(unescaped).isEqualTo("front \\\" back");
|
||||
//
|
||||
// }
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user