int start = filter.indexOf(VARIABLE_START);
int end = filter.indexOf(VARIABLE_END, start);
while (start != -1) {
// Unfinished variable
if (end == -1) {
throw new InvalidSyntaxException("The filter contains an unfinished variable", filter);
}
String key = filter.substring(start + VARIABLE_START.length(), end);
// Error detection :
// Empty variable.
if (key.length() == 0) {
throw new InvalidSyntaxException("The filter variable '${}' is not a valid " +
"variable", filter);
}
// Variable with spaces.
Character forbidden = containsForbiddenCharacter(key);
if (forbidden != null) {
throw new InvalidSyntaxException("The filter variable '${" + key + "}' contains a forbidden " +
"character : '" + forbidden + "'", filter);
}
variables.add(key);