mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-05-08 20:22:55 +00:00
RegExpInitialize specifies how the pattern string should be created before passing it to [[RegExpMatcher]]. Rather than passing it as-is, the string should be converted to code points and back to a "List" (if the Unicode flag is present), or as a "List" of UTF-16 code units. Further. the spec requires that we keep both the original pattern string and this parsed string in the RegExp object. The caveat is that the LibRegex parser further requires any multi-byte code units to be escaped (as "\unnnn"). Otherwise, the code unit is recognized as individual UTF-8 bytes.
46 lines
1.3 KiB
C++
46 lines
1.3 KiB
C++
/*
|
|
* Copyright (c) 2020, Matthew Olsson <mattco@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <LibJS/AST.h>
|
|
#include <LibJS/Runtime/Object.h>
|
|
#include <LibRegex/Regex.h>
|
|
|
|
struct Flags {
|
|
regex::RegexOptions<ECMAScriptFlags> effective_flags;
|
|
regex::RegexOptions<ECMAScriptFlags> declared_flags;
|
|
};
|
|
|
|
namespace JS {
|
|
|
|
RegExpObject* regexp_create(GlobalObject&, Value pattern, Value flags);
|
|
|
|
class RegExpObject : public Object {
|
|
JS_OBJECT(RegExpObject, Object);
|
|
|
|
public:
|
|
static RegExpObject* create(GlobalObject&, String original_pattern, String parsed_pattern, String flags);
|
|
|
|
RegExpObject(String original_pattern, String parsed_pattern, String flags, Object& prototype);
|
|
virtual void initialize(GlobalObject&) override;
|
|
virtual ~RegExpObject() override;
|
|
|
|
const String& pattern() const { return m_original_pattern; }
|
|
const String& flags() const { return m_flags; }
|
|
const regex::RegexOptions<ECMAScriptFlags>& declared_options() { return m_active_flags.declared_flags; }
|
|
const Regex<ECMA262>& regex() { return m_regex; }
|
|
const Regex<ECMA262>& regex() const { return m_regex; }
|
|
|
|
private:
|
|
String m_original_pattern;
|
|
String m_parsed_pattern;
|
|
String m_flags;
|
|
Flags m_active_flags;
|
|
Regex<ECMA262> m_regex;
|
|
};
|
|
|
|
}
|