I have case where I need to split a string in Java with various escape characters. The format will be something like:
id:"description",id:"description",....
id: numeric (int)
description: String escaped with EscapeUtils.escapeJava(input)
, it could contain any
readable characters, including :
, ,
and even "
which will be
escaped to \"
.
So, the String.split
method wouldn't seem appropiate as it could get issues with descriptions with ,
or :
. I know I can write some algorithm that will work fine, it is even a nice excersice to do Test Driven Development, but I was wondering if there's some lazy way around it and use some kind of parser that can do this kind of stuff?
My other possible approach is to generate a JSONArray and don't mess with complexity I'm not interested in, but it will requiere one more library dependency which I'm not convinced of incluidng in this module...
So, what I'm asking for is ideas on how this kind of problem can be solved (libraries, with the Java API, etc.).