diff --git a/src/SMARTPL.g b/src/SMARTPL.g index 1bbd1792..b4b15702 100644 --- a/src/SMARTPL.g +++ b/src/SMARTPL.g @@ -38,7 +38,7 @@ nexpr : NOT^ crit ; crit : LPAR expression RPAR -> expression - | STRTAG (INCLUDES|IS) STR + | STRTAG (INCLUDES|IS|STARTSWITH) STR | INTTAG INTBOOL INT | DATETAG (AFTER|BEFORE) dateval | ENUMTAG IS ENUMVAL @@ -85,6 +85,9 @@ INCLUDES : 'includes' IS : 'is' ; +STARTSWITH : 'starts with' + ; + INTBOOL : (GREATER|GREATEREQUAL|LESS|LESSEQUAL|EQUAL) ; diff --git a/src/SMARTPL2SQL.g b/src/SMARTPL2SQL.g index d1ad199d..c2726ed5 100644 --- a/src/SMARTPL2SQL.g +++ b/src/SMARTPL2SQL.g @@ -114,6 +114,20 @@ expression returns [ pANTLR3_STRING result ] $result->append8($result, sqlite3_mprintf("\%q", (const char *)val)); $result->append8($result, "'"); } + | STRTAG STARTSWITH STR + { + pANTLR3_UINT8 val; + val = $STR.text->toUTF8($STR.text)->chars; + val++; + val[strlen((const char *)val) - 1] = '\0'; + + $result = $STR.text->factory->newRaw($STR.text->factory); + $result->append8($result, "f."); + $result->appendS($result, $STRTAG.text->toUTF8($STRTAG.text)); + $result->append8($result, " LIKE '"); + $result->append8($result, sqlite3_mprintf("\%q", (const char *)val)); + $result->append8($result, "\%'"); + } | INTTAG INTBOOL INT { $result = $INTTAG.text->factory->newRaw($INTTAG.text->factory);