![]() |
|
|||
File indexing completed on 2025-02-22 10:42:34
0001 0002 // Copyright 2021 the V8 project authors. All rights reserved. 0003 // Use of this source code is governed by a BSD-style license that can be 0004 // found in the LICENSE file. 0005 0006 #ifndef INCLUDE_V8_REGEXP_H_ 0007 #define INCLUDE_V8_REGEXP_H_ 0008 0009 #include "v8-local-handle.h" // NOLINT(build/include_directory) 0010 #include "v8-object.h" // NOLINT(build/include_directory) 0011 #include "v8config.h" // NOLINT(build/include_directory) 0012 0013 namespace v8 { 0014 0015 class Context; 0016 0017 /** 0018 * An instance of the built-in RegExp constructor (ECMA-262, 15.10). 0019 */ 0020 class V8_EXPORT RegExp : public Object { 0021 public: 0022 /** 0023 * Regular expression flag bits. They can be or'ed to enable a set 0024 * of flags. 0025 * The kLinear value ('l') is experimental and can only be used with 0026 * --enable-experimental-regexp-engine. RegExps with kLinear flag are 0027 * guaranteed to be executed in asymptotic linear time wrt. the length of 0028 * the subject string. 0029 */ 0030 enum Flags { 0031 kNone = 0, 0032 kGlobal = 1 << 0, 0033 kIgnoreCase = 1 << 1, 0034 kMultiline = 1 << 2, 0035 kSticky = 1 << 3, 0036 kUnicode = 1 << 4, 0037 kDotAll = 1 << 5, 0038 kLinear = 1 << 6, 0039 kHasIndices = 1 << 7, 0040 kUnicodeSets = 1 << 8, 0041 }; 0042 0043 static constexpr int kFlagCount = 9; 0044 0045 /** 0046 * Creates a regular expression from the given pattern string and 0047 * the flags bit field. May throw a JavaScript exception as 0048 * described in ECMA-262, 15.10.4.1. 0049 * 0050 * For example, 0051 * RegExp::New(v8::String::New("foo"), 0052 * static_cast<RegExp::Flags>(kGlobal | kMultiline)) 0053 * is equivalent to evaluating "/foo/gm". 0054 */ 0055 static V8_WARN_UNUSED_RESULT MaybeLocal<RegExp> New(Local<Context> context, 0056 Local<String> pattern, 0057 Flags flags); 0058 0059 /** 0060 * Like New, but additionally specifies a backtrack limit. If the number of 0061 * backtracks done in one Exec call hits the limit, a match failure is 0062 * immediately returned. 0063 */ 0064 static V8_WARN_UNUSED_RESULT MaybeLocal<RegExp> NewWithBacktrackLimit( 0065 Local<Context> context, Local<String> pattern, Flags flags, 0066 uint32_t backtrack_limit); 0067 0068 /** 0069 * Executes the current RegExp instance on the given subject string. 0070 * Equivalent to RegExp.prototype.exec as described in 0071 * 0072 * https://tc39.es/ecma262/#sec-regexp.prototype.exec 0073 * 0074 * On success, an Array containing the matched strings is returned. On 0075 * failure, returns Null. 0076 * 0077 * Note: modifies global context state, accessible e.g. through RegExp.input. 0078 */ 0079 V8_WARN_UNUSED_RESULT MaybeLocal<Object> Exec(Local<Context> context, 0080 Local<String> subject); 0081 0082 /** 0083 * Returns the value of the source property: a string representing 0084 * the regular expression. 0085 */ 0086 Local<String> GetSource() const; 0087 0088 /** 0089 * Returns the flags bit field. 0090 */ 0091 Flags GetFlags() const; 0092 0093 V8_INLINE static RegExp* Cast(Value* value) { 0094 #ifdef V8_ENABLE_CHECKS 0095 CheckCast(value); 0096 #endif 0097 return static_cast<RegExp*>(value); 0098 } 0099 0100 private: 0101 static void CheckCast(Value* obj); 0102 }; 0103 0104 } // namespace v8 0105 0106 #endif // INCLUDE_V8_REGEXP_H_
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
![]() ![]() |