Skip to content

Add string escape function or escape functionality built into CAPTURE macro #2967

Open
@toughengineer

Description

@toughengineer

The problem

This:

const auto asciiControlsString =
  "null \0 tab \t carriage return \r line feed \n whatever this is \xf quotation mark \" chars"sv;
CAPTURE(asciiControlsString);

results in a message like this:

with message:
 line feed rolsString := "null  tab      carriage return
   whatever this is � quotation mark " chars"

Notice that because of carriage return \r character it garbles up the message:

 line feed rolsString := "null  tab      carriage return
 ^         ^
text       remnants of the variable name
after \r

Proposed solution

Having an escape() function to escape non-printable and some special characters (like carriage return) provided by Catch2 would be wonderful so people don't have to reinvent the wheel every time.

The result of code like this:

CAPTURE(escape(asciiControlsString));

can look like this:

with message:
  escape(asciiControlsString) := "null \0 tab \t carriage return \r
  line feed \n whatever this is � quotation mark " chars"

Alternatively CAPTURE() macro can incorporate this functionality, or Catch2 can provide additional macro with such functionality, e.g. CAPTURE_ESCAPED().

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions