001: /*=============================================================================
002: * Copyright Texas Instruments 2003-2004. All Rights Reserved.
003: *
004: * This program is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 2 of the License, or (at your option) any later version.
008: *
009: * This program is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: *
018: * $ProjectHeader: OSCRIPT 0.155 Fri, 20 Dec 2002 18:34:22 -0800 rclark $
019: */
020:
021: package oscript.data;
022:
023: import oscript.exceptions.*;
024: import oscript.*;
025:
026: /**
027: * The result of executing a pattern against a string. This object acts
028: * both as an object and as an array with the following properties and
029: * indicies:
030: * <div id="regtable"><table>
031: * <tr>
032: * <th>Property/Index</th>
033: * <th>Description</th>
034: * </tr>
035: * <tr>
036: * <td>property: <code>index</code></td>
037: * <td>the index of the matched string</td>
038: * </tr>
039: * <tr>
040: * <td>property: <code>input</code></td>
041: * <td>the original string</td>
042: * </tr>
043: * <tr>
044: * <td>index: <code>0</code></td>
045: * <td>the last matched characters</td>
046: * </tr>
047: * <tr>
048: * <td>index: <code>1</code> thru <code>n</code></td>
049: * <td>The parenthesized substring matches, if any</td>
050: * </tr>
051: * </table></div>
052: * Note 1: this API is modeled after the JavaScript RegExp API, for the
053: * benefit of users already familiar with JavaScript.
054: * <p>
055: * Note 2: the properties (<code>index</code>, etc) work by bean-access,
056: * so they are implemented by getter methods (since they are read-only)
057: *
058: * @author Rob Clark (rob@ti.com)
059: */
060: public abstract class RegExpResult extends OObject {
061: public final static Value TYPE = BuiltinType
062: .makeBuiltinType("oscript.data.RegExpResult");
063: public final static String PARENT_TYPE_NAME = "oscript.data.OObject";
064: public final static String TYPE_NAME = "RegExpResult";
065: public final static String[] MEMBER_NAMES = new String[] {
066: "getType", "castToJavaObject", "castToString",
067: "bopInstanceOf", "bopEquals", "bopNotEquals", "getMember",
068: "elementAt", "length", "getIndex", "getInput", "index",
069: "input"
070: // XXX
071: };
072:
073: /**
074: * The input string, whose match results are contained in this object
075: */
076: private Value input;
077:
078: /*=======================================================================*/
079: /**
080: * Class Constructor.
081: *
082: * @param input the string to match the regular expression against
083: */
084: protected RegExpResult(Value input) {
085: super ();
086: this .input = input;
087: }
088:
089: /*=======================================================================*/
090: /**
091: * Get the type of this object. The returned type doesn't have to take
092: * into account the possibility of a script type extending a built-in
093: * type, since that is handled by {@link #getType}.
094: *
095: * @return the object's type
096: */
097: protected Value getTypeImpl() {
098: return TYPE;
099: }
100:
101: /*=======================================================================*/
102: /**
103: * Get the original input string.
104: */
105: public Value getInput() {
106: return input;
107: }
108:
109: /*=======================================================================*/
110: /**
111: * The index of the match in the string, or <code>-1</code> if no match.
112: */
113: public abstract Value getIndex();
114:
115: /*=======================================================================*/
116: /**
117: * For types that implement <code>elementAt</code>, this returns the
118: * number of elements.
119: *
120: * @return an integer length
121: * @throws PackagedScriptObjectException(NoSuchMemberException)
122: * @see #elementAt
123: * @see #elementsAt
124: */
125: public abstract int length() throws PackagedScriptObjectException;
126:
127: /*=======================================================================*/
128: /**
129: * Get the specified index of this object, if this object is an array. If
130: * needed, the array is grown to the appropriate size.
131: *
132: * @param idx the index to get
133: * @return a reference to the member
134: * @throws PackagedScriptObjectException(NoSuchMemberException)
135: * @see #length
136: * @see #elementsAt
137: */
138: public abstract Value elementAt(Value idx)
139: throws PackagedScriptObjectException;
140: }
141:
142: /*
143: * Local Variables:
144: * tab-width: 2
145: * indent-tabs-mode: nil
146: * mode: java
147: * c-indentation-style: java
148: * c-basic-offset: 2
149: * eval: (c-set-offset 'substatement-open '0)
150: * eval: (c-set-offset 'case-label '+)
151: * eval: (c-set-offset 'inclass '+)
152: * eval: (c-set-offset 'inline-open '0)
153: * End:
154: */
|