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
16#ifndef ARKCOMPILER_TOOLCHAIN_WEBSOCKET_STRING_UTILS_H
17#define ARKCOMPILER_TOOLCHAIN_WEBSOCKET_STRING_UTILS_H
18
19#include <algorithm>
20#include <cctype>
21#include <string>
22
23namespace OHOS::ArkCompiler::Toolchain {
24// all cctype function arguments must be representable as unsigned char
25inline void TrimLeft(std::string &str)
26{
27    str.erase(str.begin(), std::find_if(str.begin(), str.end(), [](unsigned char ch) { return !std::isspace(ch); }));
28}
29
30inline void TrimRight(std::string &str)
31{
32    str.erase(std::find_if(str.rbegin(), str.rend(), [](unsigned char ch) { return !std::isspace(ch); }).base(),
33              str.end());
34}
35
36inline void Trim(std::string &str)
37{
38    TrimLeft(str);
39    TrimRight(str);
40}
41
42inline void ToLowerCase(std::string& str)
43{
44    std::transform(str.begin(), str.end(), str.begin(), [](unsigned char c) { return std::tolower(c); });
45}
46} // namespace OHOS::ArkCompiler::Toolchain
47
48#endif // ARKCOMPILER_TOOLCHAIN_WEBSOCKET_STRING_UTILS_H
49
50