I am looking for an elegant and simple solution to the following problem .. it is not something I think I can do easily with StringReplace or grep, t my attempts at it have ended up with nasty code that fails to take account of special cases.
Essentially I want to enclose some source strings in quotation marks, while taking account of \n, to form a valid delphi string assignment statement. (it is sort of a heredoc front end to Delphi, invoked from the tools menu). Line breaks in the source strings are not significant, nor are leading and trailing spaces, except that test lines within a paragraph are assumed to have a single space separating words on consecutive lines..
So if I start out with
fred <<< a frog he would
a wooing go,\n\n whether his mother would
let him or no \n
I want to generate the delphi code
fred := 'a frog he would a wooing go,'+#13+#10+#13+#10+
'whether his mother would let him or no'+#13+#10+#13+#10+'hey ho';
Anyone care to code up something elegant to handle this? Maybe it is some sort of state machine?