import java.util.ArrayList;
import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
public class String2 {
public String toString() {
return getSubString(0, chars.size());
}
+
+
+ public static String[] getGroups(String s, String regexp){
+ Pattern pattern = Pattern.compile(regexp);
+ Matcher matcher = pattern.matcher(s);
+
+ matcher.find();
+ String[] result = new String[matcher.groupCount()];
+
+ for (int i = 0; i< result.length; i++){
+ result[i] = matcher.group(i+1);
+ }
+
+ return result;
+ }
}
assertFalse(tokenizer.hasMoreContent());
}
+
+ @Test
+ public void testMultilineTokenization() throws Exception {
+ Tokenizer tokenizer = new Tokenizer(
+ "* heading\r\nnormal text\r\nnormal text 2");
+ tokenizer.addTerminator(PRESERVE,"\\*[ \\t]+.*\\r?\\n");
+ tokenizer.addTerminator(DROP,"\\r?\\n", "normalText");
+
+ assertTokenEquals("* heading\r\n", tokenizer);
+ assertTokenEquals("normal text", tokenizer);
+ assertTokenEquals("normal text 2", tokenizer);
+
+ assertNull(tokenizer.getNextToken());
+ assertFalse(tokenizer.hasMoreContent());
+ }
+
+
private void assertTokenEquals(String expectedValue, Tokenizer tokenizer){
assertEquals(expectedValue, tokenizer.getNextToken().token);
}