1 /*
2 * Copyright (c) 2023 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 #include "unittest_utils.h"
17 #include <regex>
18
19 namespace OHOS {
20 namespace MediaAVCodec {
DecArgv(int & index,int & argc,char ** argv)21 void DecArgv(int &index, int &argc, char **argv)
22 {
23 if (argc <= 0 || index >= argc) {
24 return;
25 }
26 for (int i = index; i < argc - 1; ++i) {
27 (argv)[i] = (argv)[i + 1];
28 }
29 --argc;
30 --index;
31 }
32
GetNum(const char * str,const std::string key)33 int32_t GetNum(const char *str, const std::string key)
34 {
35 int32_t resultInt = 0;
36 std::string keyVal = std::string(str);
37 std::regex regexKey(key + "=(\\d+)");
38 std::regex regexDigital("\\d+");
39 std::smatch matchVals;
40 if (std::regex_search(keyVal, matchVals, regexKey)) {
41 std::string startStr = matchVals[1].str();
42 resultInt = std::regex_match(startStr, regexDigital) ? std::stoi(startStr) : 0;
43 }
44 return resultInt;
45 }
46 } // namespace MediaAVCodec
47 } // namespace OHOS