diff options
Diffstat (limited to 'AK/PrintfImplementation.h')
-rw-r--r-- | AK/PrintfImplementation.h | 52 |
1 files changed, 26 insertions, 26 deletions
diff --git a/AK/PrintfImplementation.h b/AK/PrintfImplementation.h index 51b46b4b47..eb344c5eb8 100644 --- a/AK/PrintfImplementation.h +++ b/AK/PrintfImplementation.h @@ -14,7 +14,7 @@ #include <wchar.h> #ifdef __serenity__ -extern "C" size_t strlen(const char*); +extern "C" size_t strlen(char const*); #else # include <string.h> #endif @@ -24,8 +24,8 @@ namespace PrintfImplementation { template<typename PutChFunc, typename T, typename CharType> ALWAYS_INLINE int print_hex(PutChFunc putch, CharType*& bufptr, T number, bool upper_case, bool alternate_form, bool left_pad, bool zero_pad, u32 field_width, bool has_precision, u32 precision) { - constexpr const char* printf_hex_digits_lower = "0123456789abcdef"; - constexpr const char* printf_hex_digits_upper = "0123456789ABCDEF"; + constexpr char const* printf_hex_digits_lower = "0123456789abcdef"; + constexpr char const* printf_hex_digits_upper = "0123456789ABCDEF"; u32 digits = 0; for (T n = number; n > 0; n >>= 4) @@ -331,104 +331,104 @@ struct ModifierState { template<typename PutChFunc, typename ArgumentListRefT, template<typename T, typename U = ArgumentListRefT> typename NextArgument, typename CharType = char> struct PrintfImpl { - ALWAYS_INLINE PrintfImpl(PutChFunc& putch, CharType*& bufptr, const int& nwritten) + ALWAYS_INLINE PrintfImpl(PutChFunc& putch, CharType*& bufptr, int const& nwritten) : m_bufptr(bufptr) , m_nwritten(nwritten) , m_putch(putch) { } - ALWAYS_INLINE int format_s(const ModifierState& state, ArgumentListRefT ap) const + ALWAYS_INLINE int format_s(ModifierState const& 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); + wchar_t const* sp = NextArgument<wchar_t const*>()(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); + char const* sp = NextArgument<char const*>()(ap); if (!sp) sp = "(null)"; return print_string(m_putch, m_bufptr, sp, strlen(sp), state.left_pad, state.field_width, state.dot, state.precision, state.has_precision); } - ALWAYS_INLINE int format_d(const ModifierState& state, ArgumentListRefT ap) const + ALWAYS_INLINE int format_d(ModifierState const& state, ArgumentListRefT ap) const { if (state.long_qualifiers >= 2) return print_i64(m_putch, m_bufptr, NextArgument<i64>()(ap), state.always_sign, state.left_pad, state.zero_pad, state.field_width, state.has_precision, state.precision); return print_signed_number(m_putch, m_bufptr, NextArgument<int>()(ap), state.always_sign, state.left_pad, state.zero_pad, state.field_width, state.has_precision, state.precision); } - ALWAYS_INLINE int format_i(const ModifierState& state, ArgumentListRefT ap) const + ALWAYS_INLINE int format_i(ModifierState const& state, ArgumentListRefT ap) const { return format_d(state, ap); } - ALWAYS_INLINE int format_u(const ModifierState& state, ArgumentListRefT ap) const + ALWAYS_INLINE int format_u(ModifierState const& state, ArgumentListRefT ap) const { if (state.long_qualifiers >= 2) return print_decimal(m_putch, m_bufptr, NextArgument<u64>()(ap), false, false, state.left_pad, state.zero_pad, state.field_width, state.has_precision, state.precision); return print_decimal(m_putch, m_bufptr, NextArgument<u32>()(ap), false, false, state.left_pad, state.zero_pad, state.field_width, state.has_precision, state.precision); } - ALWAYS_INLINE int format_Q(const ModifierState& state, ArgumentListRefT ap) const + ALWAYS_INLINE int format_Q(ModifierState const& state, ArgumentListRefT ap) const { return print_decimal(m_putch, m_bufptr, NextArgument<u64>()(ap), false, false, state.left_pad, state.zero_pad, state.field_width, state.has_precision, state.precision); } - ALWAYS_INLINE int format_q(const ModifierState& state, ArgumentListRefT ap) const + ALWAYS_INLINE int format_q(ModifierState const& state, ArgumentListRefT ap) const { return print_hex(m_putch, m_bufptr, NextArgument<u64>()(ap), false, false, state.left_pad, state.zero_pad, 16, false, 1); } - ALWAYS_INLINE int format_g(const ModifierState& state, ArgumentListRefT ap) const + ALWAYS_INLINE int format_g(ModifierState const& state, ArgumentListRefT ap) const { return format_f(state, ap); } - ALWAYS_INLINE int format_f(const ModifierState& state, ArgumentListRefT ap) const + ALWAYS_INLINE int format_f(ModifierState const& state, ArgumentListRefT ap) const { return print_double(m_putch, m_bufptr, NextArgument<double>()(ap), state.always_sign, state.left_pad, state.zero_pad, state.field_width, state.precision); } - ALWAYS_INLINE int format_o(const ModifierState& state, ArgumentListRefT ap) const + ALWAYS_INLINE int format_o(ModifierState const& state, ArgumentListRefT ap) const { return print_octal_number(m_putch, m_bufptr, NextArgument<u32>()(ap), state.alternate_form, state.left_pad, state.zero_pad, state.field_width, state.has_precision, state.precision); } - ALWAYS_INLINE int format_x(const ModifierState& state, ArgumentListRefT ap) const + ALWAYS_INLINE int format_x(ModifierState const& state, ArgumentListRefT ap) const { if (state.long_qualifiers >= 2) return print_hex(m_putch, m_bufptr, NextArgument<u64>()(ap), false, state.alternate_form, state.left_pad, state.zero_pad, state.field_width, state.has_precision, state.precision); return print_hex(m_putch, m_bufptr, NextArgument<u32>()(ap), false, state.alternate_form, state.left_pad, state.zero_pad, state.field_width, state.has_precision, state.precision); } - ALWAYS_INLINE int format_X(const ModifierState& state, ArgumentListRefT ap) const + ALWAYS_INLINE int format_X(ModifierState const& state, ArgumentListRefT ap) const { if (state.long_qualifiers >= 2) return print_hex(m_putch, m_bufptr, NextArgument<u64>()(ap), true, state.alternate_form, state.left_pad, state.zero_pad, state.field_width, state.has_precision, state.precision); return print_hex(m_putch, m_bufptr, NextArgument<u32>()(ap), true, state.alternate_form, state.left_pad, state.zero_pad, state.field_width, state.has_precision, state.precision); } - ALWAYS_INLINE int format_n(const ModifierState&, ArgumentListRefT ap) const + ALWAYS_INLINE int format_n(ModifierState const&, ArgumentListRefT ap) const { *NextArgument<int*>()(ap) = m_nwritten; return 0; } - ALWAYS_INLINE int format_p(const ModifierState&, ArgumentListRefT ap) const + ALWAYS_INLINE int format_p(ModifierState const&, ArgumentListRefT ap) const { return print_hex(m_putch, m_bufptr, NextArgument<FlatPtr>()(ap), false, true, false, true, 8, false, 1); } - ALWAYS_INLINE int format_P(const ModifierState&, ArgumentListRefT ap) const + ALWAYS_INLINE int format_P(ModifierState const&, ArgumentListRefT ap) const { return print_hex(m_putch, m_bufptr, NextArgument<FlatPtr>()(ap), true, true, false, true, 8, false, 1); } - ALWAYS_INLINE int format_percent(const ModifierState&, ArgumentListRefT) const + ALWAYS_INLINE int format_percent(ModifierState const&, ArgumentListRefT) const { m_putch(m_bufptr, '%'); return 1; } - ALWAYS_INLINE int format_c(const ModifierState& state, ArgumentListRefT ap) const + ALWAYS_INLINE int format_c(ModifierState const& state, ArgumentListRefT ap) const { char c = NextArgument<int>()(ap); return print_string(m_putch, m_bufptr, &c, 1, state.left_pad, state.field_width, state.dot, state.precision, state.has_precision); } - ALWAYS_INLINE int format_unrecognized(CharType format_op, const CharType* fmt, const ModifierState&, ArgumentListRefT) const + ALWAYS_INLINE int format_unrecognized(CharType format_op, CharType const* fmt, ModifierState const&, ArgumentListRefT) const { dbgln("printf_internal: Unimplemented format specifier {} (fmt: {})", format_op, fmt); return 0; @@ -436,7 +436,7 @@ struct PrintfImpl { protected: CharType*& m_bufptr; - const int& m_nwritten; + int const& m_nwritten; PutChFunc& m_putch; }; @@ -454,14 +454,14 @@ struct VaArgNextArgument { break; template<typename PutChFunc, template<typename T, typename U, template<typename X, typename Y> typename V, typename C = char> typename Impl = PrintfImpl, typename ArgumentListT = va_list, template<typename T, typename V = decltype(declval<ArgumentListT&>())> typename NextArgument = VaArgNextArgument, typename CharType = char> -ALWAYS_INLINE int printf_internal(PutChFunc putch, IdentityType<CharType>* buffer, const CharType*& fmt, ArgumentListT ap) +ALWAYS_INLINE int printf_internal(PutChFunc putch, IdentityType<CharType>* buffer, CharType const*& fmt, ArgumentListT ap) { int ret = 0; CharType* bufptr = buffer; Impl<PutChFunc, ArgumentListT&, NextArgument, CharType> impl { putch, bufptr, ret }; - for (const CharType* p = fmt; *p; ++p) { + for (CharType const* p = fmt; *p; ++p) { ModifierState state; if (*p == '%' && *(p + 1)) { one_more: |