diff --git a/src/Scripting/NasalString.cxx b/src/Scripting/NasalString.cxx index df29b862b..c3aaf609e 100644 --- a/src/Scripting/NasalString.cxx +++ b/src/Scripting/NasalString.cxx @@ -59,6 +59,18 @@ static naRef f_starts_with(naContext c, naRef me, int argc, naRef* args) return naNum( str.starts_with(rhs) ); } +/** + * Check whether string ends with other string + */ +static naRef f_ends_with(naContext c, naRef me, int argc, naRef* args) +{ + nasal::CallContext ctx(c, argc, args); + nasal::String str = nasal::from_nasal(c, me), + rhs = ctx.requireArg(0); + + return naNum( str.ends_with(rhs) ); +} + /** * Helper to convert size_t position/npos to Nasal conventions (-1 == npos) */ @@ -125,6 +137,7 @@ naRef initNasalString(naRef globals, naRef string, naContext c, naRef gcSave) string_module.set("compare", f_compare); string_module.set("starts_with", f_starts_with); + string_module.set("ends_with", f_ends_with); string_module.set("find", f_find); string_module.set("find_first_of", f_find_first_of); string_module.set("find_first_not_of", f_find_first_not_of);