summaryrefslogtreecommitdiffstats
path: root/thirdparty/icu4c/common/unicode/char16ptr.h
diff options
context:
space:
mode:
Diffstat (limited to 'thirdparty/icu4c/common/unicode/char16ptr.h')
-rw-r--r--thirdparty/icu4c/common/unicode/char16ptr.h71
1 files changed, 71 insertions, 0 deletions
diff --git a/thirdparty/icu4c/common/unicode/char16ptr.h b/thirdparty/icu4c/common/unicode/char16ptr.h
index de8182c7ad..daf35cd43b 100644
--- a/thirdparty/icu4c/common/unicode/char16ptr.h
+++ b/thirdparty/icu4c/common/unicode/char16ptr.h
@@ -12,6 +12,7 @@
#if U_SHOW_CPLUSPLUS_API
#include <cstddef>
+#include <string_view>
/**
* \file
@@ -306,6 +307,76 @@ inline OldUChar *toOldUCharPtr(char16_t *p) {
return reinterpret_cast<OldUChar *>(p);
}
+#ifndef U_FORCE_HIDE_INTERNAL_API
+/**
+ * Is T convertible to a std::u16string_view or some other 16-bit string view?
+ * @internal
+ */
+template<typename T>
+constexpr bool ConvertibleToU16StringView =
+ std::is_convertible_v<T, std::u16string_view>
+#if !U_CHAR16_IS_TYPEDEF && (!defined(_LIBCPP_VERSION) || _LIBCPP_VERSION < 180000)
+ || std::is_convertible_v<T, std::basic_string_view<uint16_t>>
+#endif
+#if U_SIZEOF_WCHAR_T==2
+ || std::is_convertible_v<T, std::wstring_view>
+#endif
+ ;
+
+namespace internal {
+/**
+ * Pass-through overload.
+ * @internal
+ */
+inline std::u16string_view toU16StringView(std::u16string_view sv) { return sv; }
+
+#if !U_CHAR16_IS_TYPEDEF && (!defined(_LIBCPP_VERSION) || _LIBCPP_VERSION < 180000)
+/**
+ * Basically undefined behavior but sometimes necessary conversion
+ * from std::basic_string_view<uint16_t> to std::u16string_view.
+ * @internal
+ */
+inline std::u16string_view toU16StringView(std::basic_string_view<uint16_t> sv) {
+ return { ConstChar16Ptr(sv.data()), sv.length() };
+}
+#endif
+
+#if U_SIZEOF_WCHAR_T==2
+/**
+ * Basically undefined behavior but sometimes necessary conversion
+ * from std::wstring_view to std::u16string_view.
+ * @internal
+ */
+inline std::u16string_view toU16StringView(std::wstring_view sv) {
+ return { ConstChar16Ptr(sv.data()), sv.length() };
+}
+#endif
+
+/**
+ * Pass-through overload.
+ * @internal
+ */
+template <typename T,
+ typename = typename std::enable_if_t<!std::is_pointer_v<std::remove_reference_t<T>>>>
+inline std::u16string_view toU16StringViewNullable(const T& text) {
+ return toU16StringView(text);
+}
+
+/**
+ * In case of nullptr, return an empty view.
+ * @internal
+ */
+template <typename T,
+ typename = typename std::enable_if_t<std::is_pointer_v<std::remove_reference_t<T>>>,
+ typename = void>
+inline std::u16string_view toU16StringViewNullable(const T& text) {
+ if (text == nullptr) return {}; // For backward compatibility.
+ return toU16StringView(text);
+}
+
+} // internal
+#endif // U_FORCE_HIDE_INTERNAL_API
+
U_NAMESPACE_END
#endif /* U_SHOW_CPLUSPLUS_API */