Disclaimer: this is theoretical question with the purpose of increasing my understanding. I know that I can always use tools like a JSON library to solve the problem.
Suppose I want to create a comma separated list of values which may themselves contain comma's. These commas need to be escaped first. Assuming that I use . as the escape character then ["a", "b,c"] becomes a,b.,c.
However, if one of the values originally contained a ., sequence then we'd need to escape those before escaping the commas. So [ "a", "b.,c" ] becomes a,b..,c.
However, if one of the values originally contained a .., sequence then we'd need to escape those before escaping the commas. So [ "a", "b..,c" ] becomes a,b...,c.
However, if one of the values originally contained a ..., sequence then we'd need to escape those before escaping the commas. So [ "a", "b...,c" ] becomes a,b....,c.
Etc...
The decoding process must perform the reversed recursion.
However, I suspect if I'm making it too hard and there is a simpler way. Is there a simpler way?