1 /*
2 * Copyright (C) 2024 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 "string_helper.h"
17
18 #include <algorithm>
19
20 namespace OHOS {
21 namespace Media {
22 namespace Effect {
EndsWith(const std::string & input,const std::string & suffix)23 bool StringHelp::EndsWith(const std::string &input, const std::string &suffix)
24 {
25 if (input.length() < suffix.length()) {
26 return false;
27 }
28 return input.compare(input.length() - suffix.length(), suffix.length(), suffix) == 0;
29 }
30
EndsWithIgnoreCase(const std::string & input,const std::string & suffix)31 bool StringHelp::EndsWithIgnoreCase(const std::string &input, const std::string &suffix)
32 {
33 if (input.length() < suffix.length()) {
34 return false;
35 }
36
37 std::string inputEnd = input.substr(input.length() - suffix.length(), suffix.length());
38 std::transform(inputEnd.begin(), inputEnd.end(), inputEnd.begin(), ::tolower);
39
40 std::string suffixLower = suffix;
41 std::transform(suffixLower.begin(), suffixLower.end(), suffixLower.begin(), ::tolower);
42
43 return inputEnd.compare(suffixLower) == 0;
44 }
45 } // namespace Effect
46 } // namespace Media
47 } // namespace OHOS