• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2021-2025 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef ETS_REGEXP_REGEXP_EXECUTOR_H
17 #define ETS_REGEXP_REGEXP_EXECUTOR_H
18 
19 #include "runtime/regexp/ecmascript/regexp_executor.h"
20 #include "plugins/ets/runtime/types/ets_string.h"
21 #include "utils/logger.h"
22 
23 namespace ark::ets {
24 
25 struct RegExpExecResult {
26     uint32_t endIndex = 0;
27     uint32_t index = 0;
28     PandaVector<std::pair<bool, PandaString>> captures;
29     PandaVector<std::pair<uint32_t, uint32_t>> indices;
30     std::map<PandaString, std::pair<int32_t, int32_t>> namedGroups;
31     bool isSuccess = false;
32     bool isWide = false;
33 };
34 
35 class RegExpExecutor : public ark::RegExpExecutor {
36 public:
37     RegExpExecResult GetResult(bool isSuccess, bool hasIndices) const;
38 
39 private:
40     std::pair<uint32_t, uint32_t> GetIndices(CaptureState *captureState) const;
41     void HandleCaptures(PandaVector<std::pair<bool, PandaString>> &captures,
42                         PandaVector<std::pair<uint32_t, uint32_t>> &indices, CaptureState *captureState) const;
43 };
44 }  // namespace ark::ets
45 
46 #endif  // ets_REGEXP_REGEXP_EXECUTOR_H
47