Function: visible

- Added helper function to render control characters visible.  This may be
  replaced by JSON::encode.
This commit is contained in:
Paul Beckingham 2013-08-30 10:51:43 -07:00
parent ac811c6930
commit 7e5b43bb9d
2 changed files with 23 additions and 0 deletions

View file

@ -682,6 +682,28 @@ bool isPunctuation (char c)
return ispunct (c);
}
////////////////////////////////////////////////////////////////////////////////
std::string visible (char input)
{
// Sanitize 'message'.
char stringized[2] = {0};
stringized[0] = input;
std::string sanitized = stringized;
switch (input)
{
case ' ': sanitized = "\\s"; break;
case '\r': sanitized = "\\r"; break;
case '\n': sanitized = "\\n"; break;
case '\f': sanitized = "\\f"; break;
case '\t': sanitized = "\\t"; break;
case '\v': sanitized = "\\v"; break;
default: sanitized = input; break;
}
return sanitized;
}
////////////////////////////////////////////////////////////////////////////////
bool compare (
const std::string& left,

View file

@ -63,6 +63,7 @@ bool isWordStart (const std::string&, std::string::size_type);
bool isWordEnd (const std::string&, std::string::size_type);
bool isTokenEnd (const std::string&, std::string::size_type);
bool isPunctuation (char);
std::string visible (char);
bool compare (const std::string&, const std::string&, bool sensitive = true);
bool closeEnough (const std::string&, const std::string&, unsigned int minLength = 0);
std::string::size_type find (const std::string&, const std::string&, bool sensitive = true);