Friday 15 March 2013

string - Using escape sequence at runtime with C++ -



string - Using escape sequence at runtime with C++ -

i quiet new c++ , need read input msvc++ text-field , write file. need write \n new line file , not \n.

after researching found escape characters work @ compile-time. possible me utilize on run-time. using c++ task.

i might write bit differently if doing in c++ today (i wrote in c around 20 years ago), might @ to the lowest degree provide little inspiration:

/* ** public domain jerry coffin. ** ** interprets string in manner similar compiler ** string literals in program. escape sequences ** longer translated equivalant, string ** translated in place , either remains same length or ** becomes shorter. */ #include <string.h> #include <stdio.h> #include "snip_str.h" char *translate(char *string) { char *here=string; size_t len=strlen(string); int num; int numlen; while (null!=(here=strchr(here,'\\'))) { numlen=1; switch (here[1]) { case '\\': break; case 'r': *here = '\r'; break; case 'n': *here = '\n'; break; case 't': *here = '\t'; break; case 'v': *here = '\v'; break; case 'a': *here = '\a'; break; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': numlen = sscanf(here,"%o",&num); *here = (char)num; break; case 'x': numlen = sscanf(here,"%x",&num); *here = (char) num; break; } num = here - string + numlen; here++; memmove(here,here+numlen,len-num ); } homecoming string; }

c++ string unicode escaping

No comments:

Post a Comment