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