config: Add UNITY_IS_PRINTABLE_CHAR function macro

This allows other charsets, such as UTF-8, to be printed properly
without escaping.
This commit is contained in:
Shawn Silverman
2026-08-18 18:55:46 -07:00
parent 3a6eb6dfd7
commit 66fc62189c
2 changed files with 17 additions and 1 deletions
+8
View File
@@ -250,4 +250,12 @@
*/ */
/* #define UNITY_INCLUDE_EXEC_TIME */ /* #define UNITY_INCLUDE_EXEC_TIME */
/* Define this macro to redefine what the UnityPrintChar() function considers
* a printable character.
*
* Example, for printing UTF-8:
* #define UNITY_IS_PRINTABLE_CHAR(c) ((128 <= (c)) && ((c) <= 255))
*/
/* #define UNITY_IS_PRINTABLE_CHAR(c) ((32 <= (c)) && ((c) <= 126)) */
#endif /* UNITY_CONFIG_H */ #endif /* UNITY_CONFIG_H */
+9 -1
View File
@@ -7,6 +7,8 @@
#include "unity.h" #include "unity.h"
#include <stdbool.h>
#ifndef UNITY_PROGMEM #ifndef UNITY_PROGMEM
#define UNITY_PROGMEM #define UNITY_PROGMEM
#endif #endif
@@ -88,8 +90,14 @@ static const char UNITY_PROGMEM UnityStrDetail2Name[] = " " UNITY_DET
/* Local helper function to print characters. */ /* Local helper function to print characters. */
static void UnityPrintChar(const char* pch) static void UnityPrintChar(const char* pch)
{ {
#ifdef UNITY_IS_PRINTABLE_CHAR
const bool isPrintable = UNITY_IS_PRINTABLE_CHAR(*pch);
#else
const bool isPrintable = ((32 <= *pch) && (*pch <= 126));
#endif // UNITY_IS_PRINTABLE_CHAR
/* printable characters plus CR & LF are printed */ /* printable characters plus CR & LF are printed */
if ((*pch <= 126) && (*pch >= 32)) if (isPrintable)
{ {
UNITY_OUTPUT_CHAR(*pch); UNITY_OUTPUT_CHAR(*pch);
} }