diff --git a/README_SMARTPL.md b/README_SMARTPL.md index aeb8ec15..afced012 100644 --- a/README_SMARTPL.md +++ b/README_SMARTPL.md @@ -44,13 +44,14 @@ Where valid field-names (with their types) are: * time_played (date) Valid operators include: -* is, includes (string) +* is, includes, starts with (string) * >, <, <=, >=, = (int) * after, before (date) * is (enumeration) The "is" operator must exactly match the field value, while the "includes" operator matches a substring. -Both matches are case-insensitive. +The "starts with" operator matches, if the value starts with the given prefix. +All three matches are case-insensitive. Valid operands include: * "string value" (string) 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);