mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 10:38:11 +00:00
LibJS: Make escape_regexp_pattern() a RegExpObject member function
Similarly to regexp_initialize() this can be a member function instead of taking a RegExpObject argument. Having it available outside RegExpPrototype is also useful for other things that need RegExp.prototype.source behavior - e.g. the REPL for pretty-printing.
This commit is contained in:
parent
83bd675477
commit
78fd8c1ca2
3 changed files with 12 additions and 11 deletions
|
@ -10,6 +10,7 @@
|
|||
#include <LibJS/Runtime/RegExpObject.h>
|
||||
#include <LibJS/Runtime/StringPrototype.h>
|
||||
#include <LibJS/Runtime/Value.h>
|
||||
#include <LibJS/Token.h>
|
||||
|
||||
namespace JS {
|
||||
|
||||
|
@ -188,6 +189,15 @@ RegExpObject* RegExpObject::regexp_initialize(GlobalObject& global_object, Value
|
|||
return this;
|
||||
}
|
||||
|
||||
// 22.2.3.2.5 EscapeRegExpPattern ( P, F ), https://tc39.es/ecma262/#sec-escaperegexppattern
|
||||
String RegExpObject::escape_regexp_pattern() const
|
||||
{
|
||||
if (m_pattern.is_empty())
|
||||
return "(?:)";
|
||||
// FIXME: Check u flag and escape accordingly
|
||||
return m_pattern.replace("\n", "\\n", true).replace("\r", "\\r", true).replace(LINE_SEPARATOR_STRING, "\\u2028", true).replace(PARAGRAPH_SEPARATOR_STRING, "\\u2029", true).replace("/", "\\/", true);
|
||||
}
|
||||
|
||||
// 22.2.3.2.4 RegExpCreate ( P, F ), https://tc39.es/ecma262/#sec-regexpcreate
|
||||
RegExpObject* regexp_create(GlobalObject& global_object, Value pattern, Value flags)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue