summaryrefslogtreecommitdiff
path: root/AK
diff options
context:
space:
mode:
authorsafarp <safar.pavel@gmail.com>2022-03-20 09:53:52 +0100
committerAli Mohammad Pur <Ali.mpfard@gmail.com>2022-03-30 11:30:43 +0430
commit704e1d13f46f33302f80698018e86554a5006d14 (patch)
tree70a7a11eb578703e85fc3d7c76f7aa00690426dc /AK
parent824cf570d30888a4309274d467c7c22dde884a69 (diff)
downloadserenity-704e1d13f46f33302f80698018e86554a5006d14.zip
AK: Allow printing wide characters using %ls modifier
Diffstat (limited to 'AK')
-rw-r--r--AK/PrintfImplementation.h16
1 files changed, 14 insertions, 2 deletions
diff --git a/AK/PrintfImplementation.h b/AK/PrintfImplementation.h
index 44cbc62ba3..51b46b4b47 100644
--- a/AK/PrintfImplementation.h
+++ b/AK/PrintfImplementation.h
@@ -11,6 +11,7 @@
#include <AK/Types.h>
#include <math.h>
#include <stdarg.h>
+#include <wchar.h>
#ifdef __serenity__
extern "C" size_t strlen(const char*);
@@ -277,8 +278,8 @@ ALWAYS_INLINE int print_octal_number(PutChFunc putch, CharType*& bufptr, u64 num
return field_width;
}
-template<typename PutChFunc, typename CharType>
-ALWAYS_INLINE int print_string(PutChFunc putch, CharType*& bufptr, const char* str, size_t len, bool left_pad, size_t field_width, bool dot, size_t precision, bool has_fraction)
+template<typename PutChFunc, typename T, typename CharType>
+ALWAYS_INLINE int print_string(PutChFunc putch, CharType*& bufptr, T str, size_t len, bool left_pad, size_t field_width, bool dot, size_t precision, bool has_fraction)
{
if (has_fraction)
len = min(len, precision);
@@ -339,6 +340,17 @@ struct PrintfImpl {
ALWAYS_INLINE int format_s(const ModifierState& state, ArgumentListRefT ap) const
{
+ // FIXME: Narrow characters should be converted to wide characters on the fly and vice versa.
+ // https://pubs.opengroup.org/onlinepubs/9699919799/functions/printf.html
+ // https://pubs.opengroup.org/onlinepubs/9699919799/functions/wprintf.html
+#ifndef KERNEL
+ if (state.long_qualifiers) {
+ const wchar_t* sp = NextArgument<const wchar_t*>()(ap);
+ if (!sp)
+ sp = L"(null)";
+ return print_string(m_putch, m_bufptr, sp, wcslen(sp), state.left_pad, state.field_width, state.dot, state.precision, state.has_precision);
+ }
+#endif
const char* sp = NextArgument<const char*>()(ap);
if (!sp)
sp = "(null)";