Hi I am trying to parse VML Path value using Java String manipulation. I want to retreive all the commands in the path like MoveTo, LineTo, CurveTo, RLineTo (other commands) and their corresponding x and y coordinates/parameters.
Here are example data to parse, each command has their own x,y coordinates.
1. m1,1 l1,200,200,200,200,1 xe
2. m, l1,200,200,200,200,1 xe
Can you suggest an algorithm or code on retreiving the commands and the parameters for each command? For example in number 1.
Command = moveto 'm'
Command Parameters = (x=1,y=1).
Ref: http://www.w3.org/TR/NOTE-VML#_Toc416858391
This is something weird but I tried using StringTokenizer like
StringTokenizer tokenizer = new StringTokenizer(path);
A friend suggested using StringTokenizer and it did something near to my goal, it gave me the following data. Maybe I can utilize StringTokenizer to suit my needs.
m1,1
l1,200,200,200,200,1
xe
For #1, here is the ideal output. (pseudocode)
String command_type = "m" List<String, String> parameters = add("1", "1")
String command_type = "l" List<String, String> parameters = add("1", "200")
add("200", "200")
add("200", "1")
String command_type = "x" (can have no parameter )
String command_type = "e" (can have no parameter )
For #2, here is the ideal output. (pseudocode)
String command_type = "m" List<String, String> parameters = add("0", "0") // because the x and y parameters are not specified so I need to force them to 0,0
String command_type = "l" List<String, String> parameters = add("1", "200")
add("200", "200")
add("200", "1")
String command_type = "x" (can have no parameter )
String command_type = "e" (can have no parameter )
A good spec is important here but based on your sample input and output I have guessed:
Letter -> comma separated parameters -> letter -> comma separated parameters
I have also noted that commands are not separated by spaces. e.g. you have xe as two separate commands. This means that in your sample spaces have no meaning and can be ignored.
I also note that commands are all single letters. (Otherwise xe wouldn’t come as two commands)
Also Parameters must come in pairs and must be numbers. I see no negative numbers in your sample but I assume that these are possible. I will also assume that they are integers and not decimals.
So based on the assumed spec I can come up with a possible solution for you to have a look through and work out what it is doing.