I am trying to write a function to transform a string literal in Delphi/pascal to the C equivalent. A string literal in Delphi matches the regex ("#"([0-9]{1,5}|"$"[0-9a-fA-F]{1,6})|"'"([^']|'')*"'")+ so that the string
"This is a test with a tab\ta breakline\nand apostrophe '"
will be written in Pascal as
'This is a test with a tab'#9'a breakline'#$A'and apostrophe '''
I managed to strip the apostrophes, but I am having trouble managing the special characters.
Simply use
replaceApp()function that can be found at: http://www.cppreference.com/wiki/string/basic_string/replaceThen code can look as:
Of course changes ‘\t’ -> ‘$7’ can be saved in some structure that you can use in loop instead of replacing each item in separate lines.
Edit:
Second solution (example taken from comment) with using
map: