From b511091728404e1637c0333db6efabf6e0d75810 Mon Sep 17 00:00:00 2001 From: Baptiste Wicht Date: Mon, 26 Sep 2016 13:09:24 +0200 Subject: [PATCH] Add support for boolean printing --- printf/include/printf_def.hpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/printf/include/printf_def.hpp b/printf/include/printf_def.hpp index 179dc6ff..e8b5b0c0 100644 --- a/printf/include/printf_def.hpp +++ b/printf/include/printf_def.hpp @@ -165,6 +165,16 @@ std::string vsprintf(const std::string& format, va_list va){ s += "B"; } } + // Boolean + else if(ch == 'b'){ + bool value= va_arg(va, int); + + if(value){ + s += "true"; + } else { + s += "false"; + } + } //String else if(ch == 's'){ const char* arg = va_arg(va, const char*); @@ -376,6 +386,16 @@ void vsprintf_raw(char* out_buffer, size_t /*n*/, const char* format, va_list va out_i += str_cat(out_buffer + out_i, "B"); } } + // Boolean + else if(ch == 'b'){ + bool value= va_arg(va, int); + + if(value){ + out_i += str_cat(out_buffer + out_i, "true"); + } else { + out_i += str_cat(out_buffer + out_i, "false"); + } + } //String else if(ch == 's'){ const char* arg = va_arg(va, const char*);