javax0.geci.jamal.macros.Contains Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of javageci-jamal Show documentation
Show all versions of javageci-jamal Show documentation
Javageci jamal macro library
package javax0.geci.jamal.macros;
import javax0.jamal.api.BadSyntax;
import javax0.jamal.api.Input;
import javax0.jamal.api.Macro;
import javax0.jamal.api.Processor;
import javax0.jamal.tools.InputHandler;
/**
* A simple implementation of the String.contains functionality. It can be used as
*
* {@code
* {%@contains /something/ in a string%}
* }
*
* The arguments can be separated by space in case the {@code something} does not contain any space, using any non alpha
* numeric character or using `regex` as defined in {@link javax0.jamal.tools.InputHandler#getParts(Input) getParts()}
*/
public class Contains implements Macro {
@Override
public String evaluate(Input in, Processor processor) throws BadSyntax {
final var parts = InputHandler.getParts(in, 2);
if (parts.length < 2) {
throw new BadSyntax("{@contains A B} needs two arguments");
}
return "" + parts[1].contains(parts[0]);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy