Here you can find the source of splitMacros(String s)
Parameter | Description |
---|---|
s | String to parse |
public static List<String> splitMacros(String s)
//package com.java2s; import java.util.*; public class Main { /**//from w w w . j a v a 2 s . c o m * This parses the given string with the following form. * <pre>some text ${macro1} more text ... ${macro2} ... ${macroN} end text</pre> * It returns a list that flip-flops between the text and the macro:<pre> * [some text, macro1, more text, ..., macro2, ..., macroN, end text] * </pre> * * @param s String to parse * @return List of tokens */ public static List<String> splitMacros(String s) { List<String> tokens = new ArrayList<String>(); int idx1 = s.indexOf("${"); while (idx1 >= 0) { int idx2 = s.indexOf("}", idx1); if (idx2 < 0) { break; } tokens.add(s.substring(0, idx1)); tokens.add(s.substring(idx1 + 2, idx2)); s = s.substring(idx2 + 1); idx1 = s.indexOf("${"); } if (s.length() > 0) { tokens.add(s); } return tokens; } }