summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--modules/regex/regex.cpp8
-rw-r--r--modules/regex/regex.h4
2 files changed, 8 insertions, 4 deletions
diff --git a/modules/regex/regex.cpp b/modules/regex/regex.cpp
index 388e6dfdec..a0f4b4934c 100644
--- a/modules/regex/regex.cpp
+++ b/modules/regex/regex.cpp
@@ -985,7 +985,9 @@ static bool RegEx_is_shorthand(CharType ch) {
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;
clear();
@@ -1421,7 +1423,7 @@ void RegEx::clear() {
if (root)
memdelete(root);
- pattern.clear();
+ root = NULL;
group_names.clear();
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_group_count"),&RegEx::get_group_count);
ObjectTypeDB::bind_method(_MD("get_names"),&RegEx::get_names);
+
+ ADD_PROPERTY(PropertyInfo(Variant::STRING, "pattern"), _SCS("compile"), _SCS("get_pattern"));
}
diff --git a/modules/regex/regex.h b/modules/regex/regex.h
index 8d31b84773..803aa72b3f 100644
--- a/modules/regex/regex.h
+++ b/modules/regex/regex.h
@@ -78,9 +78,9 @@ public:
};
-class RegEx : public Reference {
+class RegEx : public Resource {
- OBJ_TYPE(RegEx, Reference);
+ OBJ_TYPE(RegEx, Resource);
RegExNode* root;
Vector<Variant> group_names;