[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Parsing strings written by string.format("%q")
- From: David Given <dg@...>
- Date: Wed, 23 Nov 2016 21:22:41 +0100
I want to write out strings to a file and read them back in again, in an
ASCII-safe way. I'm writing them out with string.format("%q"), because
it's cheap and easy[*], but now I need to read them back in again.
Actually going through the string and parsing the escapes seems like a
lot of work. A faster but much scarier alternative is to wrap the string
with 'return (<string>' and compile and execute it in a restricted
environment.
Given that the interpreter already contains code to safely turn an
escaped string into a Lua string, there must be a better way --- what is it?
--
┌─── dg@cowlark.com ───── http://www.cowlark.com ─────
│ "There is nothing in the world so dangerous --- and I mean *nothing*
│ --- as a children's story that happens to be true." --- Master Li Kao,
│ _The Bridge of Birds_
Attachment:
signature.asc
Description: OpenPGP digital signature