// Path: alice-src/bitoflife/chatterbean/config/TokenizerConfig.java
// public interface TokenizerConfig
// {
//   public Tokenizer newInstance();
// 
//   public String[] splitters();
// }
// 
// Path: alice-src/bitoflife/chatterbean/util/Escaper.java
// public static String escapeRegex(String splitter)
// {
//   String special = "";
//   try
//   {
//     splitter = splitter.replaceAll("\\\\", "\\\\\\\\");
// 
//     for (int i = 0, n = regex.length; i < n; i++)
//     {
//       special = regex[i];
//       splitter = splitter.replaceAll(special, "\\" + special);
//     }
//   }
//   catch (RuntimeException e)
//   {
//     throw new RuntimeException(e.getMessage() + "\nWhen trying to escape \"" + special + "\" in \"" + splitter + "\"", e);
//   }
// 
//   return splitter;
// }


import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import bitoflife.chatterbean.config.TokenizerConfig;
import static bitoflife.chatterbean.util.Escaper.escapeRegex;
/*
Copyleft (C) 2005 Hio Perroni Filho
xperroni@yahoo.com
ICQ: 2490863

This file is part of ChatterBean.

ChatterBean is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

ChatterBean is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with ChatterBean (look at the Documents/ directory); if not, either write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA, or visit (http://www.gnu.org/licenses/gpl.txt).
*/

package bitoflife.chatterbean.text;



public class Tokenizer
{
  /*
  Attribute Section
  */

  private Boolean ignoreWhitespace;

  private String[] splitters;

  private Pattern pattern;

  /*
  Constructor Section
  */

  public Tokenizer()
  {
  }

  public Tokenizer(String... splitters)
  {
    setIgnoreWhitespace(true);
    setSplitters(splitters);
  }

  public Tokenizer(TokenizerConfig config)
  {
    this(config.splitters());
  }

  /*
  Event Section
  */

  private void afterSetProperty()
  {
    if (splitters == null || ignoreWhitespace == null)
      return;

    String expression = "";
    for (int i = 0, n = splitters.length;;)
    {
// Path: alice-src/bitoflife/chatterbean/config/TokenizerConfig.java
// public interface TokenizerConfig
// {
//   public Tokenizer newInstance();
// 
//   public String[] splitters();
// }
// 
// Path: alice-src/bitoflife/chatterbean/util/Escaper.java
// public static String escapeRegex(String splitter)
// {
//   String special = "";
//   try
//   {
//     splitter = splitter.replaceAll("\\\\", "\\\\\\\\");
// 
//     for (int i = 0, n = regex.length; i < n; i++)
//     {
//       special = regex[i];
//       splitter = splitter.replaceAll(special, "\\" + special);
//     }
//   }
//   catch (RuntimeException e)
//   {
//     throw new RuntimeException(e.getMessage() + "\nWhen trying to escape \"" + special + "\" in \"" + splitter + "\"", e);
//   }
// 
//   return splitter;
// }


// Path: alice-src/bitoflife/chatterbean/text/Tokenizer.java
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import bitoflife.chatterbean.config.TokenizerConfig;
import static bitoflife.chatterbean.util.Escaper.escapeRegex;

/*
Copyleft (C) 2005 Hio Perroni Filho
xperroni@yahoo.com
ICQ: 2490863

This file is part of ChatterBean.

ChatterBean is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

ChatterBean is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with ChatterBean (look at the Documents/ directory); if not, either write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA, or visit (http://www.gnu.org/licenses/gpl.txt).
*/

package bitoflife.chatterbean.text;



public class Tokenizer
{
  /*
  Attribute Section
  */

  private Boolean ignoreWhitespace;

  private String[] splitters;

  private Pattern pattern;

  /*
  Constructor Section
  */

  public Tokenizer()
  {
  }

  public Tokenizer(String... splitters)
  {
    setIgnoreWhitespace(true);
    setSplitters(splitters);
  }

  public Tokenizer(TokenizerConfig config)
  {
    this(config.splitters());
  }

  /*
  Event Section
  */

  private void afterSetProperty()
  {
    if (splitters == null || ignoreWhitespace == null)
      return;

    String expression = "";
    for (int i = 0, n = splitters.length;;)
    {
      expression += escapeRegex(splitters[i]);