[smartpl] Support "starts with" operator for string fields

This commit is contained in:
chme 2015-07-04 05:50:11 +02:00
parent ea4ea072cd
commit 879307f3ac
2 changed files with 18 additions and 1 deletions

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