use of org.apache.commons.text.StringSubstitutor in project jdbi by jdbi.
the class StringSubstitutorTemplateEngine method render.
@Override
public String render(String template, StatementContext ctx) {
StringSubstitutor substitutor = new StringSubstitutor(ctx.getAttributes());
customizer.accept(substitutor);
return substitutor.replace(template);
}
use of org.apache.commons.text.StringSubstitutor in project commons-text by apache.
the class StringSubstitutorGetSetTest method testGetSetValueDelimiter.
/**
* Tests get set.
*/
@Test
public void testGetSetValueDelimiter() {
final StringSubstitutor sub = new StringSubstitutor();
assertTrue(sub.getValueDelimiterMatcher() instanceof AbstractStringMatcher.CharArrayMatcher);
sub.setValueDelimiter(':');
assertTrue(sub.getValueDelimiterMatcher() instanceof AbstractStringMatcher.CharMatcher);
sub.setValueDelimiter("||");
assertTrue(sub.getValueDelimiterMatcher() instanceof AbstractStringMatcher.CharArrayMatcher);
sub.setValueDelimiter((String) null);
assertNull(sub.getValueDelimiterMatcher());
final StringMatcher matcher = StringMatcherFactory.INSTANCE.commaMatcher();
sub.setValueDelimiterMatcher(matcher);
assertSame(matcher, sub.getValueDelimiterMatcher());
sub.setValueDelimiterMatcher((StringMatcher) null);
assertNull(sub.getValueDelimiterMatcher());
}
use of org.apache.commons.text.StringSubstitutor in project commons-text by apache.
the class StringSubstitutorGetSetTest method testGetSetSuffix.
/**
* Tests get set.
*/
@Test
public void testGetSetSuffix() {
final StringSubstitutor sub = new StringSubstitutor();
assertTrue(sub.getVariableSuffixMatcher() instanceof AbstractStringMatcher.CharMatcher);
sub.setVariableSuffix('<');
assertTrue(sub.getVariableSuffixMatcher() instanceof AbstractStringMatcher.CharMatcher);
sub.setVariableSuffix("<<");
assertTrue(sub.getVariableSuffixMatcher() instanceof AbstractStringMatcher.CharArrayMatcher);
assertThrows(IllegalArgumentException.class, () -> sub.setVariableSuffix((String) null));
assertTrue(sub.getVariableSuffixMatcher() instanceof AbstractStringMatcher.CharArrayMatcher);
final StringMatcher matcher = StringMatcherFactory.INSTANCE.commaMatcher();
sub.setVariableSuffixMatcher(matcher);
assertSame(matcher, sub.getVariableSuffixMatcher());
assertThrows(IllegalArgumentException.class, () -> sub.setVariableSuffixMatcher((StringMatcher) null));
assertSame(matcher, sub.getVariableSuffixMatcher());
}
use of org.apache.commons.text.StringSubstitutor in project commons-text by apache.
the class StringSubstitutorGetSetTest method testGetSetPrefix.
/**
* Tests get set.
*/
@Test
public void testGetSetPrefix() {
final StringSubstitutor sub = new StringSubstitutor();
assertTrue(sub.getVariablePrefixMatcher() instanceof AbstractStringMatcher.CharArrayMatcher);
sub.setVariablePrefix('<');
assertTrue(sub.getVariablePrefixMatcher() instanceof AbstractStringMatcher.CharMatcher);
sub.setVariablePrefix("<<");
assertTrue(sub.getVariablePrefixMatcher() instanceof AbstractStringMatcher.CharArrayMatcher);
assertThrows(IllegalArgumentException.class, () -> sub.setVariablePrefix((String) null));
assertTrue(sub.getVariablePrefixMatcher() instanceof AbstractStringMatcher.CharArrayMatcher);
final StringMatcher matcher = StringMatcherFactory.INSTANCE.commaMatcher();
sub.setVariablePrefixMatcher(matcher);
assertSame(matcher, sub.getVariablePrefixMatcher());
assertThrows(IllegalArgumentException.class, () -> sub.setVariablePrefixMatcher((StringMatcher) null));
assertSame(matcher, sub.getVariablePrefixMatcher());
}
use of org.apache.commons.text.StringSubstitutor in project commons-text by apache.
the class StringSubstitutorFilterReaderTest method testReadMixedBufferLengthsVarLenPlusToNoReplace.
@Test
public void testReadMixedBufferLengthsVarLenPlusToNoReplace() throws IOException {
final StringSubstitutor substitutor = new StringSubstitutor(values);
final String template = "123456";
assertTrue(template.length() > getMinExpressionLength(substitutor) + 1);
try (Reader reader = createReader(substitutor, template)) {
final int endIndex = template.length() - 1;
final char[] cbuf = new char[endIndex];
reader.read(cbuf);
final String result = String.valueOf(cbuf);
assertEquals(template.substring(0, endIndex), result);
assertEquals('6', reader.read());
}
}
Aggregations