OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef V8_OBJECTS_REGEXP_MATCH_INFO_H_ |
| 6 #define V8_OBJECTS_REGEXP_MATCH_INFO_H_ |
| 7 |
| 8 #include "src/base/compiler-specific.h" |
| 9 #include "src/objects.h" |
| 10 |
| 11 // Has to be the last include (doesn't have include guards): |
| 12 #include "src/objects/object-macros.h" |
| 13 |
| 14 namespace v8 { |
| 15 namespace internal { |
| 16 |
| 17 class Object; |
| 18 class String; |
| 19 |
| 20 // The property RegExpMatchInfo includes the matchIndices |
| 21 // array of the last successful regexp match (an array of start/end index |
| 22 // pairs for the match and all the captured substrings), the invariant is |
| 23 // that there are at least two capture indices. The array also contains |
| 24 // the subject string for the last successful match. |
| 25 // After creation the result must be treated as a FixedArray in all regards. |
| 26 class V8_EXPORT_PRIVATE RegExpMatchInfo : NON_EXPORTED_BASE(public FixedArray) { |
| 27 public: |
| 28 // Returns the number of captures, which is defined as the length of the |
| 29 // matchIndices objects of the last match. matchIndices contains two indices |
| 30 // for each capture (including the match itself), i.e. 2 * #captures + 2. |
| 31 inline int NumberOfCaptureRegisters(); |
| 32 inline void SetNumberOfCaptureRegisters(int value); |
| 33 |
| 34 // Returns the subject string of the last match. |
| 35 inline String* LastSubject(); |
| 36 inline void SetLastSubject(String* value); |
| 37 |
| 38 // Like LastSubject, but modifiable by the user. |
| 39 inline Object* LastInput(); |
| 40 inline void SetLastInput(Object* value); |
| 41 |
| 42 // Returns the i'th capture index, 0 <= i < NumberOfCaptures(). Capture(0) and |
| 43 // Capture(1) determine the start- and endpoint of the match itself. |
| 44 inline int Capture(int i); |
| 45 inline void SetCapture(int i, int value); |
| 46 |
| 47 // Reserves space for captures. |
| 48 static Handle<RegExpMatchInfo> ReserveCaptures( |
| 49 Handle<RegExpMatchInfo> match_info, int capture_count); |
| 50 |
| 51 DECLARE_CAST(RegExpMatchInfo) |
| 52 |
| 53 static const int kNumberOfCapturesIndex = 0; |
| 54 static const int kLastSubjectIndex = 1; |
| 55 static const int kLastInputIndex = 2; |
| 56 static const int kFirstCaptureIndex = 3; |
| 57 static const int kLastMatchOverhead = kFirstCaptureIndex; |
| 58 |
| 59 static const int kNumberOfCapturesOffset = FixedArray::kHeaderSize; |
| 60 static const int kLastSubjectOffset = kNumberOfCapturesOffset + kPointerSize; |
| 61 static const int kLastInputOffset = kLastSubjectOffset + kPointerSize; |
| 62 static const int kFirstCaptureOffset = kLastInputOffset + kPointerSize; |
| 63 |
| 64 // Every match info is guaranteed to have enough space to store two captures. |
| 65 static const int kInitialCaptureIndices = 2; |
| 66 |
| 67 private: |
| 68 DISALLOW_IMPLICIT_CONSTRUCTORS(RegExpMatchInfo); |
| 69 }; |
| 70 |
| 71 } // namespace internal |
| 72 } // namespace v8 |
| 73 |
| 74 #include "src/objects/object-macros-undef.h" |
| 75 |
| 76 #endif // V8_OBJECTS_REGEXP_MATCH_INFO_H_ |
OLD | NEW |