From de7e35ec6686e23526893d762ebd2acabbd4532d Mon Sep 17 00:00:00 2001 From: Tomek Rozen Date: Thu, 12 Sep 2019 16:47:35 +0200 Subject: [PATCH] [C++] Non-printable CHAR printed as int --- .../uk/co/real_logic/sbe/generation/cpp/CppGenerator.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/cpp/CppGenerator.java b/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/cpp/CppGenerator.java index 506b5d8ea3..595f46c380 100755 --- a/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/cpp/CppGenerator.java +++ b/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/cpp/CppGenerator.java @@ -2532,7 +2532,12 @@ private CharSequence writeTokenDisplay( // have to duplicate because of checkstyle :/ if (typeToken.encoding().primitiveType() == PrimitiveType.CHAR) { - sb.append(indent + "builder << '\"' << (char)" + fieldName + "() << '\"';\n"); + sb.append( + indent + "if (std::isprint(" + fieldName + "())) {\n" + + indent + " builder << '\"' << (char)" + fieldName + "() << '\"';\n" + + indent + "} else {\n" + + indent + " builder << (int)" + fieldName + "();\n" + + indent + "}\n"); } else {