onlyMe
onlyMe

Reputation: 127

Escaping characters in database

I'm trying to build my own simple database and I'm solving one final problem. I'm saving database data to file using my own format (really simplified JSON cut off of everything not required). That problem is escaping. I'm using (for example) { as char to signify upcoming name of table. Problem comes when someone uses { in tableName. How to solve this?

If I just change it to some another value, user may enter that replace string and after decoding saved database back to program readable way (arrays,...), these strings will be decoded and user won't get what he put in. I spend long time thinking about this and couldn't find any solution. Any ideas?

Upvotes: 1

Views: 1789

Answers (1)

Brad
Brad

Reputation: 163334

You need an escape character of sort. Don't just replace it.

Assuming { is ambiguous, to refer to a literal { you would use \{. Now, the \ is ambiguous, so simply allow escaping it as well with \\. No more ambiguity!

Upvotes: 2

Related Questions