~ubuntu-branches/ubuntu/precise/classpath/precise

« back to all changes in this revision

Viewing changes to java/util/regex/Matcher.java

  • Committer: Bazaar Package Importer
  • Author(s): Michael Koch
  • Date: 2006-05-27 16:11:15 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20060527161115-h6e39eposdt5snb6
Tags: 2:0.91-3
* Install header files to /usr/include/classpath.
* debian/control: classpath: Conflict with jamvm < 1.4.3 and
  cacao < 0.96 (Closes: #368172).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* Matcher.java -- Instance of a regular expression applied to a char sequence.
2
 
   Copyright (C) 2002, 2004 Free Software Foundation, Inc.
 
2
   Copyright (C) 2002, 2004, 2006 Free Software Foundation, Inc.
3
3
 
4
4
This file is part of GNU Classpath.
5
5
 
38
38
 
39
39
package java.util.regex;
40
40
 
 
41
import gnu.regexp.RE;
41
42
import gnu.regexp.REMatch;
 
43
import gnu.regexp.CharIndexed;
42
44
 
43
45
/**
44
46
 * Instance of a regular expression applied to a char sequence.
45
47
 *
46
48
 * @since 1.4
47
49
 */
48
 
public final class Matcher
 
50
public final class Matcher implements MatchResult
49
51
{
50
52
  private Pattern pattern;
51
53
  private CharSequence input;
 
54
  // We use CharIndexed as an input object to the getMatch method in order
 
55
  // that /\G/ (the end of the previous match) may work.  The information
 
56
  // of the previous match is stored in the CharIndexed object.
 
57
  private CharIndexed inputCharIndexed;
52
58
  private int position;
53
59
  private int appendPosition;
54
60
  private REMatch match;
57
63
  {
58
64
    this.pattern = pattern;
59
65
    this.input = input;
 
66
    this.inputCharIndexed = RE.makeCharIndexed(input, 0);
60
67
  }
61
68
  
62
69
  /**
74
81
    assertMatchOp();
75
82
    sb.append(input.subSequence(appendPosition,
76
83
                                match.getStartIndex()).toString());
77
 
    sb.append(match.substituteInto(replacement));
 
84
    sb.append(RE.getReplacement(replacement, match,
 
85
        RE.REG_REPLACE_USE_BACKSLASHESCAPE));
78
86
    appendPosition = match.getEndIndex();
79
87
    return this;
80
88
  }
117
125
  public boolean find ()
118
126
  {
119
127
    boolean first = (match == null);
120
 
    match = pattern.getRE().getMatch(input, position);
 
128
    match = pattern.getRE().getMatch(inputCharIndexed, position);
121
129
    if (match != null)
122
130
      {
123
131
        int endIndex = match.getEndIndex();
148
156
   */
149
157
  public boolean find (int start)
150
158
  {
151
 
    match = pattern.getRE().getMatch(input, start);
 
159
    match = pattern.getRE().getMatch(inputCharIndexed, start);
152
160
    if (match != null)
153
161
      {
154
162
        position = match.getEndIndex();
189
197
  {
190
198
    reset();
191
199
    // Semantics might not quite match
192
 
    return pattern.getRE().substitute(input, replacement, position);
 
200
    return pattern.getRE().substitute(input, replacement, position,
 
201
        RE.REG_REPLACE_USE_BACKSLASHESCAPE);
193
202
  }
194
203
 
195
204
  /**
198
207
  public String replaceAll (String replacement)
199
208
  {
200
209
    reset();
201
 
    return pattern.getRE().substituteAll(input, replacement, position);
 
210
    return pattern.getRE().substituteAll(input, replacement, position,
 
211
        RE.REG_REPLACE_USE_BACKSLASHESCAPE);
202
212
  }
203
213
  
204
214
  public int groupCount ()
208
218
 
209
219
  public boolean lookingAt ()
210
220
  {
211
 
    match = pattern.getRE().getMatch(input, 0);
 
221
    match = pattern.getRE().getMatch(inputCharIndexed, 0);
212
222
    if (match != null)
213
223
      {
214
224
        if (match.getStartIndex() == 0)
233
243
   */
234
244
  public boolean matches ()
235
245
  {
236
 
    if (lookingAt())
 
246
    match = pattern.getRE().getMatch(inputCharIndexed, 0, RE.REG_TRY_ENTIRE_MATCH);
 
247
    if (match != null)
237
248
      {
238
 
        if (position == input.length())
239
 
          return true;
 
249
        if (match.getStartIndex() == 0)
 
250
          {
 
251
            position = match.getEndIndex();
 
252
            if (position == input.length())
 
253
                return true;
 
254
          }
240
255
        match = null;
241
256
      }
242
257
    return false;