/interpreter/tags/at2dist130208/src/edu/vub/util/regexp/UncheckedRE.java

http://ambienttalk.googlecode.com/ · Java · 109 lines · 16 code · 7 blank · 86 comment · 0 complexity · e1572b690c7e2947a12f618ea1554bf4 MD5 · raw file

  1. /* gnu/regexp/UncheckedRE.java
  2. Copyright (C) 2001, 2004 Free Software Foundation, Inc.
  3. This file is part of GNU Classpath.
  4. GNU Classpath is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2, or (at your option)
  7. any later version.
  8. GNU Classpath is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GNU Classpath; see the file COPYING. If not, write to the
  14. Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  15. 02110-1301 USA.
  16. Linking this library statically or dynamically with other modules is
  17. making a combined work based on this library. Thus, the terms and
  18. conditions of the GNU General Public License cover the whole
  19. combination.
  20. As a special exception, the copyright holders of this library give you
  21. permission to link this library with independent modules to produce an
  22. executable, regardless of the license terms of these independent
  23. modules, and to copy and distribute the resulting executable under
  24. terms of your choice, provided that you also meet, for each linked
  25. independent module, the terms and conditions of the license of that
  26. module. An independent module is a module which is not derived from
  27. or based on this library. If you modify this library, you may extend
  28. this exception to your version of the library, but you are not
  29. obligated to do so. If you do not wish to do so, delete this
  30. exception statement from your version. */
  31. package edu.vub.util.regexp;
  32. /**
  33. * UncheckedRE is a subclass of RE that allows programmers an easier means
  34. * of programmatically precompiling regular expressions. It is constructed
  35. * and used in exactly the same manner as an instance of the RE class; the
  36. * only difference is that its constructors do not throw REException.
  37. * Instead, if a syntax error is encountered during construction, a
  38. * RuntimeException will be thrown.
  39. * <P>
  40. * Note that this makes UncheckedRE dangerous if constructed with
  41. * dynamic data. Do not use UncheckedRE unless you are completely sure
  42. * that all input being passed to it contains valid, well-formed
  43. * regular expressions for the syntax specified.
  44. *
  45. * @author <A HREF="mailto:wes@cacas.org">Wes Biggs</A>
  46. * @see edu.vub.util.regexp.RE
  47. * @since edu.vub.util.regexp 1.1.4
  48. */
  49. public final class UncheckedRE extends RE {
  50. /**
  51. * Constructs a regular expression pattern buffer without any compilation
  52. * flags set, and using the default syntax (RESyntax.RE_SYNTAX_PERL5).
  53. *
  54. * @param pattern A regular expression pattern, in the form of a String,
  55. * StringBuffer or char[]. Other input types will be converted to
  56. * strings using the toString() method.
  57. * @exception RuntimeException The input pattern could not be parsed.
  58. * @exception NullPointerException The pattern was null.
  59. */
  60. public UncheckedRE(Object pattern) {
  61. this(pattern,0,RESyntax.RE_SYNTAX_PERL5);
  62. }
  63. /**
  64. * Constructs a regular expression pattern buffer using the specified
  65. * compilation flags and the default syntax (RESyntax.RE_SYNTAX_PERL5).
  66. *
  67. * @param pattern A regular expression pattern, in the form of a String,
  68. * StringBuffer, or char[]. Other input types will be converted to
  69. * strings using the toString() method.
  70. * @param cflags The logical OR of any combination of the compilation flags in the RE class.
  71. * @exception RuntimeException The input pattern could not be parsed.
  72. * @exception NullPointerException The pattern was null.
  73. */
  74. public UncheckedRE(Object pattern, int cflags) {
  75. this(pattern,cflags,RESyntax.RE_SYNTAX_PERL5);
  76. }
  77. /**
  78. * Constructs a regular expression pattern buffer using the specified
  79. * compilation flags and regular expression syntax.
  80. *
  81. * @param pattern A regular expression pattern, in the form of a String,
  82. * StringBuffer, or char[]. Other input types will be converted to
  83. * strings using the toString() method.
  84. * @param cflags The logical OR of any combination of the compilation flags in the RE class.
  85. * @param syntax The type of regular expression syntax to use.
  86. * @exception RuntimeException The input pattern could not be parsed.
  87. * @exception NullPointerException The pattern was null.
  88. */
  89. public UncheckedRE(Object pattern, int cflags, RESyntax syntax) {
  90. try {
  91. initialize(pattern,cflags,syntax,0,0);
  92. } catch (REException e) {
  93. throw new RuntimeException(e.getMessage());
  94. }
  95. }
  96. }