[libc-commits] [libc] [libc] Wchar Stringconverter (PR #146388)
Uzair Nawaz via libc-commits
libc-commits at lists.llvm.org
Tue Jul 8 14:50:16 PDT 2025
================
@@ -0,0 +1,113 @@
+//===-- Definition of a class for mbstate_t and conversion -----*-- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_STRING_CONVERTER_H
+#define LLVM_LIBC_SRC___SUPPORT_STRING_CONVERTER_H
+
+#include "hdr/types/char32_t.h"
+#include "hdr/types/char8_t.h"
+#include "hdr/types/size_t.h"
+#include "src/__support/common.h"
+#include "src/__support/error_or.h"
+#include "src/__support/wchar/character_converter.h"
+#include "src/__support/wchar/mbstate.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace internal {
+
+template <typename T> class StringConverter {
+private:
+ CharacterConverter cr;
+ const T *src;
+ size_t src_len;
+ size_t src_idx;
+ size_t num_pushed;
----------------
uzairnawaz wrote:
We do still need to store num_pushed as the call to popUTFx() that actually pushes the full character might not be the same call that updates the src_idx
Ex for a 4 byte character:
```
str_conv.pop_utf8() // pushes the full utf-32 character
str_conv.pop_utf8()
str_conv.pop_utf8()
str_conv.pop_utf8() // updates src index
```
https://github.com/llvm/llvm-project/pull/146388
More information about the libc-commits
mailing list