[ create a new paste ] login | about

Link: http://codepad.org/sYJvjmLp    [ raw code | output | fork ]

C++, pasted on Mar 21:
#include <iostream>
#include <string>

std::string 
escape_seq (const char * text)
{
   std::string res;
   unsigned char c;
   while (0 != (c = *text ++))
   {
      if (isascii (c) && isprint (c))
         res += c;
      else
      {
         char buf [16];
         sprintf (buf, "\\x%02x", c);
         res += buf;
      }
   }
   return res;
}

int main()
{
   std::cout << escape_seq ("TEST\r\t\n") << std::endl;;
}


Output:
1
TEST\x0d\x09\x0a


Create a new paste based on this one


Comments: