[llvm] [Support] Take ArrayRef in convertWideToUTF8 (PR #200687)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 1 03:20:17 PDT 2026
https://github.com/Nerixyz updated https://github.com/llvm/llvm-project/pull/200687
>From 933f19613f861d8a1bb006b56411fa7dc32b6345 Mon Sep 17 00:00:00 2001
From: Nerixyz <nerixdev at outlook.de>
Date: Sun, 31 May 2026 21:56:12 +0200
Subject: [PATCH] [Support] Take ArrayRef in convertWideToUTF8
---
llvm/include/llvm/Support/ConvertUTF.h | 15 ++++++++++-----
llvm/lib/Support/ConvertUTFWrapper.cpp | 6 +++++-
2 files changed, 15 insertions(+), 6 deletions(-)
diff --git a/llvm/include/llvm/Support/ConvertUTF.h b/llvm/include/llvm/Support/ConvertUTF.h
index ddf7057bff59d..140395f7abd17 100644
--- a/llvm/include/llvm/Support/ConvertUTF.h
+++ b/llvm/include/llvm/Support/ConvertUTF.h
@@ -246,11 +246,16 @@ LLVM_ABI bool ConvertUTF8toWide(llvm::StringRef Source, std::wstring &Result);
LLVM_ABI bool ConvertUTF8toWide(const char *Source, std::wstring &Result);
/**
-* Converts a std::wstring to a UTF-8 encoded std::string.
-* \return true on success.
-*/
-LLVM_ABI bool convertWideToUTF8(const std::wstring &Source,
- std::string &Result);
+ * Converts an ArrayRef<wchar_t> to a UTF-8 encoded std::string.
+ * \return true on success.
+ */
+LLVM_ABI bool convertWideToUTF8(ArrayRef<wchar_t> Source, std::string &Result);
+
+/**
+ * Converts a wide C-string to a UTF-8 encoded std::string.
+ * \return true on success.
+ */
+LLVM_ABI bool convertWideToUTF8(const wchar_t *Source, std::string &Result);
/**
* Convert an Unicode code point to UTF8 sequence.
diff --git a/llvm/lib/Support/ConvertUTFWrapper.cpp b/llvm/lib/Support/ConvertUTFWrapper.cpp
index 21dcf779338f7..d1a854a577933 100644
--- a/llvm/lib/Support/ConvertUTFWrapper.cpp
+++ b/llvm/lib/Support/ConvertUTFWrapper.cpp
@@ -268,7 +268,7 @@ bool ConvertUTF8toWide(const char *Source, std::wstring &Result) {
return ConvertUTF8toWide(llvm::StringRef(Source), Result);
}
-bool convertWideToUTF8(const std::wstring &Source, std::string &Result) {
+bool convertWideToUTF8(ArrayRef<wchar_t> Source, std::string &Result) {
if (sizeof(wchar_t) == 1) {
const UTF8 *Start = reinterpret_cast<const UTF8 *>(Source.data());
const UTF8 *End =
@@ -304,6 +304,10 @@ bool convertWideToUTF8(const std::wstring &Source, std::string &Result) {
}
}
+bool convertWideToUTF8(const wchar_t *Source, std::string &Result) {
+ return convertWideToUTF8(std::wstring_view(Source), Result);
+}
+
bool IsSingleCodeUnitUTF8Codepoint(unsigned V) { return V <= 0x7F; }
bool IsSingleCodeUnitUTF16Codepoint(unsigned V) {
More information about the llvm-commits
mailing list