PageRenderTime 40ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/jEdit/tags/jedit-4-1-pre5/gnu/regexp/UncheckedRE.java

#
Java | 91 lines | 16 code | 7 blank | 68 comment | 0 complexity | 89866c92477993c71d24a13733681c8c MD5 | raw file
Possible License(s): BSD-3-Clause, AGPL-1.0, Apache-2.0, LGPL-2.0, LGPL-3.0, GPL-2.0, CC-BY-SA-3.0, LGPL-2.1, GPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0
  1. /*
  2. * gnu/regexp/UncheckedRE.java
  3. * Copyright (C) 2001 Wes Biggs
  4. *
  5. * This library is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU Lesser General Public License as published
  7. * by the Free Software Foundation; either version 2.1 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This library is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU Lesser General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Lesser General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18. */
  19. package gnu.regexp;
  20. /**
  21. * UncheckedRE is a subclass of RE that allows programmers an easier means
  22. * of programmatically precompiling regular expressions. It is constructed
  23. * and used in exactly the same manner as an instance of the RE class; the
  24. * only difference is that its constructors do not throw REException.
  25. * Instead, if a syntax error is encountered during construction, a
  26. * RuntimeException will be thrown.
  27. * <P>
  28. * Note that this makes UncheckedRE dangerous if constructed with
  29. * dynamic data. Do not use UncheckedRE unless you are completely sure
  30. * that all input being passed to it contains valid, well-formed
  31. * regular expressions for the syntax specified.
  32. *
  33. * @author <A HREF="mailto:wes@cacas.org">Wes Biggs</A>
  34. * @see gnu.regexp.RE
  35. * @since gnu.regexp 1.1.4
  36. */
  37. public final class UncheckedRE extends RE {
  38. /**
  39. * Constructs a regular expression pattern buffer without any compilation
  40. * flags set, and using the default syntax (RESyntax.RE_SYNTAX_PERL5).
  41. *
  42. * @param pattern A regular expression pattern, in the form of a String,
  43. * StringBuffer or char[]. Other input types will be converted to
  44. * strings using the toString() method.
  45. * @exception RuntimeException The input pattern could not be parsed.
  46. * @exception NullPointerException The pattern was null.
  47. */
  48. public UncheckedRE(Object pattern) {
  49. this(pattern,0,RESyntax.RE_SYNTAX_PERL5);
  50. }
  51. /**
  52. * Constructs a regular expression pattern buffer using the specified
  53. * compilation flags and the default syntax (RESyntax.RE_SYNTAX_PERL5).
  54. *
  55. * @param pattern A regular expression pattern, in the form of a String,
  56. * StringBuffer, or char[]. Other input types will be converted to
  57. * strings using the toString() method.
  58. * @param cflags The logical OR of any combination of the compilation flags in the RE class.
  59. * @exception RuntimeException The input pattern could not be parsed.
  60. * @exception NullPointerException The pattern was null.
  61. */
  62. public UncheckedRE(Object pattern, int cflags) {
  63. this(pattern,cflags,RESyntax.RE_SYNTAX_PERL5);
  64. }
  65. /**
  66. * Constructs a regular expression pattern buffer using the specified
  67. * compilation flags and regular expression syntax.
  68. *
  69. * @param pattern A regular expression pattern, in the form of a String,
  70. * StringBuffer, or char[]. Other input types will be converted to
  71. * strings using the toString() method.
  72. * @param cflags The logical OR of any combination of the compilation flags in the RE class.
  73. * @param syntax The type of regular expression syntax to use.
  74. * @exception RuntimeException The input pattern could not be parsed.
  75. * @exception NullPointerException The pattern was null.
  76. */
  77. public UncheckedRE(Object pattern, int cflags, RESyntax syntax) {
  78. try {
  79. initialize(pattern,cflags,syntax,0,0);
  80. } catch (REException e) {
  81. throw new RuntimeException(e.getMessage());
  82. }
  83. }
  84. }