Syntax
SelectByString(string s, string key1, value1 [, string key2, value2 [, ...]] [, "else"]) SelectByStringEval(string s, string key1, string value1 [, string key2, string value2 [, ...]] [, string "else"])
Parameters
s |
The search string. The search string is not case-sensitive for ASCII character strings. |
key1, value1 [, ...] |
If the search string matches keyN,
SelectByString returns valueN. Keys and
values must come in pairs.
|
"else" |
The default value to return if the search string is not found.
If else is not specified,
SelectByString /SelectByStringEval
will throw an error when the search string is not found.
This parameter must be named.
(See Usage.)
|
Usage
The values used with SelectByString
may be of any type and even may be a mix of types:
val = SelectByString(s, \ "foo", false, \ "bar", 1, \ "baz", 3.1415, \ else="hello world!") MessageClip(String(val))
SelectByStringEval
behaves the same as SelectByString
except that its keys and its values must be strings.
SelectByStringEval
then evaluates the matched value. That is:
SelectByStringEval(s, \ "foo", "0", \ "bar", "1")
is shorthand for:
Eval(SelectByString(s, \ "foo", "0", \ "bar", "1"))
SelectByString
is useful to create wrapper functions to specify
presets to other filters. For example:
function TemporalSoftenPreset(clip c, string "preset") { preset = Default(preset, "default") s = SelectByString(preset, \ "default", "c.TemporalSoften(4, 4, 8, 15, 2)", \ "sh0dan-soft", "c.TemporalSoften(2, 3, 3, 6, 2)", \ "sh0dan-medium", "c.TemporalSoften(3, 5, 5, 10, 2)", \ "sh0dan-heavy", "c.TemporalSoften(4, 8, 8, 10, 2)", \ else="") Assert(s != "", "TemporalSoftenPreset: invalid preset") return Eval(s) }
(In the example above, although it is not necessary to wrap the TemporalSoften(...)
calls in strings, doing so is recommended. If each call were not thunked in a string,
AviSynth would generate a separate clip for each one. Since AviSynth generates frames only when
requested, the extra clips shouldn't affect performance significantly,
although they may have negative memory consequences. Furthermore, some
filters (e.g. PixieDust
) can be called only once per script.)
See SelectByString.examples.avs for additional examples.
Revision History
-
0.3.0
-
Added the
else
parameter.
-
Added the
-
0.2.3
- Improved error reporting.
-
0.2.2
- Added stricter argument type-checking.
-
0.2.1
- Added some additional error-handling code.
-
0.2.0
- Removed dependency on the AviSynth C interface.
-
Added
SelectByStringEval
.
-
0.1.0
- Initial release.