{
string out;
- for (string::const_iterator it = in.begin(); it != in.end(); ++it)
+ for (const char c : in)
{
- if (*it == '\\')
+ if (c == '\\')
{
out += "\\\\";
}
- else if ((unsigned char)(*it) > 127)
+ else if ((unsigned char)(c) > 127)
{
char s[5];
- snprintf(s, 5, "\\x%02x", (unsigned char)(*it));
+ snprintf(s, 5, "\\x%02x", (unsigned char)(c));
out += string(s);
}
else
{
- out += *it;
+ out += c;
}
}
{
out += "\\\\";
}
- else if (c <= ' ')
+ else if ((unsigned char)(c) <= ' ')
{
char s[5];
- snprintf(s, 5, "\\x%02x", c);
+ snprintf(s, 5, "\\x%02x", (unsigned char)(c));
out += string(s);
}
else
BOOST_AUTO_TEST_CASE(pipe_escape)
{
BOOST_CHECK_EQUAL(Pipe::escape("hello world\n"), "hello\\x20world\\x0a");
+
+ BOOST_CHECK_EQUAL(Pipe::escape("ä"), "ä");
}
BOOST_AUTO_TEST_CASE(pipe_unescape)
{
BOOST_CHECK_EQUAL(Pipe::unescape("hello\\x20world\\x0a"), "hello world\n");
+
+ BOOST_CHECK_EQUAL(Pipe::unescape("ä"), "ä");
}