Makefile.am: Build property resource files into libgcj.
2004-03-08 Anthony Green <green@redhat.com> * Makefile.am: Build property resource files into libgcj. * Makefile.in: Rebuilt. * java/util/regex/Matcher.java, java/util/regex/Pattern.java, java/util/regex/PatternSyntaxException.java, gnu/regexp/CharIndexed.java, gnu/regexp/CharIndexedCharArray.java, gnu/regexp/CharIndexedInputStream.java, gnu/regexp/CharIndexedReader.java, gnu/regexp/CharIndexedString.java, gnu/regexp/CharIndexedStringBuffer.java, gnu/regexp/RE.java, gnu/regexp/REException.java, gnu/regexp/REFilterInputStream.java, gnu/regexp/REFilterReader.java, gnu/regexp/REMatch.java, gnu/regexp/REMatchEnumeration.java, gnu/regexp/RESyntax.java, gnu/regexp/REToken.java, gnu/regexp/RETokenAny.java, gnu/regexp/RETokenBackRef.java, gnu/regexp/RETokenChar.java, gnu/regexp/RETokenEnd.java, gnu/regexp/RETokenEndSub.java, gnu/regexp/RETokenLookAhead.java, gnu/regexp/RETokenOneOf.java, gnu/regexp/RETokenPOSIX.java, gnu/regexp/RETokenRange.java, gnu/regexp/RETokenRepeated.java, gnu/regexp/RETokenStart.java, gnu/regexp/RETokenWordBoundary.java, gnu/regexp/UncheckedRE.java: Files merged from GNU Classpath. From-SVN: r79198
This commit is contained in:
parent
c497b9764a
commit
ec730df5fc
34 changed files with 5130 additions and 136 deletions
|
@ -1,5 +1,5 @@
|
|||
/* Matcher.java --
|
||||
Copyright (C) 2002 Free Software Foundation, Inc.
|
||||
/* Matcher.java -- Instance of a regular expression applied to a char sequence.
|
||||
Copyright (C) 2002, 2004 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
|
@ -38,13 +38,27 @@ exception statement from your version. */
|
|||
|
||||
package java.util.regex;
|
||||
|
||||
import gnu.regexp.RE;
|
||||
import gnu.regexp.REMatch;
|
||||
|
||||
/**
|
||||
* @author Michael Koch
|
||||
* Instance of a regular expression applied to a char sequence.
|
||||
*
|
||||
* @since 1.4
|
||||
*/
|
||||
public class Matcher
|
||||
{
|
||||
private Pattern pattern;
|
||||
private CharSequence input;
|
||||
private int position;
|
||||
private int appendPosition;
|
||||
private REMatch match;
|
||||
|
||||
Matcher(Pattern pattern, CharSequence input)
|
||||
{
|
||||
this.pattern = pattern;
|
||||
this.input = input;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param sb The target string buffer
|
||||
|
@ -58,7 +72,12 @@ public class Matcher
|
|||
public Matcher appendReplacement (StringBuffer sb, String replacement)
|
||||
throws IllegalStateException
|
||||
{
|
||||
throw new Error("Not implemented");
|
||||
assertMatchOp();
|
||||
sb.append(input.subSequence(appendPosition,
|
||||
match.getStartIndex()).toString());
|
||||
sb.append(match.substituteInto(replacement));
|
||||
appendPosition = match.getEndIndex();
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -66,7 +85,8 @@ public class Matcher
|
|||
*/
|
||||
public StringBuffer appendTail (StringBuffer sb)
|
||||
{
|
||||
throw new Error("Not implemented");
|
||||
sb.append(input.subSequence(appendPosition, input.length()).toString());
|
||||
return sb;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -76,7 +96,8 @@ public class Matcher
|
|||
public int end ()
|
||||
throws IllegalStateException
|
||||
{
|
||||
throw new Error ("Not implemented");
|
||||
assertMatchOp();
|
||||
return match.getEndIndex();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -90,14 +111,36 @@ public class Matcher
|
|||
public int end (int group)
|
||||
throws IllegalStateException
|
||||
{
|
||||
throw new Error ("Not implemented");
|
||||
assertMatchOp();
|
||||
return match.getEndIndex(group);
|
||||
}
|
||||
|
||||
public boolean find ()
|
||||
{
|
||||
throw new Error ("Not implemented");
|
||||
}
|
||||
|
||||
boolean first = (match == null);
|
||||
match = pattern.getRE().getMatch(input, position);
|
||||
if (match != null)
|
||||
{
|
||||
int endIndex = match.getEndIndex();
|
||||
// Are we stuck at the same position?
|
||||
if (!first && endIndex == position)
|
||||
{
|
||||
match = null;
|
||||
// Not at the end of the input yet?
|
||||
if (position < input.length() - 1)
|
||||
{
|
||||
position++;
|
||||
return find(position);
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
position = endIndex;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param start The index to start the new pattern matching
|
||||
*
|
||||
|
@ -106,7 +149,13 @@ public class Matcher
|
|||
*/
|
||||
public boolean find (int start)
|
||||
{
|
||||
throw new Error ("Not implemented");
|
||||
match = pattern.getRE().getMatch(input, start);
|
||||
if (match != null)
|
||||
{
|
||||
position = match.getEndIndex();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -115,7 +164,8 @@ public class Matcher
|
|||
*/
|
||||
public String group ()
|
||||
{
|
||||
throw new Error ("Not implemented");
|
||||
assertMatchOp();
|
||||
return match.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -129,7 +179,8 @@ public class Matcher
|
|||
public String group (int group)
|
||||
throws IllegalStateException
|
||||
{
|
||||
throw new Error ("Not implemented");
|
||||
assertMatchOp();
|
||||
return match.toString(group);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -137,7 +188,9 @@ public class Matcher
|
|||
*/
|
||||
public String replaceFirst (String replacement)
|
||||
{
|
||||
throw new Error ("Not implemented");
|
||||
reset();
|
||||
// Semantics might not quite match
|
||||
return pattern.getRE().substitute(input, replacement, position);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -145,17 +198,25 @@ public class Matcher
|
|||
*/
|
||||
public String replaceAll (String replacement)
|
||||
{
|
||||
throw new Error ("Not implemented");
|
||||
reset();
|
||||
return pattern.getRE().substituteAll(input, replacement, position);
|
||||
}
|
||||
|
||||
public int groupCount ()
|
||||
{
|
||||
throw new Error("Not implemented");
|
||||
return pattern.getRE().getNumSubs();
|
||||
}
|
||||
|
||||
public boolean lookingAt ()
|
||||
{
|
||||
throw new Error("Not implemented");
|
||||
match = pattern.getRE().getMatch(input, 0);
|
||||
if (match != null)
|
||||
{
|
||||
if (match.getStartIndex() == 0)
|
||||
return true;
|
||||
match = null;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -170,7 +231,7 @@ public class Matcher
|
|||
*/
|
||||
public boolean matches ()
|
||||
{
|
||||
throw new Error("Not implemented");
|
||||
return find(0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -183,7 +244,9 @@ public class Matcher
|
|||
|
||||
public Matcher reset ()
|
||||
{
|
||||
throw new Error ("Not implemented");
|
||||
position = 0;
|
||||
match = null;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -191,7 +254,8 @@ public class Matcher
|
|||
*/
|
||||
public Matcher reset (CharSequence input)
|
||||
{
|
||||
throw new Error ("Not implemented");
|
||||
this.input = input;
|
||||
return reset();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -203,7 +267,8 @@ public class Matcher
|
|||
public int start ()
|
||||
throws IllegalStateException
|
||||
{
|
||||
throw new Error("Not implemented");
|
||||
assertMatchOp();
|
||||
return match.getStartIndex();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -217,6 +282,12 @@ public class Matcher
|
|||
public int start (int group)
|
||||
throws IllegalStateException
|
||||
{
|
||||
throw new Error("Not implemented");
|
||||
assertMatchOp();
|
||||
return match.getStartIndex(group);
|
||||
}
|
||||
|
||||
private void assertMatchOp()
|
||||
{
|
||||
if (match == null) throw new IllegalStateException();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/* Pattern.java --
|
||||
Copyright (C) 2002 Free Software Foundation, Inc.
|
||||
/* Pattern.java -- Compiled regular expression ready to be applied.
|
||||
Copyright (C) 2002, 2004 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
|
@ -35,13 +35,19 @@ this exception to your version of the library, but you are not
|
|||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
// Stub class until java.util.regex is implemented.
|
||||
package java.util.regex;
|
||||
|
||||
import gnu.regexp.RE;
|
||||
import gnu.regexp.RESyntax;
|
||||
import gnu.regexp.REException;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
|
||||
|
||||
/**
|
||||
* @author Michael Koch
|
||||
* Compiled regular expression ready to be applied.
|
||||
*
|
||||
* @since 1.4
|
||||
*/
|
||||
public class Pattern implements Serializable
|
||||
|
@ -56,8 +62,10 @@ public class Pattern implements Serializable
|
|||
public static final int UNICODE_CASE = 64;
|
||||
public static final int UNIX_LINES = 1;
|
||||
|
||||
private String regex;
|
||||
private int flags;
|
||||
private final String regex;
|
||||
private final int flags;
|
||||
|
||||
private final RE re;
|
||||
|
||||
private Pattern (String regex)
|
||||
throws PatternSyntaxException
|
||||
|
@ -71,9 +79,48 @@ public class Pattern implements Serializable
|
|||
this.regex = regex;
|
||||
this.flags = flags;
|
||||
|
||||
throw new Error ("Not implemented");
|
||||
int gnuFlags = 0;
|
||||
if ((flags & CASE_INSENSITIVE) != 0)
|
||||
gnuFlags |= RE.REG_ICASE;
|
||||
if ((flags & MULTILINE) != 0)
|
||||
gnuFlags |= RE.REG_MULTILINE;
|
||||
if ((flags & DOTALL) != 0)
|
||||
gnuFlags |= RE.REG_DOT_NEWLINE;
|
||||
// not yet supported:
|
||||
// if ((flags & UNICODE_CASE) != 0) gnuFlags =
|
||||
// if ((flags & CANON_EQ) != 0) gnuFlags =
|
||||
|
||||
// Eventually there will be such a thing as JDK 1_4 syntax
|
||||
RESyntax syntax = RESyntax.RE_SYNTAX_PERL5;
|
||||
if ((flags & UNIX_LINES) != 0)
|
||||
{
|
||||
// Use a syntax set with \n for linefeeds?
|
||||
syntax = new RESyntax(syntax);
|
||||
syntax.setLineSeparator("\n");
|
||||
}
|
||||
|
||||
if ((flags & COMMENTS) != 0)
|
||||
{
|
||||
// Use a syntax with support for comments?
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
this.re = new RE(regex, gnuFlags, syntax);
|
||||
}
|
||||
catch (REException e)
|
||||
{
|
||||
throw new PatternSyntaxException(e.getMessage(),
|
||||
regex, e.getPosition());
|
||||
}
|
||||
}
|
||||
|
||||
// package private accessor method
|
||||
RE getRE()
|
||||
{
|
||||
return re;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param regex The regular expression
|
||||
*
|
||||
|
@ -82,7 +129,7 @@ public class Pattern implements Serializable
|
|||
public static Pattern compile (String regex)
|
||||
throws PatternSyntaxException
|
||||
{
|
||||
throw new Error ("Not implemented");
|
||||
return compile(regex, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -116,7 +163,7 @@ public class Pattern implements Serializable
|
|||
*/
|
||||
public static boolean matches (String regex, CharSequence input)
|
||||
{
|
||||
throw new Error ("Not implemented");
|
||||
return compile(regex).matcher(input).matches();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -124,7 +171,7 @@ public class Pattern implements Serializable
|
|||
*/
|
||||
public Matcher matcher (CharSequence input)
|
||||
{
|
||||
throw new Error ("Not implemented");
|
||||
return new Matcher(this, input);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -132,7 +179,7 @@ public class Pattern implements Serializable
|
|||
*/
|
||||
public String[] split (CharSequence input)
|
||||
{
|
||||
throw new Error ("Not implemented");
|
||||
return split(input, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -141,11 +188,67 @@ public class Pattern implements Serializable
|
|||
*/
|
||||
public String[] split (CharSequence input, int limit)
|
||||
{
|
||||
throw new Error ("Not implemented");
|
||||
Matcher matcher = new Matcher(this, input);
|
||||
ArrayList list = new ArrayList();
|
||||
int empties = 0;
|
||||
int count = 0;
|
||||
int start = 0;
|
||||
int end;
|
||||
boolean matched;
|
||||
|
||||
while (matched = matcher.find() && (limit <= 0 || count < limit - 1))
|
||||
{
|
||||
++count;
|
||||
end = matcher.start();
|
||||
if (start == end)
|
||||
empties++;
|
||||
else
|
||||
{
|
||||
while (empties-- > 0)
|
||||
list.add("");
|
||||
|
||||
String text = input.subSequence(start, end).toString();
|
||||
list.add(text);
|
||||
}
|
||||
start = matcher.end();
|
||||
}
|
||||
|
||||
// We matched nothing.
|
||||
if (!matched && count == 0)
|
||||
return new String[] { input.toString() };
|
||||
|
||||
// Is the last token empty?
|
||||
boolean emptyLast = (start == input.length());
|
||||
|
||||
// Can/Must we add empties or an extra last token at the end?
|
||||
if (list.size() < limit || limit < 0 || (limit == 0 && !emptyLast))
|
||||
{
|
||||
if (limit > list.size())
|
||||
{
|
||||
int max = limit - list.size();
|
||||
empties = (empties > max) ? max : empties;
|
||||
}
|
||||
while (empties-- > 0)
|
||||
list.add("");
|
||||
}
|
||||
|
||||
// last token at end
|
||||
if (limit != 0 || (limit == 0 && !emptyLast))
|
||||
{
|
||||
String t = input.subSequence(start, input.length()).toString();
|
||||
if ("".equals(t) && limit == 0)
|
||||
; // Don't add.
|
||||
else
|
||||
list.add(t);
|
||||
}
|
||||
|
||||
String[] output = new String [list.size()];
|
||||
list.toArray(output);
|
||||
return output;
|
||||
}
|
||||
|
||||
public String pattern ()
|
||||
{
|
||||
throw new Error ("Not implemented");
|
||||
return regex;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue