[libc-commits] [libc] [llvm] [libc] Change ctype to be encoding independent (PR #110574)

Michael Jones via libc-commits libc-commits at lists.llvm.org
Tue Dec 3 11:24:29 PST 2024


================
@@ -214,9 +215,9 @@ template <typename T, typename Fmt = radix::Dec> class IntegerToString {
     using UNSIGNED_T = make_integral_or_big_int_unsigned_t<T>;
 
     LIBC_INLINE static char digit_char(uint8_t digit) {
-      if (digit < 10)
-        return '0' + static_cast<char>(digit);
-      return (Fmt::IS_UPPERCASE ? 'A' : 'a') + static_cast<char>(digit - 10);
+      const char result = static_cast<char>(internal::int_to_b36_char(digit));
+      return static_cast<char>(Fmt::IS_UPPERCASE ? internal::toupper(result)
----------------
michaelrj-google wrote:

`int_to_b36_char` returns an int to match with the other ctype functions. Without the cast you get a warning for loss of precision.

https://github.com/llvm/llvm-project/pull/110574


More information about the libc-commits mailing list