/src/trafficserver/include/tsutil/Convert.h
Line | Count | Source |
1 | | /** @file |
2 | | |
3 | | Collection of utility functions for converting between different chars. |
4 | | |
5 | | @par License |
6 | | |
7 | | Licensed to the Apache Software Foundation (ASF) under one |
8 | | or more contributor license agreements. See the NOTICE file |
9 | | distributed with this work for additional information |
10 | | regarding copyright ownership. The ASF licenses this file |
11 | | to you under the Apache License, Version 2.0 (the |
12 | | "License"); you may not use this file except in compliance |
13 | | with the License. You may obtain a copy of the License at |
14 | | |
15 | | http://www.apache.org/licenses/LICENSE-2.0 |
16 | | |
17 | | Unless required by applicable law or agreed to in writing, software |
18 | | distributed under the License is distributed on an "AS IS" BASIS, |
19 | | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
20 | | See the License for the specific language governing permissions and |
21 | | limitations under the License. |
22 | | */ |
23 | | |
24 | | #pragma once |
25 | | |
26 | | #include "swoc/MemSpan.h" |
27 | | |
28 | | #include <algorithm> |
29 | | #include <cctype> |
30 | | #include <string_view> |
31 | | |
32 | | namespace ts |
33 | | { |
34 | | /** Copy @a src to @a dst, transforming to lower case. |
35 | | * |
36 | | * @param src Input string. |
37 | | * @param dst Output buffer. |
38 | | */ |
39 | | inline void |
40 | | transform_lower(std::string_view src, swoc::MemSpan<char> dst) |
41 | 0 | { |
42 | 0 | if (src.size() > dst.size() - 1) { // clip @a src, reserving space for the terminal nul. |
43 | 0 | src = std::string_view{src.data(), dst.size() - 1}; |
44 | 0 | } |
45 | 0 | auto final = |
46 | 0 | std::transform(src.begin(), src.end(), dst.data(), [](unsigned char c) -> char { return static_cast<char>(std::tolower(c)); }); |
47 | 0 | *final++ = '\0'; |
48 | 0 | } |
49 | | } // namespace ts |