Changed RegEx to inherit Resource

This commit is contained in:
Zher Huei Lee 2016-10-26 13:05:00 +01:00
parent c3b4686082
commit 9a5ce099f1
2 changed files with 8 additions and 4 deletions

View file

@ -985,7 +985,9 @@ static bool RegEx_is_shorthand(CharType ch) {
Error RegEx::compile(const String& p_pattern) { Error RegEx::compile(const String& p_pattern) {
if (pattern == p_pattern) ERR_FAIL_COND_V(p_pattern.length() == 0, FAILED);
if (pattern == p_pattern && root)
return OK; return OK;
clear(); clear();
@ -1421,7 +1423,7 @@ void RegEx::clear() {
if (root) if (root)
memdelete(root); memdelete(root);
pattern.clear(); root = NULL;
group_names.clear(); group_names.clear();
lookahead_depth = 0; lookahead_depth = 0;
} }
@ -1494,5 +1496,7 @@ void RegEx::_bind_methods() {
ObjectTypeDB::bind_method(_MD("get_pattern"),&RegEx::get_pattern); ObjectTypeDB::bind_method(_MD("get_pattern"),&RegEx::get_pattern);
ObjectTypeDB::bind_method(_MD("get_group_count"),&RegEx::get_group_count); ObjectTypeDB::bind_method(_MD("get_group_count"),&RegEx::get_group_count);
ObjectTypeDB::bind_method(_MD("get_names"),&RegEx::get_names); ObjectTypeDB::bind_method(_MD("get_names"),&RegEx::get_names);
ADD_PROPERTY(PropertyInfo(Variant::STRING, "pattern"), _SCS("compile"), _SCS("get_pattern"));
} }

View file

@ -78,9 +78,9 @@ public:
}; };
class RegEx : public Reference { class RegEx : public Resource {
OBJ_TYPE(RegEx, Reference); OBJ_TYPE(RegEx, Resource);
RegExNode* root; RegExNode* root;
Vector<Variant> group_names; Vector<Variant> group_names;