home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 6 / AACD06.ISO / AACD / Programming / ICU / include / parsepos.h < prev    next >
C/C++ Source or Header  |  1999-11-12  |  5KB  |  178 lines

  1. /*
  2. *******************************************************************************
  3. *                                                                             *
  4. * COPYRIGHT:                                                                  *
  5. *   (C) Copyright Taligent, Inc.,  1997                                       *
  6. *   (C) Copyright International Business Machines Corporation,  1997-1999     *
  7. *   Licensed Material - Program-Property of IBM - All Rights Reserved.        *
  8. *   US Government Users Restricted Rights - Use, duplication, or disclosure   *
  9. *   restricted by GSA ADP Schedule Contract with IBM Corp.                    *
  10. *                                                                             *
  11. *******************************************************************************
  12. *
  13. * File PARSEPOS.H
  14. *
  15. * Modification History:
  16. *
  17. *   Date        Name        Description
  18. *   07/09/97    helena      Converted from java.
  19. *   07/17/98    stephen     Added errorIndex support.
  20. *   05/11/99    stephen     Cleaned up.
  21. *******************************************************************************
  22. */
  23.  
  24. #ifndef PARSEPOS_H
  25. #define PARSEPOS_H
  26.  
  27. #include "utypes.h"
  28.      
  29. /**
  30.  * <code>ParsePosition</code> is a simple class used by <code>Format</code>
  31.  * and its subclasses to keep track of the current position during parsing.
  32.  * The <code>parseObject</code> method in the various <code>Format</code>
  33.  * classes requires a <code>ParsePosition</code> object as an argument.
  34.  *
  35.  * <p> 
  36.  * By design, as you parse through a string with different formats,
  37.  * you can use the same <code>ParsePosition</code>, since the index parameter
  38.  * records the current position.
  39.  *
  40.  * @version     1.3 10/30/97
  41.  * @author      Mark Davis, Helena Shih
  42.  * @see         java.text.Format
  43.  */
  44.  
  45. class U_I18N_API ParsePosition {
  46. public:
  47.     /**
  48.      * Default constructor, the index starts with 0 as default.
  49.      */
  50.     ParsePosition() 
  51.       { this->index = 0; this->errorIndex = -1; }
  52.  
  53.     /**
  54.      * Create a new ParsePosition with the given initial index.
  55.      * @param newIndex the new text offset.
  56.      */
  57.     ParsePosition(UTextOffset newIndex) 
  58.       {    this->index = newIndex; this->errorIndex = -1; } 
  59.     
  60.     /**
  61.      * Copy constructor
  62.      * @param copy the object to be copied from.
  63.      */
  64.     ParsePosition(const ParsePosition& copy) 
  65.       {    this->index = copy.index; this->errorIndex = copy.errorIndex; }
  66.  
  67.     /**
  68.      * Destructor
  69.      */
  70.     ~ParsePosition() {}
  71.  
  72.     /**
  73.      * Assignment operator
  74.      */
  75.     ParsePosition&      operator=(const ParsePosition& copy);
  76.  
  77.     /** 
  78.      * Equality operator.
  79.      * @return TRUE if the two parse positions are equal, FALSE otherwise.
  80.      */
  81.     bool_t              operator==(const ParsePosition& that) const;
  82.  
  83.     /** 
  84.      * Equality operator.
  85.      * @return TRUE if the two parse positions are not equal, FALSE otherwise.
  86.      */
  87.     bool_t              operator!=(const ParsePosition& that) const;
  88.  
  89.     /**
  90.      * Retrieve the current parse position.  On input to a parse method, this
  91.      * is the index of the character at which parsing will begin; on output, it
  92.      * is the index of the character following the last character parsed.
  93.      * @return the current index.
  94.      */
  95.     UTextOffset getIndex(void) const;
  96.  
  97.     /**
  98.      * Set the current parse position.
  99.      * @param index the new index.
  100.      */
  101.     void setIndex(UTextOffset index);
  102.  
  103.     /**
  104.      * Set the index at which a parse error occurred.  Formatters
  105.      * should set this before returning an error code from their
  106.      * parseObject method.  The default value is -1 if this is not
  107.      * set.  */
  108.     void setErrorIndex(UTextOffset ei);
  109.  
  110.     /**
  111.      * Retrieve the index at which an error occurred, or -1 if the
  112.      * error index has not been set.  */
  113.     UTextOffset getErrorIndex(void) const;
  114.  
  115. private:
  116.     /**
  117.      * Input: the place you start parsing.
  118.      * <br>Output: position where the parse stopped.
  119.      * This is designed to be used serially,
  120.      * with each call setting index up for the next one.
  121.      */
  122.     UTextOffset index;
  123.     
  124.     /**
  125.      * The index at which a parse error occurred.
  126.      */
  127.     UTextOffset errorIndex;
  128. };
  129.  
  130. inline ParsePosition&
  131. ParsePosition::operator=(const ParsePosition& copy)
  132. {
  133.   index = copy.index;
  134.   errorIndex = copy.errorIndex;
  135.   return *this;
  136. }
  137.  
  138. inline bool_t
  139. ParsePosition::operator==(const ParsePosition& copy) const
  140. {
  141.   if(index != copy.index || errorIndex != copy.errorIndex) 
  142.   return FALSE;
  143.   else
  144.   return TRUE;
  145. }
  146.  
  147. inline bool_t
  148. ParsePosition::operator!=(const ParsePosition& copy) const
  149. {
  150.   return !operator==(copy);
  151. }
  152.  
  153. inline UTextOffset
  154. ParsePosition::getIndex() const
  155. {
  156.   return index;
  157. }
  158.  
  159. inline void
  160. ParsePosition::setIndex(UTextOffset idx)
  161. {
  162.   this->index = idx;
  163. }
  164.  
  165. inline UTextOffset
  166. ParsePosition::getErrorIndex() const
  167. {
  168.   return errorIndex;
  169. }
  170.  
  171. inline void
  172. ParsePosition::setErrorIndex(UTextOffset ei)
  173. {
  174.   this->errorIndex = ei;
  175. }
  176.  
  177. #endif
  178.