Skip to content

Commit

Permalink
fix: add missing overloads to JsonObjectFormatter (philips-software#212)
Browse files Browse the repository at this point in the history
* fix(infra/syntax): add missing overloads to JsonFormatter

* chore(infra/syntax): reduce duplication and code smells

* chore: fix SonarCloud findings
  • Loading branch information
rjaegers committed Mar 1, 2023
1 parent 38992cf commit c4047c3
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
6 changes: 3 additions & 3 deletions infra/syntax/JsonFormatter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ namespace infra
{
namespace
{
static const char* charactersToEscape = "<>&'\"";
const char* charactersToEscape = "<>&'\"";

std::size_t EscapedCharacterSize(char c)
{
std::array<char, 7> shouldBeEscaped = { '"', '\\', '\b', '\f', '\n', '\r', '\t' };
if (std::any_of(shouldBeEscaped.begin(), shouldBeEscaped.end(), [c](char shouldBeEscaped)
{ return c == shouldBeEscaped; }))
if (std::any_of(shouldBeEscaped.begin(), shouldBeEscaped.end(), [c](char escape)
{ return c == escape; }))
return 2;
else
return 6;
Expand Down
4 changes: 1 addition & 3 deletions infra/syntax/XmlFormatter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ namespace infra
{
namespace
{
static const char* charactersToEscape = "<>&'\"";

void ReplaceEscapeCharacter(infra::TextOutputStream& stream, char c)
{
switch (c)
Expand All @@ -31,7 +29,7 @@ namespace infra

void InsertEscapedContent(infra::TextOutputStream& stream, infra::BoundedConstString content)
{
infra::InsertEscapedContent(stream, content, charactersToEscape, ReplaceEscapeCharacter);
infra::InsertEscapedContent(stream, content, "<>&'\"", ReplaceEscapeCharacter);
}
}

Expand Down

0 comments on commit c4047c3

Please sign in to comment.