0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-09-30 04:38:52 +02:00

ircd::js: Trap find() overload with JSString type.

This commit is contained in:
Jason Volk 2016-10-30 05:57:10 -07:00
parent 5ebd15c983
commit 3fcd3d2bb0
2 changed files with 18 additions and 1 deletions

View file

@ -72,11 +72,12 @@ class trap
auto &name() const { return _name; }
auto &jsclass() const { return *_class; }
// Search for trap by relative path
// Get child by name (NOT PATH)
const trap &child(const string &name) const;
trap &child(const string &name);
// Path is absolute to root
static trap &find(const string::handle &path);
static trap &find(const std::string &path);
operator const JSClass &() const { return jsclass(); }

View file

@ -465,6 +465,22 @@ ircd::js::trap::find(const std::string &path)
return *ret;
}
ircd::js::trap &
ircd::js::trap::find(const string::handle &path)
{
if(unlikely(!tree))
throw error("Failed to find trap tree root");
trap *ret(tree);
tokens(string(path), '.', basic::string_closure<string>([&ret]
(const string &part)
{
ret = &ret->child(part);
}));
return *ret;
}
ircd::js::trap &
ircd::js::trap::child(const string &name)
try