package com.ronsoft.books.nio.regex; import java.util.regex.Pattern; import java.util.List; import java.util.LinkedList; /** * Demonstrate behavior of splitting strings. The XML output created * here can be styled into HTML or some other useful form. * See poodle.xsl. * * Created: April, 2002 * @author Ron Hitchens (ron@ronsoft.com) * @version $Id: Poodle.java,v 1.3 2002/05/01 03:47:07 ron Exp $ */ public class Poodle { /** * Generate a matrix table of how Pattern.split() behaves with * various regex patterns and limit values. */ public static void main (String [] argv) throws Exception { String input = "poodle zoo"; Pattern space = Pattern.compile (" "); Pattern d = Pattern.compile ("d"); Pattern o = Pattern.compile ("o"); Pattern [] patterns = { space, d, o }; int limits [] = { 1, 2, 5, -2, 0 }; // Use supplied args, if any. Assume args are good. // Usage: input pattern [pattern ...] // Don't forget to quote the args. if (argv.length != 0) { input = argv [0]; patterns = collectPatterns (argv); } generateTable (input, patterns, limits); } /** * Output a simple XML document with the results of applying * the list of regex patterns to the input with each of the * limit values provided. I should probably use the JAX APIs * to do this, but I want to keep the code simple. */ private static void generateTable (String input, Pattern [] patterns, int [] limits) { System.out.println (""); System.out.println ("