1 /*
2 * Copyright (C) 2022 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 #include "operator_matching_rule.h"
16
17 using namespace std;
18 namespace OHOS {
19 namespace Telephony {
IccidRegexMatch(const std::string & iccidFromSim,const std::string & iccidRegex)20 bool OperatorMatchingRule::IccidRegexMatch(const std::string &iccidFromSim, const std::string &iccidRegex)
21 {
22 if (iccidFromSim.empty()) {
23 return false;
24 }
25 return std::regex_match(iccidFromSim, std::regex(iccidRegex));
26 }
27
ImsiRegexMatch(const std::string & imsiFromSim,const std::string & imsiRegex)28 bool OperatorMatchingRule::ImsiRegexMatch(const std::string &imsiFromSim, const std::string &imsiRegex)
29 {
30 if (imsiFromSim.empty()) {
31 return false;
32 }
33 return std::regex_match(imsiFromSim, std::regex(imsiRegex));
34 }
35
SpnRegexMatch(const std::string & spnFromSim,const std::string & spnRegex)36 bool OperatorMatchingRule::SpnRegexMatch(const std::string &spnFromSim, const std::string &spnRegex)
37 {
38 if (spnFromSim.empty()) {
39 return false;
40 }
41 return std::regex_match(spnFromSim, std::regex(spnRegex));
42 }
43
PrefixMatch(const std::string & valueFromSim,const std::string & valuePrefix)44 bool OperatorMatchingRule::PrefixMatch(const std::string &valueFromSim, const std::string &valuePrefix)
45 {
46 if (valueFromSim.empty()) {
47 return false;
48 }
49 return !(valueFromSim.compare(PREFIX_INDEX, valuePrefix.size(), valuePrefix));
50 }
51 } // namespace Telephony
52 } // namespace OHOS
53