Merge pull request #509 from chme/smartplstartswith

[smartpl] Add "starts with" to smart playlist language
This commit is contained in:
ejurgensen 2018-04-11 19:04:30 +02:00 committed by GitHub
commit fe05f80822
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 3 deletions

View File

@ -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)

View File

@ -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)
;

View File

@ -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);