+ private static final String VARIABLE = "\\$!?\\{[a-zA-Z0-9_-]+\\}";
+
+ private static final Pattern processingInstruction = Pattern.compile("(" + VARIABLE + ")|(!'[^{}'\\$]*)'");
+
+ /**
+ * Creates a new SprintfCommand that is parsed as from template source.
+ *
+ * @param content
+ * the part from the template that is to be parsed.
+ */
+ protected SprintfCommand(String content) {
+ StringBuffer raw = new StringBuffer();
+ List<String> var = new LinkedList<String>();
+ int counter = 0;
+ Matcher m = processingInstruction.matcher(content);
+ int last = 0;
+ while (m.find()) {
+ raw.append(content.substring(last, m.start()));
+ String group = null;
+ if ((group = m.group(1)) != null) {
+ var.add(group);
+ } else if ((group = m.group(2)) != null) {
+ var.add(group);
+ } else {
+ throw new Error("Regex is broken??");
+ }
+ last = m.end();
+ raw.append("{" + (counter++) + "}");
+ }
+ raw.append(content.substring(last));
+ text = raw.toString();
+ store = var.toArray(new String[var.size()]);
+ }
+
+ private static final Pattern replacant = Pattern.compile("\\{([0-9]+)\\}");
+