bneradt commented on code in PR #11392: URL: https://github.com/apache/trafficserver/pull/11392#discussion_r1619569336
########## include/tsutil/StringConvert.h: ########## @@ -0,0 +1,71 @@ +/* + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +#pragma once + +#include <charconv> +#include <stdexcept> +#include <string> +#include <system_error> + +namespace ts +{ + +inline std::string +hex(const std::string_view input) Review Comment: I was initially confused, assuming `hex` converted from base 10 or some such to hex. Maybe comment with something like: ```cpp /** Convert values into their hex ascii equivalents. * @note This is a reimplementation of boost's hex. * @return The series of hex values corresponding to @a input */ ``` ########## include/tsutil/StringConvert.h: ########## @@ -0,0 +1,71 @@ +/* + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +#pragma once + +#include <charconv> +#include <stdexcept> +#include <string> +#include <system_error> + +namespace ts +{ + +inline std::string +hex(const std::string_view input) +{ + std::string result; + + result.resize(input.size() * 2); + + char *p = result.data(); + for (auto x : input) { + if (auto [ptr, err] = std::to_chars(p, result.data() + result.size(), x, 16); err == std::errc()) { + p = ptr; + } else { + throw std::runtime_error(std::make_error_code(err).message().c_str()); + } + } + + return result; +} + +inline std::string +unhex(const std::string_view input) Review Comment: Maybe doc with: ```cpp /** The inverse function of hex above. * @note This is a reimplementation of boost's unhex. */ -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: github-unsubscr...@trafficserver.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org