String Templates

A string template is used to extract information from strings using templates, or creating a string by using a template and filling it with data. The class StringTemplate is taking care of this task. The constructor needs a template and two strings which defines the start and the end of all markers in the template. The template can be an empty string, but the strings defining markers must be non empty. Here is an example on how the class can be used.


  StringTemplate st = new StringTemplate("family{number}.tree", "{", "}");
  st.setMarker("{number}", "100");
  System.out.println(st.getPaintedTemplate());
  st.paintTemplate("family200.tree");
  System.out.println(st.getFirstValue("{number}"));
    
Running the code gives following output.

  family100.tree
  200
    
The template in this example is family{number}.tree while the only marker is {number} since markers start with '{' and ends with '}'. The second line of code sets the marker to 100 and the next row creates the results and prints it. The fourth row extracts 200 from the value and the next row prints it.

Attributes used to define the start and the end of markers in Softparsmap are markers_begin and markers_end. Some tags in def.xml are using templates and markers in order to extract data from strings and create strings.