Skip to content

Commit

Permalink
Allow TAB CR and LF in expression strings
Browse files Browse the repository at this point in the history
  • Loading branch information
pinterf committed Oct 5, 2021
1 parent 2ad840b commit 132614c
Show file tree
Hide file tree
Showing 16 changed files with 33 additions and 30 deletions.
3 changes: 3 additions & 0 deletions common/parser/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

namespace Filtering { namespace Parser {

constexpr auto SYMBOL_SEPARATORS = " \r\n\t";
constexpr auto SYMBOL_SEPARATORS_COORD = " \r\n\t(),;.";

class Parser {
String parsed_string;
String error_string;
Expand Down
2 changes: 1 addition & 1 deletion masktools/filters/blur/mappedblur.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class MappedBlur : public MaskTools::Filter
bits_per_pixel = bit_depths[C];
bool isFloat = bits_per_pixel == 32;

auto coeffs = Parser::getDefaultParser().parse(parameters["kernel"].toString(), " ").getExpression();
auto coeffs = Parser::getDefaultParser().parse(parameters["kernel"].toString(), Parser::SYMBOL_SEPARATORS).getExpression();

if (isFloat) {
memset(matrix_f, 0, sizeof(matrix_f));
Expand Down
4 changes: 2 additions & 2 deletions masktools/filters/convolution/convolution.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ class Convolution : public MaskTools::Filter
i_vertical = i_horizontal = NULL;
f_vertical = f_horizontal = NULL;
vertical = horizontal = NULL;
auto hcoeffs = Parser::getDefaultParser().parse(parameters["horizontal"].toString(), " ").getExpression();
auto vcoeffs = Parser::getDefaultParser().parse(parameters["vertical"].toString(), " ").getExpression();
auto hcoeffs = Parser::getDefaultParser().parse(parameters["horizontal"].toString(), Parser::SYMBOL_SEPARATORS).getExpression();
auto vcoeffs = Parser::getDefaultParser().parse(parameters["vertical"].toString(), Parser::SYMBOL_SEPARATORS).getExpression();
nHorizontal = hcoeffs.size();
nVertical = vcoeffs.size();

Expand Down
6 changes: 3 additions & 3 deletions masktools/filters/lut/functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class Nonizer {
public:
Nonizer(const String &mode)
{
auto coefficients = Parser::getDefaultParser().parse(mode, " (),;").getExpression();
auto coefficients = Parser::getDefaultParser().parse(mode, Parser::SYMBOL_SEPARATORS_COORD).getExpression();
nCoefficients = coefficients.size();
pdCoefficients = new Double[nCoefficients];
int i = 0;
Expand Down Expand Up @@ -359,7 +359,7 @@ class Nonizer16 {
public:
Nonizer16(const String &mode)
{
auto coefficients = Parser::getDefaultParser().parse(mode, " (),;").getExpression();
auto coefficients = Parser::getDefaultParser().parse(mode, Parser::SYMBOL_SEPARATORS_COORD).getExpression();
nCoefficients = coefficients.size();
pdCoefficients = new Double[nCoefficients];
int i = 0;
Expand Down Expand Up @@ -605,7 +605,7 @@ class Nonizer32 {
public:
Nonizer32(const String &mode)
{
auto coefficients = Parser::getDefaultParser().parse(mode, " (),;").getExpression();
auto coefficients = Parser::getDefaultParser().parse(mode, Parser::SYMBOL_SEPARATORS_COORD).getExpression();
nCoefficients = coefficients.size();
pdCoefficients = new Double[nCoefficients];
int i = 0;
Expand Down
4 changes: 2 additions & 2 deletions masktools/filters/lut/lut/lut.h
Original file line number Diff line number Diff line change
Expand Up @@ -242,11 +242,11 @@ class Lutx : public MaskTools::Filter

bool customExpressionDefined = false;
if (parameters[expr_strs[i]].is_defined()) {
parser.parse_strict(parameters[expr_strs[i]].toString(), " ");
parser.parse_strict(parameters[expr_strs[i]].toString(), Parser::SYMBOL_SEPARATORS);
customExpressionDefined = true;
}
else
parser.parse_strict(parameters["expr"].toString(), " ");
parser.parse_strict(parameters["expr"].toString(), Parser::SYMBOL_SEPARATORS);

auto err_pos = parser.getErrorPos();
if (err_pos >= 0) {
Expand Down
4 changes: 2 additions & 2 deletions masktools/filters/lut/lutf/lutf.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,11 @@ class Lutf : public MaskTools::Filter

bool customExpressionDefined = false;
if (parameters[expr_strs[i]].is_defined()) {
parser.parse_strict(parameters[expr_strs[i]].toString(), " ");
parser.parse_strict(parameters[expr_strs[i]].toString(), Parser::SYMBOL_SEPARATORS);
customExpressionDefined = true;
}
else
parser.parse_strict(parameters["expr"].toString(), " ");
parser.parse_strict(parameters["expr"].toString(), Parser::SYMBOL_SEPARATORS);

auto err_pos = parser.getErrorPos();
if (err_pos >= 0) {
Expand Down
10 changes: 5 additions & 5 deletions masktools/filters/lut/luts/luts.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ class Luts : public MaskTools::Filter

void FillCoordinates(const String &coordinates)
{
auto coeffs = Parser::getDefaultParser().parse( coordinates, " (),;." ).getExpression();
auto coeffs = Parser::getDefaultParser().parse( coordinates, Parser::SYMBOL_SEPARATORS_COORD).getExpression();
nCoordinates = coeffs.size();
pCoordinates = new int[nCoordinates];
int i = 0;
Expand Down Expand Up @@ -261,11 +261,11 @@ class Luts : public MaskTools::Filter
//----- main expression
bool customExpressionDefined = false;
if (parameters[expr_strs[i]].is_defined()) {
parser.parse_strict(parameters[expr_strs[i]].toString(), " ");
parser.parse_strict(parameters[expr_strs[i]].toString(), Parser::SYMBOL_SEPARATORS);
customExpressionDefined = true;
}
else
parser.parse_strict(parameters["expr"].toString(), " ");
parser.parse_strict(parameters["expr"].toString(), Parser::SYMBOL_SEPARATORS);

auto err_pos = parser.getErrorPos();
if (err_pos >= 0) {
Expand Down Expand Up @@ -306,11 +306,11 @@ class Luts : public MaskTools::Filter
//Part #2 ----- weight expression
bool customExpressionDefined_w = false;
if (parameters[expr_strs_w[i]].is_defined()) {
parser.parse_strict(parameters[expr_strs_w[i]].toString(), " ");
parser.parse_strict(parameters[expr_strs_w[i]].toString(), Parser::SYMBOL_SEPARATORS);
customExpressionDefined_w = true;
}
else if (parameters["wexpr"].is_defined()) {
parser.parse_strict(parameters["wexpr"].toString(), " ");
parser.parse_strict(parameters["wexpr"].toString(), Parser::SYMBOL_SEPARATORS);
}
else {
continue; // no parse context/lut will be used for weights
Expand Down
4 changes: 2 additions & 2 deletions masktools/filters/lut/lutspa/lutspa.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ class Lutspa : public MaskTools::Filter
const int w = i ? nCoreWidthUV : nCoreWidth;
const int h = i ? nCoreHeightUV : nCoreHeight;
if ( parameters[expr_strs[i]].is_defined() )
parser.parse_strict(parameters[expr_strs[i]].toString(), " ");
parser.parse_strict(parameters[expr_strs[i]].toString(), Parser::SYMBOL_SEPARATORS);
else
parser.parse_strict(parameters["expr"].toString(), " ");
parser.parse_strict(parameters["expr"].toString(), Parser::SYMBOL_SEPARATORS);

auto err_pos = parser.getErrorPos();
if (err_pos >= 0) {
Expand Down
6 changes: 3 additions & 3 deletions masktools/filters/lut/lutsx/lutsx.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class Lutsx : public MaskTools::Filter

void FillCoordinates(const String &coordinates)
{
auto coeffs = Parser::getDefaultParser().parse( coordinates, " (),;." ).getExpression();
auto coeffs = Parser::getDefaultParser().parse( coordinates, Parser::SYMBOL_SEPARATORS_COORD).getExpression();
nCoordinates = coeffs.size();
pCoordinates = new int[nCoordinates];
int i = 0;
Expand Down Expand Up @@ -146,11 +146,11 @@ class Lutsx : public MaskTools::Filter

bool customExpressionDefined = false;
if (parameters[expr_strs[i]].is_defined()) {
parser.parse_strict(parameters[expr_strs[i]].toString(), " ");
parser.parse_strict(parameters[expr_strs[i]].toString(), Parser::SYMBOL_SEPARATORS);
customExpressionDefined = true;
}
else
parser.parse_strict(parameters["expr"].toString(), " ");
parser.parse_strict(parameters["expr"].toString(), Parser::SYMBOL_SEPARATORS);

auto err_pos = parser.getErrorPos();
if (err_pos >= 0) {
Expand Down
4 changes: 2 additions & 2 deletions masktools/filters/lut/lutxy/lutxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -236,11 +236,11 @@ class Lutxy : public MaskTools::Filter

bool customExpressionDefined = false;
if (parameters[expr_strs[i]].is_defined()) {
parser.parse_strict(parameters[expr_strs[i]].toString(), " ");
parser.parse_strict(parameters[expr_strs[i]].toString(), Parser::SYMBOL_SEPARATORS);
customExpressionDefined = true;
}
else
parser.parse_strict(parameters["expr"].toString(), " ");
parser.parse_strict(parameters["expr"].toString(), Parser::SYMBOL_SEPARATORS);

auto err_pos = parser.getErrorPos();
if (err_pos >= 0) {
Expand Down
4 changes: 2 additions & 2 deletions masktools/filters/lut/lutxyz/lutxyz.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,11 @@ class Lutxyz : public MaskTools::Filter

bool customExpressionDefined = false;
if (parameters[expr_strs[i]].is_defined()) {
parser.parse_strict(parameters[expr_strs[i]].toString(), " ");
parser.parse_strict(parameters[expr_strs[i]].toString(), Parser::SYMBOL_SEPARATORS);
customExpressionDefined = true;
}
else
parser.parse_strict(parameters["expr"].toString(), " ");
parser.parse_strict(parameters["expr"].toString(), Parser::SYMBOL_SEPARATORS);

auto err_pos = parser.getErrorPos();
if (err_pos >= 0) {
Expand Down
4 changes: 2 additions & 2 deletions masktools/filters/lut/lutxyza/lutxyza.h
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,11 @@ class Lutxyza : public MaskTools::Filter

bool customExpressionDefined = false;
if (parameters[expr_strs[i]].is_defined()) {
parser.parse_strict(parameters[expr_strs[i]].toString(), " ");
parser.parse_strict(parameters[expr_strs[i]].toString(), Parser::SYMBOL_SEPARATORS);
customExpressionDefined = true;
}
else
parser.parse_strict(parameters["expr"].toString(), " ");
parser.parse_strict(parameters["expr"].toString(), Parser::SYMBOL_SEPARATORS);

auto err_pos = parser.getErrorPos();
if (err_pos >= 0) {
Expand Down
2 changes: 1 addition & 1 deletion masktools/filters/mask/edge/edgemask.h
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ class EdgeMask : public MaskTools::Filter
else
{
print(LOG_DEBUG, "Edge : using custom detector");
auto coeffs = Parser::getDefaultParser().parse(parameters["mode"].toString(), " ").getExpression();
auto coeffs = Parser::getDefaultParser().parse(parameters["mode"].toString(), Parser::SYMBOL_SEPARATORS).getExpression();
bool isAsmOk = true;
if (isFloat) {
memset(matrix_f, 0, sizeof(matrix_f));
Expand Down
2 changes: 1 addition & 1 deletion masktools/filters/morphologic/morphologic.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class MorphologicFilter : public MaskTools::Filter

void FillCoordinates(const String &coordinates)
{
auto coeffs = Parser::getDefaultParser().parse(coordinates, " (),;.").getExpression();
auto coeffs = Parser::getDefaultParser().parse(coordinates, Parser::SYMBOL_SEPARATORS_COORD).getExpression();
coordinates_count = coeffs.size();
coordinates_list = new int[coordinates_count];
int i = 0;
Expand Down
2 changes: 1 addition & 1 deletion masktools/filters/morphologic/morphologic16.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class MorphologicFilter16 : public MaskTools::Filter

void FillCoordinates(const String &coordinates)
{
auto coeffs = Parser::getDefaultParser().parse( coordinates, " (),;." ).getExpression();
auto coeffs = Parser::getDefaultParser().parse( coordinates, Parser::SYMBOL_SEPARATORS_COORD).getExpression();
coordinates_count = coeffs.size();
coordinates_list = new int[coordinates_count];
int i = 0;
Expand Down
2 changes: 1 addition & 1 deletion masktools/helpers/parser/spirit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ String Converter(const String &str)
String Infix(const String &str)
{
Parser::Parser parser = Parser::getDefaultParser().addSymbol(Parser::Symbol::X).addSymbol(Parser::Symbol::Y).addSymbol(Parser::Symbol::Z);
parser.parse(str, " ");
parser.parse(str, Parser::SYMBOL_SEPARATORS);
Parser::Context ctx(parser.getExpression());
return ctx.infix();
}
Expand Down

0 comments on commit 132614c

Please sign in to comment.