Skip to content

Commit 66fc621

Browse files
committed
config: Add UNITY_IS_PRINTABLE_CHAR function macro
This allows other charsets, such as UTF-8, to be printed properly without escaping.
1 parent 3a6eb6d commit 66fc621

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

‎examples/unity_config.h‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,4 +250,12 @@
250250
*/
251251
/* #define UNITY_INCLUDE_EXEC_TIME */
252252

253+
/* Define this macro to redefine what the UnityPrintChar() function considers
254+
* a printable character.
255+
*
256+
* Example, for printing UTF-8:
257+
* #define UNITY_IS_PRINTABLE_CHAR(c) ((128 <= (c)) && ((c) <= 255))
258+
*/
259+
/* #define UNITY_IS_PRINTABLE_CHAR(c) ((32 <= (c)) && ((c) <= 126)) */
260+
253261
#endif /* UNITY_CONFIG_H */

‎src/unity.c‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
#include "unity.h"
99

10+
#include <stdbool.h>
11+
1012
#ifndef UNITY_PROGMEM
1113
#define UNITY_PROGMEM
1214
#endif
@@ -88,8 +90,14 @@ static const char UNITY_PROGMEM UnityStrDetail2Name[] = " " UNITY_DET
8890
/* Local helper function to print characters. */
8991
static void UnityPrintChar(const char* pch)
9092
{
93+
#ifdef UNITY_IS_PRINTABLE_CHAR
94+
const bool isPrintable = UNITY_IS_PRINTABLE_CHAR(*pch);
95+
#else
96+
const bool isPrintable = ((32 <= *pch) && (*pch <= 126));
97+
#endif // UNITY_IS_PRINTABLE_CHAR
98+
9199
/* printable characters plus CR & LF are printed */
92-
if ((*pch <= 126) && (*pch >= 32))
100+
if (isPrintable)
93101
{
94102
UNITY_OUTPUT_CHAR(*pch);
95103
}

0 commit comments

Comments
 (0)