1e509ee18Sopenharmony_ci/* 2e509ee18Sopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd. 3e509ee18Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4e509ee18Sopenharmony_ci * you may not use this file except in compliance with the License. 5e509ee18Sopenharmony_ci * You may obtain a copy of the License at 6e509ee18Sopenharmony_ci * 7e509ee18Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8e509ee18Sopenharmony_ci * 9e509ee18Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10e509ee18Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11e509ee18Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12e509ee18Sopenharmony_ci * See the License for the specific language governing permissions and 13e509ee18Sopenharmony_ci * limitations under the License. 14e509ee18Sopenharmony_ci */ 15e509ee18Sopenharmony_ci 16e509ee18Sopenharmony_ci#ifndef ARKCOMPILER_TOOLCHAIN_WEBSOCKET_STRING_UTILS_H 17e509ee18Sopenharmony_ci#define ARKCOMPILER_TOOLCHAIN_WEBSOCKET_STRING_UTILS_H 18e509ee18Sopenharmony_ci 19e509ee18Sopenharmony_ci#include <algorithm> 20e509ee18Sopenharmony_ci#include <cctype> 21e509ee18Sopenharmony_ci#include <string> 22e509ee18Sopenharmony_ci 23e509ee18Sopenharmony_cinamespace OHOS::ArkCompiler::Toolchain { 24e509ee18Sopenharmony_ci// all cctype function arguments must be representable as unsigned char 25e509ee18Sopenharmony_ciinline void TrimLeft(std::string &str) 26e509ee18Sopenharmony_ci{ 27e509ee18Sopenharmony_ci str.erase(str.begin(), std::find_if(str.begin(), str.end(), [](unsigned char ch) { return !std::isspace(ch); })); 28e509ee18Sopenharmony_ci} 29e509ee18Sopenharmony_ci 30e509ee18Sopenharmony_ciinline void TrimRight(std::string &str) 31e509ee18Sopenharmony_ci{ 32e509ee18Sopenharmony_ci str.erase(std::find_if(str.rbegin(), str.rend(), [](unsigned char ch) { return !std::isspace(ch); }).base(), 33e509ee18Sopenharmony_ci str.end()); 34e509ee18Sopenharmony_ci} 35e509ee18Sopenharmony_ci 36e509ee18Sopenharmony_ciinline void Trim(std::string &str) 37e509ee18Sopenharmony_ci{ 38e509ee18Sopenharmony_ci TrimLeft(str); 39e509ee18Sopenharmony_ci TrimRight(str); 40e509ee18Sopenharmony_ci} 41e509ee18Sopenharmony_ci 42e509ee18Sopenharmony_ciinline void ToLowerCase(std::string& str) 43e509ee18Sopenharmony_ci{ 44e509ee18Sopenharmony_ci std::transform(str.begin(), str.end(), str.begin(), [](unsigned char c) { return std::tolower(c); }); 45e509ee18Sopenharmony_ci} 46e509ee18Sopenharmony_ci} // namespace OHOS::ArkCompiler::Toolchain 47e509ee18Sopenharmony_ci 48e509ee18Sopenharmony_ci#endif // ARKCOMPILER_TOOLCHAIN_WEBSOCKET_STRING_UTILS_H 49e509ee18Sopenharmony_ci 50