aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/jsruntime/qv4regexp_p.h
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2018-08-08 13:15:40 +0200
committerSimon Hausmann <simon.hausmann@qt.io>2018-08-15 14:24:23 +0000
commita1964f0b8e0569ef9ab754e2ec4c4d0559bc7681 (patch)
tree36416a7583527d87409ce0f9152687750a265e03 /src/qml/jsruntime/qv4regexp_p.h
parent15f56b74dc18c1105c9943f76599dbab5214b8e8 (diff)
Cleanup RegExpObject
Move properties from RegExpObject to getters in RegExp.prototype to be compliant with the JS spec. Implement support for the sticky flags ('y') and correctly parse the flags in the RegExp constructor. Change-Id: I5cf05d14e8139cf30d46235b8d466fb96084fcb7 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/qml/jsruntime/qv4regexp_p.h')
-rw-r--r--src/qml/jsruntime/qv4regexp_p.h35
1 files changed, 14 insertions, 21 deletions
diff --git a/src/qml/jsruntime/qv4regexp_p.h b/src/qml/jsruntime/qv4regexp_p.h
index 9090aaa7d5..1e35d141ca 100644
--- a/src/qml/jsruntime/qv4regexp_p.h
+++ b/src/qml/jsruntime/qv4regexp_p.h
@@ -76,7 +76,7 @@ struct RegExpCacheKey;
namespace Heap {
struct RegExp : Base {
- void init(ExecutionEngine *engine, const QString& pattern, bool ignoreCase, bool multiline, bool global, bool unicode);
+ void init(ExecutionEngine *engine, const QString& pattern, uint flags);
void destroy();
QString *pattern;
@@ -93,12 +93,10 @@ struct RegExp : Base {
}
RegExpCache *cache;
int subPatternCount;
- bool ignoreCase;
- bool multiLine;
- bool global;
- bool unicode;
+ uint flags;
bool valid;
+ QString flagsAsString() const;
int captureCount() const { return subPatternCount + 1; }
};
Q_STATIC_ASSERT(std::is_trivial< RegExp >::value);
@@ -119,11 +117,13 @@ struct RegExp : public Managed
#endif
RegExpCache *cache() const { return d()->cache; }
int subPatternCount() const { return d()->subPatternCount; }
- bool ignoreCase() const { return d()->ignoreCase; }
- bool multiLine() const { return d()->multiLine; }
- bool global() const { return d()->global; }
+ bool ignoreCase() const { return d()->flags & CompiledData::RegExp::RegExp_IgnoreCase; }
+ bool multiLine() const { return d()->flags & CompiledData::RegExp::RegExp_Multiline; }
+ bool global() const { return d()->flags & CompiledData::RegExp::RegExp_Global; }
+ bool unicode() const { return d()->flags & CompiledData::RegExp::RegExp_Unicode; }
+ bool sticky() const { return d()->flags & CompiledData::RegExp::RegExp_Sticky; }
- static Heap::RegExp *create(ExecutionEngine* engine, const QString& pattern, bool ignoreCase = false, bool multiline = false, bool global = false, bool unicode = false);
+ static Heap::RegExp *create(ExecutionEngine* engine, const QString& pattern, uint flags = CompiledData::RegExp::RegExp_NoFlags);
bool isValid() const { return d()->valid; }
@@ -136,30 +136,23 @@ struct RegExp : public Managed
struct RegExpCacheKey
{
- RegExpCacheKey(const QString &pattern, bool ignoreCase, bool multiLine, bool global)
- : pattern(pattern)
- , ignoreCase(ignoreCase)
- , multiLine(multiLine)
- , global(global)
+ RegExpCacheKey(const QString &pattern, uint flags)
+ : pattern(pattern), flags(flags)
{ }
explicit inline RegExpCacheKey(const RegExp::Data *re);
bool operator==(const RegExpCacheKey &other) const
- { return pattern == other.pattern && ignoreCase == other.ignoreCase && multiLine == other.multiLine && global == other.global; }
+ { return pattern == other.pattern && flags == other.flags;; }
bool operator!=(const RegExpCacheKey &other) const
{ return !operator==(other); }
QString pattern;
- uint ignoreCase : 1;
- uint multiLine : 1;
- uint global : 1;
+ uint flags;
};
inline RegExpCacheKey::RegExpCacheKey(const RegExp::Data *re)
: pattern(*re->pattern)
- , ignoreCase(re->ignoreCase)
- , multiLine(re->multiLine)
- , global(re->global)
+ , flags(re->flags)
{}
inline uint qHash(const RegExpCacheKey& key, uint seed = 0) Q_DECL_NOTHROW