aboutsummaryrefslogtreecommitdiff
path: root/libjava/gnu/regexp
diff options
context:
space:
mode:
authorMark Wielaard <mark@klomp.org>2004-05-15 17:50:09 +0000
committerMark Wielaard <mark@gcc.gnu.org>2004-05-15 17:50:09 +0000
commitf437e359921603b19e22c44b44f6bb64c199b04f (patch)
tree75ae3d60d495fd40291164e2bc465b372a5f2946 /libjava/gnu/regexp
parentdc4917425181e331c20a26437d46c79c3cb9885b (diff)
downloadgcc-f437e359921603b19e22c44b44f6bb64c199b04f.zip
gcc-f437e359921603b19e22c44b44f6bb64c199b04f.tar.gz
gcc-f437e359921603b19e22c44b44f6bb64c199b04f.tar.bz2
CharIndexedReader.java: Removed.
* gnu/regexp/CharIndexedReader.java: Removed. * gnu/regexp/REFilterReader.java: Likewise. * gnu/regexp/RETokenLookAhead.java: Likewise. * Makefile.am (ordinary_java_source_files): Remove above classes. * Makefile.in: Regenerated. From-SVN: r81890
Diffstat (limited to 'libjava/gnu/regexp')
-rw-r--r--libjava/gnu/regexp/CharIndexedReader.java142
-rw-r--r--libjava/gnu/regexp/REFilterReader.java117
-rw-r--r--libjava/gnu/regexp/RETokenLookAhead.java68
3 files changed, 0 insertions, 327 deletions
diff --git a/libjava/gnu/regexp/CharIndexedReader.java b/libjava/gnu/regexp/CharIndexedReader.java
deleted file mode 100644
index aa0fa5a..0000000
--- a/libjava/gnu/regexp/CharIndexedReader.java
+++ /dev/null
@@ -1,142 +0,0 @@
-/*
- * gnu/regexp/CharIndexedReader.java
- * Copyright (C) 2001 Lee Sau Dan
- * Based on gnu.regexp.CharIndexedInputStream by Wes Biggs
- *
- * This library is free software; you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published
- * by the Free Software Foundation; either version 2.1 of the License, or
- * (at your option) any later version.
- *
- * This library 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 Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-package gnu.regexp;
-import java.io.Reader;
-import java.io.BufferedReader;
-import java.io.IOException;
-
-// TODO: move(x) shouldn't rely on calling next() x times
-
-class CharIndexedReader implements CharIndexed {
- private static final int BUFFER_INCREMENT = 1024;
- private static final int UNKNOWN = Integer.MAX_VALUE; // value for end
-
- private final BufferedReader br;
- // so that we don't try to reset() right away
- private int index = -1;
-
- private int bufsize = BUFFER_INCREMENT;
-
- private int end = UNKNOWN;
-
- private char cached = OUT_OF_BOUNDS;
-
- // Big enough for a \r\n pair
- // lookBehind[0] = most recent
- // lookBehind[1] = second most recent
- private char[] lookBehind = new char[] { OUT_OF_BOUNDS, OUT_OF_BOUNDS };
-
- CharIndexedReader(Reader reader, int index) {
- if (reader instanceof BufferedReader) {
- br = (BufferedReader) reader;
- } else {
- br = new BufferedReader(reader,BUFFER_INCREMENT);
- }
- next();
- if (index > 0) move(index);
- }
-
- private boolean next() {
- lookBehind[1] = lookBehind[0];
- lookBehind[0] = cached;
-
- if (end == 1) {
- cached = OUT_OF_BOUNDS;
- return false;
- }
- end--; // closer to end
-
- try {
- if (index != -1) {
- br.reset();
- }
- int i = br.read();
- br.mark(bufsize);
- if (i == -1) {
- end = 1;
- cached = OUT_OF_BOUNDS;
- return false;
- }
-
- // convert the byte read into a char
- cached = (char) i;
- index = 1;
- } catch (IOException e) {
- e.printStackTrace();
- cached = OUT_OF_BOUNDS;
- return false;
- }
- return true;
- }
-
- public char charAt(int index) {
- if (index == 0) {
- return cached;
- } else if (index >= end) {
- return OUT_OF_BOUNDS;
- } else if (index >= bufsize) {
- // Allocate more space in the buffer.
- try {
- while (bufsize <= index) bufsize += BUFFER_INCREMENT;
- br.reset();
- br.mark(bufsize);
- br.skip(index-1);
- } catch (IOException e) { }
- } else if (this.index != index) {
- try {
- br.reset();
- br.skip(index-1);
- } catch (IOException e) { }
- } else if (index == -1) {
- return lookBehind[0];
- } else if (index == -2) {
- return lookBehind[1];
- } else if (index < -2) {
- return OUT_OF_BOUNDS;
- }
-
- char ch = OUT_OF_BOUNDS;
-
- try {
- int i = br.read();
- this.index = index+1; // this.index is index of next pos relative to charAt(0)
- if (i == -1) {
- // set flag that next should fail next time?
- end = index;
- return ch;
- }
- ch = (char) i;
- } catch (IOException ie) { }
-
- return ch;
- }
-
- public boolean move(int index) {
- // move read position [index] clicks from 'charAt(0)'
- boolean retval = true;
- while (retval && (index-- > 0)) retval = next();
- return retval;
- }
-
- public boolean isValid() {
- return (cached != OUT_OF_BOUNDS);
- }
-}
diff --git a/libjava/gnu/regexp/REFilterReader.java b/libjava/gnu/regexp/REFilterReader.java
deleted file mode 100644
index 449efcc..0000000
--- a/libjava/gnu/regexp/REFilterReader.java
+++ /dev/null
@@ -1,117 +0,0 @@
-/*
- * gnu/regexp/REFilterReader.java
- * Copyright (C) 2001 Lee Sau Dan
- * Based on gnu.regexp.REFilterInputStream by Wes Biggs
- *
- * This library is free software; you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published
- * by the Free Software Foundation; either version 2.1 of the License, or
- * (at your option) any later version.
- *
- * This library 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 Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-package gnu.regexp;
-import java.io.FilterReader;
-import java.io.Reader;
-
-/**
- * Replaces instances of a given RE with replacement text.
- *
- * @author <A HREF="http://www.csis.hku.hk/~sdlee/">Lee Sau Dan</A>
- * @since gnu.regexp 1.1.0
- */
-
-public class REFilterReader extends FilterReader {
-
- private RE expr;
- private String replace;
- private String buffer;
- private int bufpos;
- private int offset;
- private CharIndexedReader stream;
-
- /**
- * Creates an REFilterReader. When reading from this stream,
- * occurrences of patterns matching the supplied regular expression
- * will be replaced with the supplied replacement text (the
- * metacharacters $0 through $9 may be used to refer to the full
- * match or subexpression matches.
- *
- * @param stream The Reader to be filtered.
- * @param expr The regular expression to search for.
- * @param replace The text pattern to replace matches with.
- */
- public REFilterReader(Reader stream, RE expr, String replace) {
- super(stream);
- this.stream = new CharIndexedReader(stream,0);
- this.expr = expr;
- this.replace = replace;
- }
-
- /**
- * Reads the next character from the stream per the general contract of
- * Reader.read(). Returns -1 on error or end of stream.
- */
- public int read() {
- // If we have buffered replace data, use it.
- if ((buffer != null) && (bufpos < buffer.length())) {
- return (int) buffer.charAt(bufpos++);
- }
-
- // check if input is at a valid position
- if (!stream.isValid()) return -1;
-
- REMatch mymatch = new REMatch(expr.getNumSubs(),offset,0);
- if (expr.match(stream,mymatch)) {
- mymatch.end[0] = mymatch.index;
- mymatch.finish(stream);
- stream.move(mymatch.toString().length());
- offset += mymatch.toString().length();
- buffer = mymatch.substituteInto(replace);
- bufpos = 1;
-
- if (buffer.length() > 0) {
- return buffer.charAt(0);
- }
- }
- char ch = stream.charAt(0);
- if (ch == CharIndexed.OUT_OF_BOUNDS) return -1;
- stream.move(1);
- offset++;
- return ch;
- }
-
- /**
- * Returns false. REFilterReader does not support mark() and
- * reset() methods.
- */
- public boolean markSupported() {
- return false;
- }
-
- /** Reads from the stream into the provided array. */
- public int read(char[] b, int off, int len) {
- int i;
- int ok = 0;
- while (len-- > 0) {
- i = read();
- if (i == -1) return (ok == 0) ? -1 : ok;
- b[off++] = (char) i;
- ok++;
- }
- return ok;
- }
-
- /** Reads from the stream into the provided array. */
- public int read(char[] b) {
- return read(b,0,b.length);
- }
-}
diff --git a/libjava/gnu/regexp/RETokenLookAhead.java b/libjava/gnu/regexp/RETokenLookAhead.java
deleted file mode 100644
index 74a9bfe..0000000
--- a/libjava/gnu/regexp/RETokenLookAhead.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * gnu/regexp/RETokenOneOf.java
- * Copyright (C) 1998-2001 Wes Biggs
- *
- * This library is free software; you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published
- * by the Free Software Foundation; either version 2.1 of the License, or
- * (at your option) any later version.
- *
- * This library 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 Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-package gnu.regexp;
-
-/**
- * @since gnu.regexp 1.1.3
- * @author Shashank Bapat
- */
-final class RETokenLookAhead extends REToken
-{
- REToken re;
- boolean negative;
-
- RETokenLookAhead(REToken re, boolean negative) throws REException {
- super(0);
- this.re = re;
- this.negative = negative;
- }
-
- boolean match(CharIndexed input, REMatch mymatch)
- {
- REMatch trymatch = (REMatch)mymatch.clone();
- REMatch trymatch1 = (REMatch)mymatch.clone();
- REMatch newMatch = null;
- if (re.match(input, trymatch)) {
- if (negative) return false;
- if (next(input, trymatch1))
- newMatch = trymatch1;
- }
-
- if (newMatch != null) {
- if (negative) return false;
- //else
- mymatch.assignFrom(newMatch);
- return true;
- }
- else { // no match
- if (negative)
- return next(input, mymatch);
- //else
- return false;
- }
- }
-
- void dump(StringBuffer os) {
- os.append("(?");
- os.append(negative ? '!' : '=');
- re.dumpAll(os);
- os.append(')');
- }
-}
-