File indexing completed on 2025-08-28 08:27:10
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018 #pragma once
0019
0020 #include <cassert>
0021 #include <optional>
0022 #include <string>
0023 #include <string_view>
0024 #include <type_traits>
0025 #include <utility>
0026 #include <vector>
0027
0028 #if __has_include(<charconv>)
0029 # include <charconv>
0030 #endif
0031
0032 #include "arrow/result.h"
0033 #include "arrow/util/visibility.h"
0034
0035 namespace arrow {
0036
0037 class Status;
0038
0039 ARROW_EXPORT std::string HexEncode(const uint8_t* data, size_t length);
0040
0041 ARROW_EXPORT std::string Escape(const char* data, size_t length);
0042
0043 ARROW_EXPORT std::string HexEncode(const char* data, size_t length);
0044
0045 ARROW_EXPORT std::string HexEncode(std::string_view str);
0046
0047 ARROW_EXPORT std::string Escape(std::string_view str);
0048
0049 ARROW_EXPORT Status ParseHexValue(const char* hex_pair, uint8_t* out);
0050
0051 ARROW_EXPORT Status ParseHexValues(std::string_view hex_string, uint8_t* out);
0052
0053 namespace internal {
0054
0055
0056 inline bool StartsWith(std::string_view s, std::string_view prefix) {
0057 return s.length() >= prefix.length() &&
0058 (s.empty() || s.substr(0, prefix.length()) == prefix);
0059 }
0060
0061
0062 inline bool EndsWith(std::string_view s, std::string_view suffix) {
0063 return s.length() >= suffix.length() &&
0064 (s.empty() || s.substr(s.length() - suffix.length()) == suffix);
0065 }
0066
0067
0068 ARROW_EXPORT
0069 std::vector<std::string_view> SplitString(std::string_view v, char delim,
0070 int64_t limit = 0);
0071
0072
0073 ARROW_EXPORT
0074 std::string JoinStrings(const std::vector<std::string_view>& strings,
0075 std::string_view delimiter);
0076
0077
0078 ARROW_EXPORT
0079 std::string JoinStrings(const std::vector<std::string>& strings,
0080 std::string_view delimiter);
0081
0082
0083 ARROW_EXPORT
0084 std::string TrimString(std::string value);
0085
0086 ARROW_EXPORT
0087 bool AsciiEqualsCaseInsensitive(std::string_view left, std::string_view right);
0088
0089 ARROW_EXPORT
0090 std::string AsciiToLower(std::string_view value);
0091
0092 ARROW_EXPORT
0093 std::string AsciiToUpper(std::string_view value);
0094
0095
0096
0097 ARROW_EXPORT
0098 std::optional<std::string> Replace(std::string_view s, std::string_view token,
0099 std::string_view replacement);
0100
0101
0102
0103
0104
0105
0106 ARROW_EXPORT
0107 arrow::Result<bool> ParseBoolean(std::string_view value);
0108
0109 #if __has_include(<charconv>)
0110
0111 namespace detail {
0112 template <typename T, typename = void>
0113 struct can_to_chars : public std::false_type {};
0114
0115 template <typename T>
0116 struct can_to_chars<
0117 T, std::void_t<decltype(std::to_chars(std::declval<char*>(), std::declval<char*>(),
0118 std::declval<std::remove_reference_t<T>>()))>>
0119 : public std::true_type {};
0120 }
0121
0122
0123
0124
0125
0126 template <typename T>
0127 inline constexpr bool have_to_chars = detail::can_to_chars<T>::value;
0128
0129
0130
0131
0132
0133
0134
0135
0136 template <typename T, typename... Args>
0137 std::string ToChars(T value, Args&&... args) {
0138 if constexpr (!have_to_chars<T>) {
0139
0140
0141 return std::to_string(value);
0142 } else {
0143
0144
0145
0146 std::string out(15, 0);
0147 auto res = std::to_chars(&out.front(), &out.back(), value, args...);
0148 while (res.ec != std::errc{}) {
0149 assert(res.ec == std::errc::value_too_large);
0150 out.resize(out.capacity() * 2);
0151 res = std::to_chars(&out.front(), &out.back(), value, args...);
0152 }
0153 const auto length = res.ptr - out.data();
0154 assert(length <= static_cast<int64_t>(out.length()));
0155 out.resize(length);
0156 return out;
0157 }
0158 }
0159
0160 #else
0161
0162 template <typename T>
0163 inline constexpr bool have_to_chars = false;
0164
0165 template <typename T, typename... Args>
0166 std::string ToChars(T value, Args&&... args) {
0167 return std::to_string(value);
0168 }
0169
0170 #endif
0171
0172 }
0173 }