Putting quotes in wysiwyg strings

Stewart Gordon smjg_1998 at yahoo.com
Thu Nov 23 10:45:33 PST 2006


Bill Baxter wrote:
>  From the spec:  'There are no escape sequences inside r" ":'
> 
> Shouldn't there be an exception for the " character itself?

That would defeat the whole point.

> Right now the only way to put the quote into a wysiwyg string like
>     foo"bar
> is something like:
>     r"foo" ~'"'~ r"bar";
> or
>     r"foo" "\"" r"bar";
> or
>     r"foo" `"` r"bar";

You missed off

     r"foo" \" r"bar";

> It would be a lot nicer if one could just do:
> 
>     r"foo\"bar";

Then how would one put a backslash at the end of a wysiwyg string?

<snip>
> The goal is that the output string should look as much like the original 
> text as possible.  One main use will be for embedding short script 
> programs (like lua or minid) inside a D executable.
> 
> This:
>     if (k & e.Shift) { ret ~= " `"` r"Shift" `"` r"; }
>     if (k & e.Ctrl)  { if (ret) ret~=" `"` r"|" `"` r"; ret ~= " `"` 
> r"Ctrl" `"` r"; }
>     if (k & e.Alt)   { if (ret) ret~=" `"` r"|" `"` r"; ret ~= " `"` 
> r"Alt" `"`
> r"; }
>     if (!ret) ret = " `"` r"None" `"` r";
> 
> definitely does not look very much like the original code.  :-(
<snip>

I see now.  Do you read the input line by line?  If so, you could detect 
whether each line contains '"' or '`', and switch between r"..." and 
`...` at the beginning of the line if necessary.  You'll only need such 
messy code as the above for lines that contain both characters.

BTW I've used the search and replace technique before.  See

http://smjg.port5.com/wwwep/quines/d.html

Stewart.

-- 
-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GCS/M d- s:-@ C++@ a->--- UB@ P+ L E@ W++@ N+++ o K-@ w++@ O? M V? PS- 
PE- Y? PGP- t- 5? X? R b DI? D G e++++ h-- r-- !y
------END GEEK CODE BLOCK------

My e-mail is valid but not my primary mailbox.  Please keep replies on 
the 'group where everyone may benefit.



More information about the Digitalmars-d mailing list