Convert String-arguments of JavaModelMarker into an Array

The JDT has a marker type, which contains an attribute called “arguments”. It is defined in the documentation:

Id marker attribute (value “arguments”). Arguments are concatenated into one String, prefixed with an argument count (followed with colon separator) and separated with ‘#’ characters. For example: { “foo”, “bar” } is encoded as “2:foo#bar”, { } is encoded as “0:”.

Empty argument is encoded as three spaces (” “).

If the argument contains a ‘#’, the character is doubled.
{“foo#test”, “bar” } is encoded as “2:foo##test#bar”

Now I want a reliable method to convert that encoded String into a String-Array. For example "2:foo##test#bar" -> {"foo", "#test", "bar"}.

"2:foo##test#bar".split("#") obviously wouldn’t do the job. At least because of the encoding of the hash sign. What would you suggest to handle this?


Source: regex

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.