home *** CD-ROM | disk | FTP | other *** search
/ Java 1.2 How-To / JavaHowTo.iso / 3rdParty / jbuilder / unsupported / JDK1.2beta3 / SOURCE / SRC.ZIP / java / text / ParsePosition.java < prev    next >
Encoding:
Java Source  |  1998-03-20  |  3.3 KB  |  102 lines

  1. /*
  2.  * @(#)ParsePosition.java    1.11 98/03/18
  3.  *
  4.  * (C) Copyright Taligent, Inc. 1996 - All Rights Reserved
  5.  * (C) Copyright IBM Corp. 1996 - All Rights Reserved
  6.  *
  7.  * Portions copyright (c) 1996-1998 Sun Microsystems, Inc. All Rights Reserved.
  8.  *
  9.  *   The original version of this source code and documentation is copyrighted
  10.  * and owned by Taligent, Inc., a wholly-owned subsidiary of IBM. These
  11.  * materials are provided under terms of a License Agreement between Taligent
  12.  * and Sun. This technology is protected by multiple US and International
  13.  * patents. This notice and attribution to Taligent may not be removed.
  14.  *   Taligent is a registered trademark of Taligent, Inc.
  15.  *
  16.  * Permission to use, copy, modify, and distribute this software
  17.  * and its documentation for NON-COMMERCIAL purposes and without
  18.  * fee is hereby granted provided that this copyright notice
  19.  * appears in all copies. Please refer to the file "copyright.html"
  20.  * for further important copyright and licensing information.
  21.  *
  22.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
  23.  * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
  24.  * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  25.  * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
  26.  * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
  27.  * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
  28.  *
  29.  */
  30.  
  31. package java.text;
  32.  
  33.  
  34. /**
  35.  * <code>ParsePosition</code> is a simple class used by <code>Format</code>
  36.  * and its subclasses to keep track of the current position during parsing.
  37.  * The <code>parseObject</code> method in the various <code>Format</code>
  38.  * classes requires a <code>ParsePosition</code> object as an argument.
  39.  *
  40.  * <p>
  41.  * By design, as you parse through a string with different formats,
  42.  * you can use the same <code>ParsePosition</code>, since the index parameter
  43.  * records the current position.
  44.  *
  45.  * @version     1.11 03/18/98
  46.  * @author      Mark Davis
  47.  * @see         java.text.Format
  48.  */
  49.  
  50. public class ParsePosition {
  51.  
  52.     /**
  53.      * Input: the place you start parsing.
  54.      * <br>Output: position where the parse stopped.
  55.      * This is designed to be used serially,
  56.      * with each call setting index up for the next one.
  57.      */
  58.     int index = 0;
  59.     int errorIndex = -1;
  60.  
  61.     /**
  62.      * Retrieve the current parse position.  On input to a parse method, this
  63.      * is the index of the character at which parsing will begin; on output, it
  64.      * is the index of the character following the last character parsed.
  65.      */
  66.     public int getIndex() {
  67.         return index;
  68.     }
  69.  
  70.     /**
  71.      * Set the current parse position.
  72.      */
  73.     public void setIndex(int index) {
  74.         this.index = index;
  75.     }
  76.  
  77.     /**
  78.      * Create a new ParsePosition with the given initial index.
  79.      */
  80.     public ParsePosition(int index) {
  81.         this.index = index;
  82.     }
  83.     /**
  84.      * Set the index at which a parse error occurred.  Formatters
  85.      * should set this before returning an error code from their
  86.      * parseObject method.  The default value is -1 if this is not set.
  87.      */
  88.     public void setErrorIndex(int ei)
  89.     {
  90.         errorIndex = ei;
  91.     }
  92.  
  93.     /**
  94.      * Retrieve the index at which an error occurred, or -1 if the
  95.      * error index has not been set.
  96.      */
  97.     public int getErrorIndex()
  98.     {
  99.         return errorIndex;
  100.     }
  101. }
  102.