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

  1. /*
  2. *******************************************************************************
  3. *                                                                             *
  4. * COPYRIGHT:                                                                  *
  5. *   (C) Copyright International Business Machines Corporation, 1998-1999      *
  6. *   Licensed Material - Program-Property of IBM - All Rights Reserved.        *
  7. *   US Government Users Restricted Rights - Use, duplication, or disclosure   *
  8. *   restricted by GSA ADP Schedule Contract with IBM Corp.                    *
  9. *                                                                             *
  10. *******************************************************************************
  11. *
  12. * File unistr.h
  13. *
  14. * Modification History:
  15. *
  16. *   Date        Name        Description
  17. *   09/25/98    stephen     Creation.
  18. *   11/11/98    stephen     Changed per 11/9 code review.
  19. *   04/20/99    stephen     Overhauled per 4/16 code review.
  20. *******************************************************************************
  21. */
  22.  
  23. #ifndef UNISTR_H
  24. #define UNISTR_H
  25.  
  26. #include <limits.h>
  27.  
  28. #include "utypes.h"
  29. #include "unicode.h"
  30. #include "ucnv.h"
  31.  
  32. // Size of stack buffer for small strings
  33. #define US_STACKBUF_SIZE 10
  34.  
  35. class Locale;
  36. class UCharReference;
  37.  
  38. /**
  39.  * UnicodeString is a concrete implementation of the abstract class 
  40.  * UnicodeText.  UnicodeString performs codeset conversion from char*
  41.  * data based on the type of data specified.
  42.  */
  43. class U_COMMON_API UnicodeString
  44. {
  45. public:
  46.  
  47.   //========================================
  48.   // Read-only operations
  49.   //========================================
  50.   
  51.   /* Comparison - bitwise only - for international comparison use collation */
  52.   
  53.   /**
  54.    * Equality operator. Performs only bitwise comparison.
  55.    * @param text The UnicodeString to compare to this one.
  56.    * @return TRUE if <TT>text</TT> contains the same characters as this one,
  57.    * FALSE otherwise.
  58.    */
  59.   inline bool_t operator== (const UnicodeString& text) const;
  60.   
  61.   /**
  62.    * Inequality operator. Performs only bitwise comparison.
  63.    * @param text The UnicodeString to compare to this one.
  64.    * @return FALSE if <TT>text</TT> contains the same characters as this one,
  65.    * TRUE otherwise.
  66.    */
  67.   inline bool_t operator!= (const UnicodeString& text) const;
  68.  
  69.   /**
  70.    * Greater than operator. Performs only bitwise comparison.
  71.    * @param text The UnicodeString to compare to this one.
  72.    * @return TRUE if the characters in <TT>text</TT> are bitwise
  73.    * greater than the characters in this, FALSE otherwise
  74.    */
  75.   inline bool_t operator> (const UnicodeString& text) const;
  76.  
  77.   /**
  78.    * Less than operator. Performs only bitwise comparison.
  79.    * @param text The UnicodeString to compare to this one.
  80.    * @return TRUE if the characters in <TT>text</TT> are bitwise
  81.    * less than the characters in this, FALSE otherwise
  82.    */
  83.   inline bool_t operator< (const UnicodeString& text) const;
  84.  
  85.   /**
  86.    * Greater than or equal operator. Performs only bitwise comparison.
  87.    * @param text The UnicodeString to compare to this one.
  88.    * @return TRUE if the characters in <TT>text</TT> are bitwise
  89.    * greater than or equal to the characters in this, FALSE otherwise
  90.    */
  91.   inline bool_t operator>= (const UnicodeString& text) const;
  92.  
  93.   /**
  94.    * Less than or equal operator. Performs only bitwise comparison.
  95.    * @param text The UnicodeString to compare to this one.
  96.    * @return TRUE if the characters in <TT>text</TT> are bitwise
  97.    * less than or equal to the characters in this, FALSE otherwise
  98.    */
  99.   inline bool_t operator<= (const UnicodeString& text) const;
  100.  
  101.   /**
  102.    * Compare the characters bitwise in this UnicodeString to
  103.    * the characters in <TT>text</TT>.
  104.    * @param text The UnicodeString to compare to this one.
  105.    * @return The result of bitwise character comparison: 0 if <TT>text</TT>
  106.    * contains the same characters as this, -1 if the characters in 
  107.    * <TT>text</TT> are bitwise less than the characters in this, +1 if the
  108.    * characters in <TT>text</TT> are bitwise greater than the characters 
  109.    * in this.
  110.    */
  111.   inline int8_t compare(const UnicodeString& text) const;
  112.  
  113.   /**
  114.    * Compare the characters bitwise in the range 
  115.    * [<TT>start</TT>, <TT>start + length</TT>) with the characters 
  116.    * in <TT>srcText</TT>
  117.    * @param start the offset at which the compare operation begins
  118.    * @param length the number of characters of text to compare.
  119.    * @param srcText the text to be compared
  120.    * @return The result of bitwise character comparison: 0 if <TT>text</TT>
  121.    * contains the same characters as this, -1 if the characters in 
  122.    * <TT>text</TT> are bitwise less than the characters in this, +1 if the
  123.    * characters in <TT>text</TT> are bitwise greater than the characters 
  124.    * in this.
  125.    */
  126.   inline int8_t compare(UTextOffset start,
  127.          int32_t length,
  128.          const UnicodeString& srcText) const;
  129.  
  130.   /**
  131.    * Compare the characters bitwise in the range 
  132.    * [<TT>start</TT>, <TT>start + length</TT>) with the characters 
  133.    * in <TT>srcText</TT> in the range 
  134.    * [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>).  
  135.    * @param start the offset at which the compare operation begins
  136.    * @param length the number of characters in this to compare.
  137.    * @param srcText the text to be compared
  138.    * @param srcStart the offset into <TT>srcText</TT> to start comparison
  139.    * @param srcLength the number of characters in <TT>src</TT> to compare
  140.    * @return The result of bitwise character comparison: 0 if <TT>text</TT>
  141.    * contains the same characters as this, -1 if the characters in 
  142.    * <TT>text</TT> are bitwise less than the characters in this, +1 if the
  143.    * characters in <TT>text</TT> are bitwise greater than the characters 
  144.    * in this.
  145.    */
  146.    inline int8_t compare(UTextOffset start,
  147.          int32_t length,
  148.          const UnicodeString& srcText,
  149.          UTextOffset srcStart,
  150.          int32_t srcLength) const;
  151.  
  152.   /**
  153.    * Compare the characters bitwise in this UnicodeString with the first 
  154.    * <TT>srcLength</TT> characters in <TT>srcChars</TT>.
  155.    * @param srcChars The characters to compare to this UnicodeString.
  156.    * @param srcLength the number of characters in <TT>srcChars</TT> to compare
  157.    * @return The result of bitwise character comparison: 0 if <TT>text</TT>
  158.    * contains the same characters as this, -1 if the characters in 
  159.    * <TT>text</TT> are bitwise less than the characters in this, +1 if the
  160.    * characters in <TT>text</TT> are bitwise greater than the characters 
  161.    * in this.
  162.    */
  163.   inline int8_t compare(const UChar *srcChars,
  164.          int32_t srcLength) const;
  165.  
  166.   /**
  167.    * Compare the characters bitwise in the range 
  168.    * [<TT>start</TT>, <TT>start + length</TT>) with the first 
  169.    * <TT>length</TT> characters in <TT>srcChars</TT>
  170.    * @param start the offset at which the compare operation begins
  171.    * @param length the number of characters to compare.
  172.    * @param srcChars the characters to be compared
  173.    * @return The result of bitwise character comparison: 0 if <TT>text</TT>
  174.    * contains the same characters as this, -1 if the characters in 
  175.    * <TT>text</TT> are bitwise less than the characters in this, +1 if the
  176.    * characters in <TT>text</TT> are bitwise greater than the characters 
  177.    * in this.
  178.    */
  179.   inline int8_t compare(UTextOffset start,
  180.          int32_t length,
  181.          const UChar *srcChars) const;
  182.  
  183.   /**
  184.    * Compare the characters bitwise in the range 
  185.    * [<TT>start</TT>, <TT>start + length</TT>) with the characters 
  186.    * in <TT>srcChars</TT> in the range 
  187.    * [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>).  
  188.    * @param start the offset at which the compare operation begins
  189.    * @param length the number of characters in this to compare
  190.    * @param srcChars the characters to be compared
  191.    * @param srcStart the offset into <TT>srcChars</TT> to start comparison
  192.    * @param srcLength the number of characters in <TT>srcChars</TT> to compare
  193.    * @return The result of bitwise character comparison: 0 if <TT>text</TT>
  194.    * contains the same characters as this, -1 if the characters in 
  195.    * <TT>text</TT> are bitwise less than the characters in this, +1 if the
  196.    * characters in <TT>text</TT> are bitwise greater than the characters 
  197.    * in this.
  198.    */
  199.   inline int8_t compare(UTextOffset start,
  200.          int32_t length,
  201.          const UChar *srcChars,
  202.          UTextOffset srcStart,
  203.          int32_t srcLength) const;
  204.  
  205.   /**
  206.    * Compare the characters bitwise in the range 
  207.    * [<TT>start</TT>, <TT>limit</TT>) with the characters 
  208.    * in <TT>srcText</TT> in the range 
  209.    * [<TT>srcStart</TT>, <TT>srcLimit</TT>).  
  210.    * @param start the offset at which the compare operation begins
  211.    * @param limit the offset immediately following the compare operation
  212.    * @param srcText the text to be compared
  213.    * @param srcStart the offset into <TT>srcText</TT> to start comparison
  214.    * @param srcLimit the offset into <TT>srcText</TT> to limit comparison
  215.    * @return The result of bitwise character comparison: 0 if <TT>text</TT>
  216.    * contains the same characters as this, -1 if the characters in 
  217.    * <TT>text</TT> are bitwise less than the characters in this, +1 if the
  218.    * characters in <TT>text</TT> are bitwise greater than the characters 
  219.    * in this.
  220.    */
  221.   inline int8_t compareBetween(UTextOffset start,
  222.             UTextOffset limit,
  223.             const UnicodeString& srcText,
  224.             UTextOffset srcStart,
  225.             UTextOffset srcLimit) const;
  226.  
  227.   /**
  228.    * Determine if this starts with the characters in <TT>text</TT>
  229.    * @param text The text to match.
  230.    * @return TRUE if this starts with the characters in <TT>text</TT>, 
  231.    * FALSE otherwise
  232.    */
  233.   inline bool_t startsWith(const UnicodeString& text) const;
  234.  
  235.   /**
  236.    * Determine if this starts with the characters in <TT>srcText</TT> 
  237.    * in the range [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>).   
  238.    * @param srcText The text to match.
  239.    * @param srcStart the offset into <TT>srcText</TT> to start matching
  240.    * @param srcLength the number of characters in <TT>srcText</TT> to match
  241.    * @return TRUE if this starts with the characters in <TT>text</TT>, 
  242.    * FALSE otherwise
  243.    */
  244.   inline bool_t startsWith(const UnicodeString& srcText,
  245.             UTextOffset srcStart,
  246.             int32_t srcLength) const;
  247.   
  248.   /**
  249.    * Determine if this starts with the characters in <TT>srcChars</TT>
  250.    * @param srcChars The characters to match.
  251.    * @param srcLength the number of characters in <TT>srcChars</TT>
  252.    * @return TRUE if this starts with the characters in <TT>srcChars</TT>, 
  253.    * FALSE otherwise
  254.    */
  255.   inline bool_t startsWith(const UChar *srcChars,
  256.             int32_t srcLength) const;
  257.  
  258.   /**
  259.    * Determine if this ends with the characters in <TT>srcChars</TT> 
  260.    * in the range  [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>).   
  261.    * @param srcChars The characters to match.
  262.    * @param srcStart the offset into <TT>srcText</TT> to start matching
  263.    * @param srcLength the number of characters in <TT>srcChars</TT> to match
  264.    * @return TRUE if this ends with the characters in <TT>srcChars</TT>, 
  265.    FALSE otherwise
  266.   */
  267.   inline bool_t startsWith(const UChar *srcChars,
  268.             UTextOffset srcStart,
  269.             int32_t srcLength) const;
  270.  
  271.   /**
  272.    * Determine if this ends with the characters in <TT>text</TT>
  273.    * @param text The text to match.
  274.    * @return TRUE if this ends with the characters in <TT>text</TT>, 
  275.    * FALSE otherwise
  276.    */
  277.   inline bool_t endsWith(const UnicodeString& text) const;
  278.  
  279.   /**
  280.    * Determine if this ends with the characters in <TT>srcText</TT> 
  281.    * in the range [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>).   
  282.    * @param srcText The text to match.
  283.    * @param srcStart the offset into <TT>srcText</TT> to start matching
  284.    * @param srcLength the number of characters in <TT>srcText</TT> to match
  285.    * @return TRUE if this ends with the characters in <TT>text</TT>, 
  286.    * FALSE otherwise
  287.    */
  288.   inline bool_t endsWith(const UnicodeString& srcText,
  289.           UTextOffset srcStart,
  290.           int32_t srcLength) const;
  291.  
  292.   /**
  293.    * Determine if this ends with the characters in <TT>srcChars</TT>
  294.    * @param srcChars The characters to match.
  295.    * @param srcLength the number of characters in <TT>srcChars</TT>
  296.    * @return TRUE if this ends with the characters in <TT>srcChars</TT>, 
  297.    * FALSE otherwise
  298.    */
  299.   inline bool_t endsWith(const UChar *srcChars,
  300.           int32_t srcLength) const;
  301.  
  302.   /**
  303.    * Determine if this ends with the characters in <TT>srcChars</TT> 
  304.    * in the range  [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>).   
  305.    * @param srcChars The characters to match.
  306.    * @param srcStart the offset into <TT>srcText</TT> to start matching
  307.    * @param srcLength the number of characters in <TT>srcChars</TT> to match
  308.    * @return TRUE if this ends with the characters in <TT>srcChars</TT>, 
  309.    * FALSE otherwise
  310.    */
  311.   inline bool_t endsWith(const UChar *srcChars,
  312.           UTextOffset srcStart,
  313.           int32_t srcLength) const;
  314.  
  315.  
  316.   /* Searching - bitwise only */
  317.  
  318.   /**
  319.    * Locate in this the first occurrence of the characters in <TT>text</TT>,
  320.    * using bitwise comparison.
  321.    * @param text The text to search for.
  322.    * @return The offset into this of the start of <TT>text</TT>, 
  323.    * or -1 if not found.
  324.    */
  325.   inline UTextOffset indexOf(const UnicodeString& text) const;
  326.  
  327.   /**
  328.    * Locate in this the first occurrence of the characters in <TT>text</TT>
  329.    * starting at offset <TT>start</TT>, using bitwise comparison.
  330.    * @param text The text to search for.
  331.    * @param start The offset at which searching will start.
  332.    * @return The offset into this of the start of <TT>text</TT>, 
  333.    * or -1 if not found.
  334.    */
  335.   inline UTextOffset indexOf(const UnicodeString& text,
  336.               UTextOffset start) const;
  337.  
  338.   /**
  339.    * Locate in this the first occurrence in the range
  340.    * [<TT>start</TT>, <TT>start + length</TT>) of the characters 
  341.    * in <TT>text</TT>, using bitwise comparison.
  342.    * @param text The text to search for.
  343.    * @param start The offset at which searching will start.
  344.    * @param length The number of characters to search
  345.    * @return The offset into this of the start of <TT>text</TT>, 
  346.    * or -1 if not found.
  347.    */
  348.   inline UTextOffset indexOf(const UnicodeString& text,
  349.               UTextOffset start,
  350.               int32_t length) const;
  351.  
  352.   /**
  353.    * Locate in this the first occurrence in the range
  354.    * [<TT>start</TT>, <TT>start + length</TT>) of the characters
  355.    *  in <TT>srcText</TT> in the range 
  356.    * [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>), 
  357.    * using bitwise comparison.   
  358.    * @param text The text to search for.
  359.    * @param srcStart the offset into <TT>srcText</TT> at which
  360.    * to start matching
  361.    * @param srcLength the number of characters in <TT>srcText</TT> to match
  362.    * @param start the offset into this at which to start matching
  363.    * @param length the number of characters in this to search
  364.    * @return The offset into this of the start of <TT>text</TT>, 
  365.    * or -1 if not found.
  366.    */
  367.   inline UTextOffset indexOf(const UnicodeString& srcText,
  368.               UTextOffset srcStart,
  369.               int32_t srcLength,
  370.               UTextOffset start,
  371.               int32_t length) const;
  372.  
  373.   /**
  374.    * Locate in this the first occurrence of the characters in
  375.    * <TT>srcChars</TT> 
  376.    * starting at offset <TT>start</TT>, using bitwise comparison. 
  377.    * @param srcChars The text to search for.
  378.    * @param srcLength the number of characters in <TT>srcChars</TT> to match
  379.    * @param start the offset into this at which to start matching
  380.    * @return The offset into this of the start of <TT>text</TT>, 
  381.    * or -1 if not found.
  382.    */
  383.   inline UTextOffset indexOf(const UChar *srcChars,
  384.               int32_t srcLength,
  385.               UTextOffset start) const;
  386.  
  387.   /**
  388.    * Locate in this the first occurrence in the range
  389.    * [<TT>start</TT>, <TT>start + length</TT>) of the characters 
  390.    * in <TT>srcChars</TT>, using bitwise comparison.
  391.    * @param text The text to search for.
  392.    * @param srcLength the number of characters in <TT>srcChars</TT>
  393.    * @param start The offset at which searching will start.
  394.    * @param length The number of characters to search
  395.    * @return The offset into this of the start of <TT>srcChars</TT>, 
  396.    * or -1 if not found.
  397.    */
  398.   inline UTextOffset indexOf(const UChar *srcChars,
  399.               int32_t srcLength,
  400.               UTextOffset start,
  401.               int32_t length) const;
  402.  
  403.   /**
  404.    * Locate in this the first occurrence in the range 
  405.    * [<TT>start</TT>, <TT>start + length</TT>) of the characters 
  406.    * in <TT>srcChars</TT> in the range 
  407.    * [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>), 
  408.    * using bitwise comparison.   
  409.    * @param srcChars The text to search for.
  410.    * @param srcStart the offset into <TT>srcChars</TT> at which 
  411.    * to start matching
  412.    * @param srcLength the number of characters in <TT>srcChars</TT> to match
  413.    * @param start the offset into this at which to start matching
  414.    * @param length the number of characters in this to search
  415.    * @return The offset into this of the start of <TT>text</TT>, 
  416.    * or -1 if not found.
  417.    */
  418.   inline UTextOffset indexOf(const UChar *srcChars,
  419.               UTextOffset srcStart,
  420.               int32_t srcLength,
  421.               UTextOffset start,
  422.               int32_t length) const;
  423.  
  424.   /**
  425.    * Locate in this the first occurrence of the character <TT>c</TT>, 
  426.    * using bitwise comparison.
  427.    * @param c The character to search for.
  428.    * @return The offset into this of <TT>c</TT>, or -1 if not found.
  429.    */
  430.   inline UTextOffset indexOf(UChar c) const;
  431.  
  432.   /**
  433.    * Locate in this the first occurrence of the character <TT>c</TT>
  434.    * starting at offset <TT>start</TT>, using bitwise comparison.
  435.    * @param c The character to search for.
  436.    * @param start The offset at which searching will start.
  437.    * @return The offset into this of <TT>c</TT>, or -1 if not found.
  438.    */
  439.   inline UTextOffset indexOf(UChar c,
  440.               UTextOffset start) const;
  441.  
  442.   /**
  443.    * Locate in this the first occurrence of the character <TT>c</TT> 
  444.    * in the range [<TT>start</TT>, <TT>start + length</TT>), 
  445.    * using bitwise comparison.   
  446.    * @param c The character to search for.
  447.    * @param start the offset into this at which to start matching
  448.    * @param length the number of characters in this to search
  449.    * @return The offset into this of <TT>c</TT>, or -1 if not found.
  450.    */
  451.   inline UTextOffset indexOf(UChar c,
  452.               UTextOffset start,
  453.               int32_t length) const;
  454.  
  455.   /**
  456.    * Locate in this the last occurrence of the characters in <TT>text</TT>, 
  457.    * using bitwise comparison.
  458.    * @param text The text to search for.
  459.    * @return The offset into this of the start of <TT>text</TT>, 
  460.    * or -1 if not found.
  461.    */
  462.   inline UTextOffset lastIndexOf(const UnicodeString& text) const;
  463.  
  464.   /**
  465.    * Locate in this the last occurrence of the characters in <TT>text</TT>
  466.    * starting at offset <TT>start</TT>, using bitwise comparison.
  467.    * @param text The text to search for.
  468.    * @param start The offset at which searching will start.
  469.    * @return The offset into this of the start of <TT>text</TT>, 
  470.    * or -1 if not found.
  471.    */
  472.   inline UTextOffset lastIndexOf(const UnicodeString& text,
  473.               UTextOffset start) const;
  474.  
  475.   /**
  476.    * Locate in this the last occurrence in the range 
  477.    * [<TT>start</TT>, <TT>start + length</TT>) of the characters
  478.    * in <TT>text</TT>, using bitwise comparison.
  479.    * @param text The text to search for.
  480.    * @param start The offset at which searching will start.
  481.    * @param length The number of characters to search
  482.    * @return The offset into this of the start of <TT>text</TT>, 
  483.    * or -1 if not found.
  484.    */
  485.   inline UTextOffset lastIndexOf(const UnicodeString& text,
  486.               UTextOffset start,
  487.               int32_t length) const;
  488.  
  489.   /**
  490.    * Locate in this the last occurrence in the range 
  491.    * [<TT>start</TT>, <TT>start + length</TT>) of the characters 
  492.    * in <TT>srcText</TT> in the range 
  493.    * [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>), 
  494.    * using bitwise comparison.   
  495.    * @param text The text to search for.
  496.    * @param srcStart the offset into <TT>srcText</TT> at which 
  497.    * to start matching
  498.    * @param srcLength the number of characters in <TT>srcText</TT> to match
  499.    * @param start the offset into this at which to start matching
  500.    * @param length the number of characters in this to search
  501.    * @return The offset into this of the start of <TT>text</TT>, 
  502.    * or -1 if not found.
  503.    */
  504.   inline UTextOffset lastIndexOf(const UnicodeString& srcText,
  505.               UTextOffset srcStart,
  506.               int32_t srcLength,
  507.               UTextOffset start,
  508.               int32_t length) const;
  509.  
  510.   /**
  511.    * Locate in this the last occurrence of the characters in <TT>srcChars</TT> 
  512.    * starting at offset <TT>start</TT>, using bitwise comparison. 
  513.    * @param srcChars The text to search for.
  514.    * @param srcLength the number of characters in <TT>srcChars</TT> to match
  515.    * @param start the offset into this at which to start matching
  516.    * @return The offset into this of the start of <TT>text</TT>, 
  517.    * or -1 if not found.
  518.    */
  519.   inline UTextOffset lastIndexOf(const UChar *srcChars,
  520.               int32_t srcLength,
  521.               UTextOffset start) const;
  522.  
  523.   /**
  524.    * Locate in this the last occurrence in the range 
  525.    * [<TT>start</TT>, <TT>start + length</TT>) of the characters 
  526.    * in <TT>srcChars</TT>, using bitwise comparison.
  527.    * @param text The text to search for.
  528.    * @param srcLength the number of characters in <TT>srcChars</TT>
  529.    * @param start The offset at which searching will start.
  530.    * @param length The number of characters to search
  531.    * @return The offset into this of the start of <TT>srcChars</TT>, 
  532.    * or -1 if not found.
  533.    */
  534.   inline UTextOffset lastIndexOf(const UChar *srcChars,
  535.               int32_t srcLength,
  536.               UTextOffset start,
  537.               int32_t length) const;
  538.  
  539.   /**
  540.    * Locate in this the last occurrence in the range 
  541.    * [<TT>start</TT>, <TT>start + length</TT>) of the characters 
  542.    * in <TT>srcChars</TT> in the range 
  543.    * [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>), 
  544.    * using bitwise comparison.   
  545.    * @param srcChars The text to search for.
  546.    * @param srcStart the offset into <TT>srcChars</TT> at which
  547.    * to start matching
  548.    * @param srcLength the number of characters in <TT>srcChars</TT> to match
  549.    * @param start the offset into this at which to start matching
  550.    * @param length the number of characters in this to search
  551.    * @return The offset into this of the start of <TT>text</TT>, 
  552.    * or -1 if not found.
  553.    */
  554.   inline UTextOffset lastIndexOf(const UChar *srcChars,
  555.               UTextOffset srcStart,
  556.               int32_t srcLength,
  557.               UTextOffset start,
  558.               int32_t length) const;
  559.  
  560.   /**
  561.    * Locate in this the last occurrence of the character <TT>c</TT>, 
  562.    * using bitwise comparison.
  563.    * @param c The character to search for.
  564.    * @return The offset into this of <TT>c</TT>, or -1 if not found.
  565.    */
  566.   inline UTextOffset lastIndexOf(UChar c) const;
  567.  
  568.   /**
  569.    * Locate in this the last occurrence of the character <TT>c</TT>
  570.    * starting at offset <TT>start</TT>, using bitwise comparison.
  571.    * @param c The character to search for.
  572.    * @param start The offset at which searching will start.
  573.    * @return The offset into this of <TT>c</TT>, or -1 if not found.
  574.    */
  575.   inline UTextOffset lastIndexOf(UChar c,
  576.               UTextOffset start) const;
  577.  
  578.   /**
  579.    * Locate in this the last occurrence of the character <TT>c</TT> 
  580.    * in the range [<TT>start</TT>, <TT>start + length</TT>), 
  581.    * using bitwise comparison.   
  582.    * @param c The character to search for.
  583.    * @param start the offset into this at which to start matching
  584.    * @param length the number of characters in this to search
  585.    * @return The offset into this of <TT>c</TT>, or -1 if not found.
  586.    */
  587.   inline UTextOffset lastIndexOf(UChar c,
  588.               UTextOffset start,
  589.               int32_t length) const;
  590.  
  591.  
  592.   /* Character access */
  593.  
  594.   /**
  595.    * Return the character at offset <tt>offset</tt>.
  596.    * @param offset a valid offset into the text
  597.    * @returns the character at offset <tt>offset</tt>
  598.    */
  599.   inline UChar charAt(UTextOffset offset) const;
  600.  
  601.   /**
  602.    * Return the character at offset <tt>offset</tt>.
  603.    * @param offset a valid offset into the text
  604.    * @returns the character at offset <tt>offset</tt>
  605.    */
  606.   inline UChar operator [] (UTextOffset offset) const;
  607.  
  608.  
  609.   /* Substring extraction */
  610.  
  611.   /**
  612.    * Copy the characters in the range 
  613.    * [<tt>start</tt>, <tt>start + length</tt>) into the array <tt>dst</tt>,
  614.    * beginning at <tt>dstStart</tt>.
  615.    * @param start offset of first character which will be copied into the array
  616.    * @param length the number of characters to extract
  617.    * @param dst array in which to copy characters.  The length of <tt>dst</tt>
  618.    * must be at least (<tt>dstStart + length</tt>).
  619.    * @param dstStart the offset in <TT>dst</TT> where the first character
  620.    * will be extracted
  621.    */
  622.   inline void extract(UTextOffset start, 
  623.            int32_t length, 
  624.            UChar *dst, 
  625.            UTextOffset dstStart = 0) const;
  626.   
  627.   /**
  628.    * Copy the characters in the range 
  629.    * [<tt>start</tt>, <tt>start + length</tt>) into the  UnicodeString
  630.    * <tt>target</tt>.
  631.    * @param start offset of first character which will be copied
  632.    * @param length the number of characters to extract
  633.    * @param target UnicodeString into which to copy characters.
  634.    * @return A reference to <TT>target</TT>
  635.    */
  636.   inline void extract(UTextOffset start,
  637.            int32_t length,
  638.            UnicodeString& target) const;
  639.  
  640.   /**
  641.    * Copy the characters in the range [<tt>start</tt>, <tt>limit</tt>) 
  642.    * into the array <tt>dst</tt>, beginning at <tt>dstStart</tt>.
  643.    * @param start offset of first character which will be copied into the array
  644.    * @param limit offset immediately following the last character to be copied
  645.    * @param dst array in which to copy characters.  The length of <tt>dst</tt> 
  646.    * must be at least (<tt>dstStart + (limit - start)</tt>).
  647.    * @param dstStart the offset in <TT>dst</TT> where the first character
  648.    * will be extracted
  649.    */
  650.   inline void extractBetween(UTextOffset start, 
  651.               UTextOffset limit, 
  652.               UChar *dst, 
  653.               UTextOffset dstStart = 0) const;
  654.  
  655.   /**
  656.    * Copy the characters in the range [<tt>start</tt>, <tt>limit</tt>) 
  657.    * into the UnicodeString <tt>target</tt>.
  658.    * @param start offset of first character which will be copied
  659.    * @param limit offset immediately following the last character to be copied
  660.    * @param target UnicodeString into which to copy characters.
  661.    * @return A reference to <TT>target</TT>
  662.    */
  663.   inline void extractBetween(UTextOffset start,
  664.               UTextOffset limit,
  665.               UnicodeString& target) const;
  666.  
  667.   /**
  668.    * Copy the characters in the range 
  669.    * [<tt>start</TT>, <tt>start + length</TT>) into an array of characters
  670.    * in a specified codepage.
  671.    * @param start offset of first character which will be copied
  672.    * @param length the number of characters to extract
  673.    * @param target the target buffer for extraction
  674.    * @param codepage the desired codepage for the characters.  0 has 
  675.    * the special meaning of the default codepage
  676.    * @return the number of characters written to <TT>dst</TT>
  677.    */
  678.   int32_t extract(UTextOffset start,
  679.            int32_t length,
  680.            char *dst,
  681.            const char *codepage = 0) const;
  682.   
  683.  
  684.   /* Length operations */
  685.  
  686.   /**
  687.    * Return the length of the UnicodeString object.  
  688.    * The length is the number of characters in the text.
  689.    * @returns the length of the UnicodeString object
  690.    */
  691.   inline int32_t  length(void) const;
  692.  
  693.   /**
  694.    * Determine if this string is empty.
  695.    * @return TRUE if this string contains 0 characters, FALSE otherwise.
  696.    */
  697.   inline bool_t empty(void) const;
  698.  
  699.  
  700.   /* Other operations */
  701.  
  702.   /**
  703.    * Generate a hash code for this object.
  704.    * @return The hash code of this UnicodeString.
  705.    */
  706.   inline int32_t hashCode(void) const;
  707.  
  708.   /**
  709.    * Determine if this string is still valid.
  710.    * @return TRUE if the string is valid, FALSE otherwise
  711.    */
  712.   inline bool_t isBogus(void) const;
  713.  
  714.   
  715.   //========================================
  716.   // Write operations
  717.   //========================================
  718.  
  719.   /* Assignment operations */
  720.  
  721.   /**
  722.    * Assignment operator.  Replace the characters in this UnicodeString
  723.    * with the characters from <TT>srcText</TT>.
  724.    * @param srcText The text containing the characters to replace
  725.    * @return a reference to this
  726.    */
  727.    UnicodeString& operator= (const UnicodeString& srcText);
  728.  
  729.   /**
  730.    * Assignment operator.  Replace the characters in this UnicodeString
  731.    * with the character <TT>ch</TT>.
  732.    * @param ch the character to replace
  733.    * @return a reference to this
  734.    */
  735.   inline UnicodeString& operator= (UChar ch);
  736.  
  737.   /**
  738.    * Set the text in the UnicodeString object to the characters
  739.    * in <TT>srcText</TT> in the range 
  740.    * [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>).
  741.    * <TT>srcText</TT> is not modified.
  742.    * @param srcText the source for the new characters
  743.    * @param srcStart the offset into <TT>srcText</TT> where new characters
  744.    * will be obtained
  745.    * @param srcLength the number of characters in <TT>srcText</TT> in the
  746.    * replace string.
  747.    * @return a reference to this
  748.    */
  749.   inline UnicodeString& setTo(const UnicodeString& srcText, 
  750.                UTextOffset srcStart, 
  751.                int32_t srcLength);
  752.  
  753.   /**
  754.    * Set the text in the UnicodeString object to the characters in 
  755.    * <TT>srcText</TT>.  
  756.    * <TT>srcText</TT> is not modified.
  757.    * @param srcText the source for the new characters
  758.    * @return a reference to this
  759.    */
  760.   inline UnicodeString& setTo(const UnicodeString& srcText);
  761.  
  762.   /**
  763.    * Set the characters in the UnicodeString object to the characters
  764.    * in <TT>srcChars</TT> in the range 
  765.    * [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>).
  766.    * <TT>srcChars</TT> is not modified.
  767.    * @param srcChars the source for the new characters
  768.    * @param srcStart the offset into <TT>srcChars</TT> where new characters 
  769.    * will be obtained
  770.    * @param srcLength the number of characters in <TT>srcChars</TT> in the 
  771.    * replace string
  772.    * @return a reference to this
  773.    */
  774.   inline UnicodeString& setTo(const UChar *srcChars, 
  775.                UTextOffset srcStart, 
  776.                int32_t srcLength);
  777.  
  778.   /**
  779.    * Set the characters in the UnicodeString object to the characters
  780.    * in <TT>srcChars</TT>. <TT>srcChars</TT> is not modified.
  781.    * @param srcChars the source for the new characters
  782.    * @param srcLength the number of Unicode characters in srcChars.
  783.    * @return a reference to this
  784.    */
  785.   inline UnicodeString& setTo(const UChar *srcChars,
  786.                int32_t srcLength);
  787.  
  788.   /**
  789.    * Set the characters in the UnicodeString object to the character 
  790.    * <TT>srcChar</TT>.
  791.    * @param srcChar the character which becomes the UnicodeString's character 
  792.    * content
  793.    * @return a reference to this
  794.    */
  795.   UnicodeString& setTo(UChar srcChar);
  796.  
  797.   /**
  798.    * Set the character at the specified offset to the specified character.
  799.    * @param offset A valid offset into the text of the character to set
  800.    * @param ch The new character
  801.    * @return A reference to this
  802.    */
  803.   UnicodeString& setCharAt(UTextOffset offset, 
  804.                UChar ch);
  805.  
  806.  
  807.   /* Append operations */
  808.  
  809.   /**
  810.    * Append operator. Append the character <TT>ch</TT> to the UnicodeString
  811.    * object.
  812.    * @param ch the character to be appended
  813.    * @return a reference to this
  814.    */
  815.  inline  UnicodeString& operator+= (UChar ch);
  816.  
  817.   /**
  818.    * Append operator. Append the characters in <TT>srcText</TT> to the
  819.    * UnicodeString object at offset <TT>start</TT>. <TT>srcText</TT> is
  820.    * not modified.
  821.    * @param srcText the source for the new characters
  822.    * @return a reference to this
  823.    */
  824.   inline UnicodeString& operator+= (const UnicodeString& srcText);
  825.  
  826.   /**
  827.    * Append the characters
  828.    * in <TT>srcText</TT> in the range 
  829.    * [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>) to the 
  830.    * UnicodeString object at offset <TT>start</TT>. <TT>srcText</TT> 
  831.    * is not modified.
  832.    * @param srcText the source for the new characters
  833.    * @param srcStart the offset into <TT>srcText</TT> where new characters 
  834.    * will be obtained
  835.    * @param srcLength the number of characters in <TT>srcText</TT> in 
  836.    * the append string
  837.    * @return a reference to this
  838.    */
  839.   inline UnicodeString& append(const UnicodeString& srcText, 
  840.             UTextOffset srcStart, 
  841.             int32_t srcLength);
  842.  
  843.   /**
  844.    * Append the characters in <TT>srcText</TT> to the UnicodeString object at 
  845.    * offset <TT>start</TT>. <TT>srcText</TT> is not modified.
  846.    * @param srcText the source for the new characters
  847.    * @return a reference to this
  848.    */
  849.   inline UnicodeString& append(const UnicodeString& srcText);
  850.  
  851.   /**
  852.    * Append the characters in <TT>srcChars</TT> in the range 
  853.    * [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>) to the UnicodeString 
  854.    * object at offset 
  855.    * <TT>start</TT>. <TT>srcChars</TT> is not modified.
  856.    * @param srcChars the source for the new characters
  857.    * @param srcStart the offset into <TT>srcChars</TT> where new characters 
  858.    * will be obtained
  859.    * @param srcLength the number of characters in <TT>srcChars</TT> in 
  860.    * the append string
  861.    * @return a reference to this
  862.    */
  863.   inline UnicodeString& append(const UChar *srcChars, 
  864.             UTextOffset srcStart, 
  865.             int32_t srcLength);
  866.  
  867.   /**
  868.    * Append the characters in <TT>srcChars</TT> to the UnicodeString object 
  869.    * at offset <TT>start</TT>. <TT>srcChars</TT> is not modified.
  870.    * @param srcChars the source for the new characters
  871.    * @param srcLength the number of Unicode characters in <TT>srcChars</TT>
  872.    * @return a reference to this
  873.    */
  874.   inline UnicodeString& append(const UChar *srcChars,
  875.             int32_t srcLength);
  876.  
  877.   /**
  878.    * Append the character <TT>srcChar</TT> to the UnicodeString object.
  879.    * @param srcChar the character to append
  880.    * @return a reference to this
  881.    */
  882.   inline UnicodeString& append(UChar srcChar);
  883.  
  884.  
  885.   /* Insert operations */
  886.  
  887.   /**
  888.    * Insert the characters in <TT>srcText</TT> in the range 
  889.    * [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>) into the UnicodeString 
  890.    * object at offset <TT>start</TT>. <TT>srcText</TT> is not modified.
  891.    * @param start the offset where the insertion begins
  892.    * @param srcText the source for the new characters 
  893.    * @param srcStart the offset into <TT>srcText</TT> where new characters 
  894.    * will be obtained
  895.    * @param srcLength the number of characters in <TT>srcText</TT> in 
  896.    * the insert string
  897.    * @return a reference to this
  898.    */
  899.   inline UnicodeString& insert(UTextOffset start, 
  900.             const UnicodeString& srcText, 
  901.             UTextOffset srcStart, 
  902.             int32_t srcLength);
  903.  
  904.   /**
  905.    * Insert the characters in <TT>srcText</TT> into the UnicodeString object
  906.    * at offset <TT>start</TT>. <TT>srcText</TT> is not modified.
  907.    * @param start the offset where the insertion begins
  908.    * @param srcText the source for the new characters 
  909.    * @return a reference to this
  910.    */
  911.   inline UnicodeString& insert(UTextOffset start, 
  912.             const UnicodeString& srcText);
  913.  
  914.   /**
  915.    * Insert the characters in <TT>srcChars</TT> in the range 
  916.    * [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>) into the UnicodeString
  917.    *  object at offset <TT>start</TT>. <TT>srcChars</TT> is not modified.
  918.    * @param start the offset at which the insertion begins
  919.    * @param srcChars the source for the new characters
  920.    * @param srcStart the offset into <TT>srcChars</TT> where new characters 
  921.    * will be obtained
  922.    * @param srcLength the number of characters in <TT>srcChars</TT> 
  923.    * in the insert string
  924.    * @return a reference to this
  925.    */
  926.   inline UnicodeString& insert(UTextOffset start, 
  927.             const UChar *srcChars, 
  928.             UTextOffset srcStart, 
  929.             int32_t srcLength);
  930.  
  931.   /**
  932.    * Insert the characters in <TT>srcChars</TT> into the UnicodeString object 
  933.    * at offset <TT>start</TT>. <TT>srcChars</TT> is not modified.
  934.    * @param start the offset where the insertion begins
  935.    * @param srcChars the source for the new characters
  936.    * @param srcLength the number of Unicode characters in srcChars.
  937.    * @return a reference to this
  938.    */
  939.   inline UnicodeString& insert(UTextOffset start, 
  940.             const UChar *srcChars,
  941.             int32_t srcLength);
  942.  
  943.   /**
  944.    * Insert the character <TT>srcChar</TT> into the UnicodeString object at 
  945.    * offset <TT>start</TT>.
  946.    * @param start the offset at which the insertion occurs
  947.    * @param srcChar the character to insert
  948.    * @return a reference to this
  949.    */
  950.   inline UnicodeString& insert(UTextOffset start, 
  951.             UChar srcChar);
  952.  
  953.  
  954.   /* Replace operations */
  955.  
  956.   /**
  957.    * Replace the characters in the range 
  958.    * [<TT>start</TT>, <TT>start + length</TT>) with the characters in 
  959.    * <TT>srcText</TT> in the range 
  960.    * [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>). 
  961.    * <TT>srcText</TT> is not modified.
  962.    * @param start the offset at which the replace operation begins
  963.    * @param length the number of characters to replace. The character at 
  964.    * <TT>start + length</TT> is not modified.
  965.    * @param srcText the source for the new characters
  966.    * @param srcStart the offset into <TT>srcText</TT> where new characters 
  967.    * will be obtained
  968.    * @param srcLength the number of characters in <TT>srcText</TT> in 
  969.    * the replace string
  970.    * @return a reference to this
  971.    */
  972.   UnicodeString& replace(UTextOffset start, 
  973.              int32_t length, 
  974.              const UnicodeString& srcText, 
  975.              UTextOffset srcStart, 
  976.              int32_t srcLength);
  977.  
  978.   /**
  979.    * Replace the characters in the range 
  980.    * [<TT>start</TT>, <TT>start + length</TT>) 
  981.    * with the characters in <TT>srcText</TT>.  <TT>srcText</TT> is
  982.    *  not modified.
  983.    * @param start the offset at which the replace operation begins
  984.    * @param length the number of characters to replace. The character at
  985.    * <TT>start + length</TT> is not modified.
  986.    * @param srcText the source for the new characters
  987.    * @return a reference to this
  988.    */
  989.   UnicodeString& replace(UTextOffset start, 
  990.              int32_t length, 
  991.              const UnicodeString& srcText);
  992.  
  993.   /**
  994.    * Replace the characters in the range 
  995.    * [<TT>start</TT>, <TT>start + length</TT>) with the characters in 
  996.    * <TT>srcChars</TT> in the range 
  997.    * [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>). <TT>srcChars</TT> 
  998.    * is not modified.
  999.    * @param start the offset at which the replace operation begins
  1000.    * @param length the number of characters to replace.  The character at
  1001.    * <TT>start + length</TT> is not modified.
  1002.    * @param srcChars the source for the new characters
  1003.    * @param srcStart the offset into <TT>srcChars</TT> where new characters
  1004.    * will be obtained
  1005.    * @param srcLength the number of characters in <TT>srcChars</TT> 
  1006.    * in the replace string
  1007.    * @return a reference to this
  1008.    */
  1009.   UnicodeString& replace(UTextOffset start, 
  1010.              int32_t length, 
  1011.              const UChar *srcChars, 
  1012.              UTextOffset srcStart, 
  1013.              int32_t srcLength);
  1014.  
  1015.   /**
  1016.    * Replace the characters in the range 
  1017.    * [<TT>start</TT>, <TT>start + length</TT>) with the characters in
  1018.    * <TT>srcChars</TT>.  <TT>srcChars</TT> is not modified.
  1019.    * @param start the offset at which the replace operation begins
  1020.    * @param length number of characters to replace.  The character at
  1021.    * <TT>start + length</TT> is not modified.
  1022.    * @param srcChars the source for the new characters
  1023.    * @param srcLength the number of Unicode characters in srcChars
  1024.    * @return a reference to this
  1025.    */
  1026.   inline UnicodeString& replace(UTextOffset start, 
  1027.              int32_t length, 
  1028.              const UChar *srcChars,
  1029.              int32_t srcLength);
  1030.  
  1031.   /**
  1032.    * Replace the characters in the range 
  1033.    * [<TT>start</TT>, <TT>start + length</TT>) with the character
  1034.    * <TT>srcChar</TT>.
  1035.    * @param start the offset at which the replace operation begins
  1036.    * @param length the number of characters to replace.  The character at
  1037.    * <TT>start + length</TT> is not modified.
  1038.    * @param srcChar the new character
  1039.    * @return a reference to this
  1040.    */
  1041.   inline UnicodeString& replace(UTextOffset start, 
  1042.              int32_t length, 
  1043.              UChar srcChar);
  1044.  
  1045.   /**
  1046.    * Replace the characters in the range [<TT>start</TT>, <TT>limit</TT>) 
  1047.    * with the characters in <TT>srcText</TT>. <TT>srcText</TT> is not modified.
  1048.    * @param start the offset at which the replace operation begins
  1049.    * @param limit the offset immediately following the replace range
  1050.    * @param srcText the source for the new characters
  1051.    * @return a reference to this
  1052.    */
  1053.   inline UnicodeString& replaceBetween(UTextOffset start, 
  1054.                 UTextOffset limit, 
  1055.                 const UnicodeString& srcText);
  1056.  
  1057.   /**
  1058.    * Replace the characters in the range [<TT>start</TT>, <TT>limit</TT>) 
  1059.    * with the characters in <TT>srcText</TT> in the range 
  1060.    * [<TT>srcStart</TT>, <TT>srcLimit</TT>). <TT>srcText</TT> is not modified.
  1061.    * @param start the offset at which the replace operation begins
  1062.    * @param limit the offset immediately following the replace range
  1063.    * @param srcText the source for the new characters
  1064.    * @param srcStart the offset into <TT>srcChars</TT> where new characters 
  1065.    * will be obtained
  1066.    * @param srcLimit the offset immediately following the range to copy 
  1067.    * in <TT>srcText</TT>
  1068.    * @return a reference to this
  1069.    */
  1070.   inline UnicodeString& replaceBetween(UTextOffset start, 
  1071.                 UTextOffset limit, 
  1072.                 const UnicodeString& srcText, 
  1073.                 UTextOffset srcStart, 
  1074.                 UTextOffset srcLimit);
  1075.  
  1076.  
  1077.   /* Search and replace operations */
  1078.  
  1079.   /**
  1080.    * Replace all occurrences of characters in oldText with the characters 
  1081.    * in newText
  1082.    * @param oldText the text containing the search text
  1083.    * @param newText the text containing the replacement text
  1084.    * @return a reference to this
  1085.    */
  1086.   inline UnicodeString& findAndReplace(const UnicodeString& oldText,
  1087.                 const UnicodeString& newText);
  1088.  
  1089.   /**
  1090.    * Replace all occurrences of characters in oldText with characters 
  1091.    * in newText
  1092.    * in the range [<TT>start</TT>, <TT>start + length</TT>).
  1093.    * @param start the start of the range in which replace will performed
  1094.    * @param length the length of the range in which replace will be performed
  1095.    * @param oldText the text containing the search text
  1096.    * @param newText the text containing the replacement text
  1097.    * @return a reference to this
  1098.    */
  1099.   inline UnicodeString& findAndReplace(UTextOffset start,
  1100.                 int32_t length,
  1101.                 const UnicodeString& oldText,
  1102.                 const UnicodeString& newText);
  1103.  
  1104.   /**
  1105.    * Replace all occurrences of characters in oldText in the range 
  1106.    * [<TT>oldStart</TT>, <TT>oldStart + oldLength</TT>) with the characters 
  1107.    * in newText in the range 
  1108.    * [<TT>newStart</TT>, <TT>newStart + newLength</TT>) 
  1109.    * in the range [<TT>start</TT>, <TT>start + length</TT>).
  1110.    * @param start the start of the range in which replace will performed
  1111.    * @param length the length of the range in which replace will be performed
  1112.    * @param oldText the text containing the search text
  1113.    * @param oldStart the start of the search range in <TT>oldText</TT>
  1114.    * @param oldLength the length of the search range in <TT>oldText</TT>
  1115.    * @param newText the text containing the replacement text
  1116.    * @param newStart the start of the replacement range in <TT>newText</TT>
  1117.    * @param newLength the length of the replacement range in <TT>newText</TT>
  1118.    * @return a reference to this
  1119.    */
  1120.   inline UnicodeString& findAndReplace(UTextOffset start,
  1121.                 int32_t length,
  1122.                 const UnicodeString& oldText,
  1123.                 UTextOffset oldStart,
  1124.                 int32_t oldLength,
  1125.                 const UnicodeString& newText,
  1126.                 UTextOffset newStart,
  1127.                 int32_t newLength);
  1128.  
  1129.  
  1130.   /* Remove operations */
  1131.  
  1132.   /**
  1133.    * Remove all characters from the UnicodeString object.
  1134.    * @return a reference to this
  1135.    */
  1136.   inline UnicodeString& remove(void);
  1137.  
  1138.   /**
  1139.    * Remove the characters in the range 
  1140.    * [<TT>start</TT>, <TT>start + length</TT>) from the UnicodeString object.
  1141.    * @param start the offset of the first character to remove
  1142.    * @param length the number of characters to remove
  1143.    * @return a reference to this
  1144.    */
  1145.   inline UnicodeString& remove(UTextOffset start, 
  1146.             int32_t length = LONG_MAX);
  1147.  
  1148.   /**
  1149.    * Remove the characters in the range 
  1150.    * [<TT>start</TT>, <TT>limit</TT>) from the UnicodeString object.
  1151.    * @param start the offset of the first character to remove
  1152.    * @param limit the offset immediately following the range to remove
  1153.    * @return a reference to this
  1154.    */
  1155.   inline UnicodeString& removeBetween(UTextOffset start,
  1156.                    UTextOffset limit = LONG_MAX);
  1157.  
  1158.  
  1159.   /* Length operations */
  1160.  
  1161.   /**
  1162.    * Pad the start of this UnicodeString with the character <TT>padChar</TT>.  
  1163.    * If the length of this UnicodeString is less than targetLength, 
  1164.    * length() - targetLength copies of padChar will be added to the
  1165.    * beginning of this UnicodeString.
  1166.    * @param targetLength the desired length of the string
  1167.    * @param padChar the character to use for padding. Defaults to 
  1168.    * space (U+0020)
  1169.    * @return TRUE if the text was padded, FALSE otherwise.
  1170.    */
  1171.   inline bool_t padLeading(int32_t targetLength,
  1172.             UChar padChar = 0x0020);
  1173.  
  1174.   /**
  1175.    * Pad the end of this UnicodeString with the character <TT>padChar</TT>.  
  1176.    * If the length of this UnicodeString is less than targetLength, 
  1177.    * length() - targetLength copies of padChar will be added to the
  1178.    * end of this UnicodeString.
  1179.    * @param targetLength the desired length of the string
  1180.    * @param padChar the character to use for padding. Defaults to 
  1181.    * space (U+0020)
  1182.    * @return TRUE if the text was padded, FALSE otherwise.
  1183.    */
  1184.   inline bool_t padTrailing(int32_t targetLength,
  1185.              UChar padChar = 0x0020);
  1186.  
  1187.   /**
  1188.    * Truncate this UnicodeString to the <TT>targetLength</TT>.
  1189.    * @param targetLength the desired length of this UnicodeString.
  1190.    * @return TRUE if the text was truncated, FALSE otherwise
  1191.    */
  1192.   inline bool_t truncate(int32_t targetLength);
  1193.  
  1194.   /**
  1195.    * Trims leading and trailing whitespace from this UnicodeString.
  1196.    * @return a reference to this
  1197.    */
  1198.   inline UnicodeString& trim(void);
  1199.  
  1200.  
  1201.   /* Miscellaneous operations */
  1202.  
  1203.   /**
  1204.    * Reverse this UnicodeString in place.
  1205.    * @return a reference to this
  1206.    */
  1207.   inline UnicodeString& reverse(void);
  1208.  
  1209.   /**
  1210.    * Reverse the range [<TT>start</TT>, <TT>start + length</TT>) in
  1211.    * this UnicodeString.
  1212.    * @param start the start of the range to reverse
  1213.    * @param length the number of characters to to reverse
  1214.    * @return a reference to this
  1215.    */
  1216.   inline UnicodeString& reverse(UTextOffset start,
  1217.              int32_t length);
  1218.  
  1219.   /**
  1220.    * Convert the characters in this to UPPER CASE following the conventions of
  1221.    * the default locale.
  1222.    * @return A reference to this.
  1223.    */
  1224.   UnicodeString& toUpper(void);
  1225.  
  1226.   /**
  1227.    * Convert the characters in this to UPPER CASE following the conventions of
  1228.    * a specific locale.
  1229.    * @param locale The locale containing the conventions to use.
  1230.    * @return A reference to this.
  1231.    */
  1232.   UnicodeString& toUpper(const Locale& locale);
  1233.  
  1234.   /**
  1235.    * Convert the characters in this to UPPER CASE following the conventions of
  1236.    * the default.
  1237.    * @return A reference to this.
  1238.    */
  1239.   UnicodeString& toLower(void);
  1240.  
  1241.   /**
  1242.    * Convert the characters in this to UPPER CASE following the conventions of
  1243.    * a specific locale.
  1244.    * @param locale The locale containing the conventions to use.
  1245.    * @return A reference to this.
  1246.    */
  1247.   UnicodeString& toLower(const Locale& locale);
  1248.  
  1249.  
  1250.   //========================================
  1251.   // Constructors
  1252.   //========================================
  1253.  
  1254.   /** Construct an empty UnicodeString.  */
  1255.   UnicodeString();
  1256.  
  1257.  
  1258.   /**
  1259.    * Construct a UnicodeString with capacity to hold <TT>capacity</TT> UChars
  1260.    * @param capacity the number of UChars this UnicodeString should hold
  1261.    * before a resize is necessary
  1262.    */
  1263.   UnicodeString(int32_t capacity);
  1264.  
  1265.   /**
  1266.    * Single UChar constructor.
  1267.    * @param ch the character to place in the UnicodeString
  1268.    */
  1269.   UnicodeString(UChar ch);
  1270.  
  1271.   /**
  1272.    * UChar* constructor.
  1273.    * @param text The characters to place in the UnicodeString.  <TT>text</TT>
  1274.    * must be NULL (U+0000) terminated.
  1275.    */
  1276.   UnicodeString(const UChar *text);
  1277.  
  1278.   /**
  1279.    * UChar* constructor.
  1280.    * @param text The characters to place in the UnicodeString.
  1281.    * @param textLength The number of Unicode characters in <TT>text</TT>
  1282.    * to copy.
  1283.    */
  1284.   UnicodeString(const UChar *text,
  1285.         int32_t textLength);
  1286.  
  1287.   /**
  1288.    * char* constructor.
  1289.    * @param codepageData an array of bytes, null-terminated
  1290.    * @param codepage the encoding of <TT>codepageData</TT>.  The special
  1291.    * value 0 for <TT>codepage</TT> indicates that the text is in the 
  1292.    * platform's default codepage.
  1293.    */
  1294.   UnicodeString(const char *codepageData,
  1295.         const char *codepage = 0);
  1296.  
  1297.   /**
  1298.    * char* constructor.
  1299.    * @param codepageData an array of bytes.
  1300.    * @param dataLength The number of bytes in <TT>codepageData</TT>.
  1301.    * @param codepage the encoding of <TT>codepageData</TT>.  The special
  1302.    * value 0 for <TT>codepage</TT> indicates that the text is in the 
  1303.    * platform's default codepage.
  1304.    */
  1305.   UnicodeString(const char *codepageData,
  1306.         int32_t dataLength,
  1307.         const char *codepage = 0);
  1308.  
  1309.   /**
  1310.    * Copy constructor.
  1311.    * @param that The UnicodeString object to copy.
  1312.    */
  1313.   inline UnicodeString(const UnicodeString& that);
  1314.  
  1315.   /** Destructor. */
  1316.   ~UnicodeString();
  1317.  
  1318.  
  1319.   /* Miscellaneous operations */
  1320.  
  1321.   /**
  1322.    * Returns the number of display cells occupied by the range
  1323.    * [<TT>start</TT>, <TT>length</TT>).
  1324.    * This function is designed for Asian text and properly takes into account
  1325.    * halfwidth and fullwidth variants of various CJK characters and the 
  1326.    * combining behavior of the Hangul Jamo characters (with some limitations;
  1327.    * see documentation for Unicode::getCellWidth()).<BR>
  1328.    * In order to avoid dealing with fractions, this function can either be
  1329.    * construed to return twice the actual number of display cells or to 
  1330.    * treat a "cell" as the width of a halfwidth character rather than the
  1331.    * width of a fullwidth character.
  1332.    * @param start the start of the range
  1333.    * @param length the number of characters to measure
  1334.    * @param asian The <TT>asian</TT> parameter controls whether characters
  1335.    * considered NEUTRAL by the Unicode class are treated as halfwidth or 
  1336.    * fullwidth here.  If you set <TT>asian</TT> to FALSE, neutrals are 
  1337.    * treated as halfwidth, and this function returns a close approximation
  1338.    * of how many Latin display cells the text will take up in a monospaced
  1339.    * font.
  1340.    * @return the number of display cells occupied by the specified substring.
  1341.    */
  1342.   int32_t numDisplayCells(UTextOffset start = 0,
  1343.               int32_t length = LONG_MAX,
  1344.               bool_t asian = TRUE) const;
  1345.  
  1346.  
  1347.   UCharReference operator[] (UTextOffset pos);
  1348.  
  1349.   // {sfb} remove these later?
  1350.   /* Hack to avoid circular dependencies */
  1351.  
  1352.   /**
  1353.    * Convert the characters in this to UPPER CASE following the conventions of
  1354.    * the default locale.
  1355.    * @retrurn A reference to this.
  1356.    */
  1357.   // UnicodeString& toUpper();
  1358.  
  1359.   /**
  1360.    * Convert the characters in this to lower case following the conventions of
  1361.    * the default locale.
  1362.    * @retrurn A reference to this.
  1363.    */
  1364.   // UnicodeString& toLower();
  1365.  
  1366.  
  1367.   //========================================
  1368.   // Implementation methods
  1369.   //========================================
  1370.   
  1371. private:
  1372.  
  1373.   int8_t doCompare(UTextOffset start,
  1374.            int32_t length,
  1375.            const UnicodeString& srcText,
  1376.            UTextOffset srcStart,
  1377.            int32_t srcLength) const;
  1378.   
  1379.   int8_t doCompare(UTextOffset start,
  1380.            int32_t length,
  1381.            const UChar *srcChars,
  1382.            UTextOffset srcStart,
  1383.            int32_t srcLength) const;
  1384.  
  1385.   UTextOffset doIndexOf(UChar c,
  1386.             UTextOffset start,
  1387.             int32_t length) const;
  1388.  
  1389.   UTextOffset doLastIndexOf(UChar c,
  1390.                 UTextOffset start,
  1391.                 int32_t length) const;
  1392.  
  1393.   void doExtract(UTextOffset start, 
  1394.          int32_t length, 
  1395.          UChar *dst, 
  1396.          UTextOffset dstStart) const;
  1397.   
  1398.   inline void doExtract(UTextOffset start,
  1399.          int32_t length,
  1400.          UnicodeString& target) const;
  1401.   
  1402.   inline UChar doCharAt(UTextOffset offset)  const;
  1403.  
  1404.   UnicodeString& doSetCharAt(UTextOffset offset,
  1405.                  UChar c);
  1406.  
  1407.   UnicodeString& doReplace(UTextOffset start, 
  1408.                int32_t length, 
  1409.                const UnicodeString& srcText, 
  1410.                UTextOffset srcStart, 
  1411.                int32_t srcLength);
  1412.  
  1413.   UnicodeString& doReplace(UTextOffset start, 
  1414.                int32_t length, 
  1415.                const UChar *srcChars, 
  1416.                UTextOffset srcStart, 
  1417.                int32_t srcLength);
  1418.  
  1419.   UnicodeString& doReverse(UTextOffset start,
  1420.                int32_t length);
  1421.  
  1422.   // calculate hash code
  1423.   int32_t doHashCode(void);
  1424.   
  1425.   // get pointer to start of array
  1426.   inline UChar* getArrayStart(void);
  1427.   inline const UChar* getArrayStart(void) const;
  1428.  
  1429.   // get the "real" capacity of the array, adjusted for ref count
  1430.   inline int32_t getCapacity(void) const;
  1431.  
  1432.   // utility method to get around lack of exception handling
  1433.   void setToBogus(void);
  1434.  
  1435.   // Pin start and limit to acceptable values.
  1436.   void pinIndices(UTextOffset& start,
  1437.           int32_t& length) const;
  1438.  
  1439.   // Real ctor for converting from codepage data
  1440.   void doCodepageCreate(const char *codepageData,
  1441.             int32_t dataLength,
  1442.             const char *codepage);
  1443.  
  1444.   // clones array if refCount > 1
  1445.   void cloneArrayIfNeeded(void);
  1446.  
  1447.   // ref counting
  1448.   inline uint16_t addRef(void);
  1449.   inline uint16_t removeRef(void);
  1450.   inline uint16_t refCount(void) const;
  1451.   inline uint16_t setRefCount(uint16_t count);
  1452.  
  1453.   UChar     fStackBuffer [ US_STACKBUF_SIZE ]; // buffer for small strings
  1454.   UChar     *fArray;        // the Unicode data
  1455.   int32_t   fLength;        // number characters in fArray
  1456.   int32_t   fCapacity;      // sizeof fArray
  1457.   bool_t    fRefCounted;    // indicates if we own storage
  1458.   int32_t   fHashCode;      // the hash code
  1459.   bool_t    fBogus;         // indicates if an operation failed
  1460.  
  1461.   // constants
  1462.   static const UChar fgInvalidUChar; // invalid UChar index
  1463.   static const int32_t kGrowSize; // grow size for this buffer
  1464.   static const int32_t kInvalidHashCode; // invalid hash code
  1465.   static const int32_t kEmptyHashCode; // hash code for empty string
  1466.   
  1467.   // statics
  1468.   inline static int32_t allocation(int32_t minSize); // allocation algorithm
  1469.   inline static UChar* allocate(int32_t minSize, // allocate buffer >= minSize
  1470.              int32_t& actualSize);
  1471.  
  1472.   // default converter cache
  1473.   static UConverter* getDefaultConverter(UErrorCode& status);
  1474.   static void releaseDefaultConverter(UConverter *converter);
  1475.  
  1476.   static UConverter *fgDefaultConverter;
  1477.  
  1478.   friend class UnicodeStringStreamer;
  1479.  
  1480. public:
  1481.  
  1482.   //========================================
  1483.   // Deprecated API
  1484.   //========================================
  1485.  
  1486.   // size() -> length()
  1487.   inline int32_t size(void) const;
  1488.  
  1489.   // parameters reordered for consistency
  1490.   inline UnicodeString& findAndReplace(const UnicodeString& oldText,
  1491.                 const UnicodeString& newText,
  1492.                 UTextOffset start,
  1493.                 int32_t length);
  1494.  
  1495.   inline void* operator new(size_t size);
  1496.   inline void* operator new(size_t size, void *location);
  1497.   inline void operator delete(void *location);
  1498.  
  1499.  
  1500.   //========================================
  1501.   // Non-public API - will be removed!
  1502.   //========================================
  1503.   UnicodeString(UChar *buff, int32_t bufLength, int32_t buffCapacity);
  1504.   const UChar* getUChars(void) const;
  1505.   inline const UChar* getUniChars(void) const;
  1506.   UChar* orphanStorage(void);
  1507.  
  1508. };
  1509.  
  1510. //========================================
  1511. // Array copying
  1512. //========================================
  1513. // Copy an array of UnicodeString OBJECTS (not pointers).
  1514. inline void 
  1515. icu_arrayCopy(const UnicodeString *src, UnicodeString *dst, int32_t count)
  1516. { while(count-- > 0) *dst++ = *src++; }
  1517.  
  1518. inline void 
  1519. icu_arrayCopy(const UnicodeString *src, int32_t srcStart, 
  1520.         UnicodeString *dst, int32_t dstStart, int32_t count)
  1521. { icu_arrayCopy(src+srcStart, dst+dstStart, count); }
  1522.  
  1523.  
  1524. //========================================
  1525. // Inline members
  1526. //========================================
  1527. inline 
  1528. UnicodeString::UnicodeString(const UnicodeString& that)
  1529.   : fArray(fStackBuffer), fLength(0), fCapacity(US_STACKBUF_SIZE),
  1530.     fRefCounted(FALSE), fHashCode(kEmptyHashCode), fBogus(FALSE)
  1531. { *this = that; }
  1532.  
  1533.  
  1534. //========================================
  1535. // Read-only alias methods
  1536. //========================================
  1537. inline bool_t
  1538. UnicodeString::operator== (const UnicodeString& text) const
  1539. { return (fLength == text.fLength 
  1540.       && doCompare(0, fLength, text, 0, text.fLength) == 0); }
  1541.  
  1542. inline bool_t
  1543. UnicodeString::operator!= (const UnicodeString& text) const
  1544. { return (! operator==(text)); }
  1545.  
  1546. inline bool_t
  1547. UnicodeString::operator> (const UnicodeString& text) const
  1548. { return doCompare(0, fLength, text, 0, text.fLength) == 1; }
  1549.  
  1550. inline bool_t
  1551. UnicodeString::operator< (const UnicodeString& text) const
  1552. { return doCompare(0, fLength, text, 0, text.fLength) == -1; }
  1553.  
  1554. inline bool_t
  1555. UnicodeString::operator>= (const UnicodeString& text) const
  1556. { return doCompare(0, fLength, text, 0, text.fLength) != -1; }
  1557.  
  1558. inline bool_t
  1559. UnicodeString::operator<= (const UnicodeString& text) const
  1560. { return doCompare(0, fLength, text, 0, text.fLength) != 1; }
  1561.  
  1562. inline int8_t 
  1563. UnicodeString::compare(const UnicodeString& text) const
  1564. { return doCompare(0, fLength, text, 0, text.fLength); }
  1565.  
  1566. inline int8_t 
  1567. UnicodeString::compare(UTextOffset start,
  1568.                int32_t length,
  1569.                const UnicodeString& srcText) const
  1570. { return doCompare(start, length, srcText, 0, srcText.fLength); }
  1571.  
  1572. inline int8_t 
  1573. UnicodeString::compare(const UChar *srcChars,
  1574.                int32_t srcLength) const
  1575. { return doCompare(0, fLength, srcChars, 0, srcLength); }
  1576.  
  1577. inline int8_t 
  1578. UnicodeString::compare(UTextOffset start,
  1579.                int32_t length,
  1580.                const UnicodeString& srcText,
  1581.                UTextOffset srcStart,
  1582.                int32_t srcLength) const
  1583. { return doCompare(start, length, srcText, srcStart, srcLength); }
  1584.  
  1585. inline int8_t
  1586. UnicodeString::compare(UTextOffset start,
  1587.                int32_t length,
  1588.                const UChar *srcChars) const
  1589. { return doCompare(start, length, srcChars, 0, length); }
  1590.  
  1591. inline int8_t 
  1592. UnicodeString::compare(UTextOffset start,
  1593.                int32_t length,
  1594.                const UChar *srcChars,
  1595.                UTextOffset srcStart,
  1596.                int32_t srcLength) const
  1597. { return doCompare(start, length, srcChars, srcStart, srcLength); }
  1598.  
  1599. inline int8_t
  1600. UnicodeString::compareBetween(UTextOffset start,
  1601.                   UTextOffset limit,
  1602.                   const UnicodeString& srcText,
  1603.                   UTextOffset srcStart,
  1604.                   UTextOffset srcLimit) const
  1605. { return doCompare(start, limit - start, 
  1606.            srcText, srcStart, srcLimit - srcStart); }
  1607.  
  1608. inline UTextOffset 
  1609. UnicodeString::indexOf(const UnicodeString& text) const
  1610. { return indexOf(text, 0, text.fLength, 0, fLength); }
  1611.  
  1612. inline UTextOffset 
  1613. UnicodeString::indexOf(const UnicodeString& text,
  1614.                UTextOffset start) const
  1615. { return indexOf(text, 0, text.fLength, start, fLength - start); }
  1616.  
  1617. inline UTextOffset 
  1618. UnicodeString::indexOf(const UnicodeString& text,
  1619.                UTextOffset start,
  1620.                int32_t length) const
  1621. { return indexOf(text, 0, text.fLength, start, length); }
  1622.  
  1623. inline UTextOffset 
  1624. UnicodeString::indexOf(const UnicodeString& srcText,
  1625.                UTextOffset srcStart,
  1626.                int32_t srcLength,
  1627.                UTextOffset start,
  1628.                int32_t length) const
  1629. {
  1630.   UTextOffset pos = 0, myStart = start;
  1631.   int32_t myLength = length, limit = start + length;
  1632.  
  1633.   // cache for speed
  1634.   UChar ch = srcText.charAt(srcStart);
  1635.  
  1636.   while( (pos = indexOf(ch, myStart, myLength)) != -1 && myLength > 0) {
  1637.     if(compare(pos, srcLength, srcText, srcStart, srcLength) == 0)
  1638.       return pos;
  1639.  
  1640.     myStart = pos + 1;
  1641.     myLength = limit - myStart;
  1642.   }
  1643.  
  1644.   return -1;
  1645. }
  1646.  
  1647. inline UTextOffset 
  1648. UnicodeString::indexOf(const UChar *srcChars,
  1649.                int32_t srcLength,
  1650.                UTextOffset start) const
  1651. { return indexOf(srcChars, 0, srcLength, start, fLength - start); }
  1652.  
  1653. inline UTextOffset 
  1654. UnicodeString::indexOf(const UChar *srcChars,
  1655.                int32_t srcLength,
  1656.                UTextOffset start,
  1657.                int32_t length) const
  1658. { return indexOf(srcChars, 0, srcLength, start, length); }
  1659.  
  1660. inline UTextOffset 
  1661. UnicodeString::indexOf(const UChar *srcChars,
  1662.                UTextOffset srcStart,
  1663.                int32_t srcLength,
  1664.                UTextOffset start,
  1665.                int32_t length) const
  1666. {
  1667.   UTextOffset pos = 0, myStart = start;
  1668.   int32_t myLength = length, limit = start + length;
  1669.  
  1670.   // cache for speed
  1671.   UChar ch = srcChars[srcStart];
  1672.  
  1673.   while( (pos = indexOf(ch, myStart, myLength)) != -1 && myLength > 0) {
  1674.     if(compare(pos, srcLength, srcChars, srcStart, srcLength) == 0)
  1675.       return pos;
  1676.  
  1677.     myStart = pos + 1;
  1678.     myLength = limit - myStart;
  1679.   }
  1680.  
  1681.   return -1;
  1682. }
  1683.  
  1684. inline UTextOffset 
  1685. UnicodeString::indexOf(UChar c) const
  1686. { return doIndexOf(c, 0, fLength); }
  1687.  
  1688. inline UTextOffset 
  1689. UnicodeString::indexOf(UChar c,
  1690.                UTextOffset start) const
  1691. { return doIndexOf(c, start, fLength - start); }
  1692.  
  1693. inline UTextOffset 
  1694. UnicodeString::indexOf(UChar c,
  1695.                UTextOffset start,
  1696.                int32_t length) const
  1697. { return doIndexOf(c, start, length); }
  1698.  
  1699. inline UTextOffset 
  1700. UnicodeString::lastIndexOf(const UnicodeString& text) const
  1701. { return lastIndexOf(text, 0, text.fLength, 0, fLength); }
  1702.  
  1703. inline UTextOffset 
  1704. UnicodeString::lastIndexOf(const UnicodeString& text,
  1705.                UTextOffset start) const
  1706. { return lastIndexOf(text, 0, text.fLength, start, fLength - start); }
  1707.  
  1708. inline UTextOffset 
  1709. UnicodeString::lastIndexOf(const UnicodeString& text,
  1710.                UTextOffset start,
  1711.                int32_t length) const
  1712. { return lastIndexOf(text, 0, text.fLength, start, length); }
  1713.  
  1714. inline UTextOffset 
  1715. UnicodeString::lastIndexOf(const UnicodeString& srcText,
  1716.                UTextOffset srcStart,
  1717.                int32_t srcLength,
  1718.                UTextOffset start,
  1719.                int32_t length) const
  1720. {
  1721.   UTextOffset pos = 0, myStart = start;
  1722.   int32_t myLength = length, limit = start + length;
  1723.  
  1724.   // cache for speed
  1725.   UChar ch = srcText.charAt(srcStart);
  1726.  
  1727.   while( (pos = lastIndexOf(ch, myStart, myLength)) != -1 && myLength > 0) {
  1728.     if(compare(pos, srcLength, srcText, srcStart, srcLength) == 0)
  1729.       return pos;
  1730.  
  1731.     myLength = pos - myStart - 1;
  1732.   }
  1733.  
  1734.   return -1;
  1735. }
  1736.  
  1737. inline UTextOffset 
  1738. UnicodeString::lastIndexOf(const UChar *srcChars,
  1739.                int32_t srcLength,
  1740.                UTextOffset start) const
  1741. { return lastIndexOf(srcChars, 0, srcLength, start, fLength - start); }
  1742.  
  1743. inline UTextOffset 
  1744. UnicodeString::lastIndexOf(const UChar *srcChars,
  1745.                int32_t srcLength,
  1746.                UTextOffset start,
  1747.                int32_t length) const
  1748. { return lastIndexOf(srcChars, 0, srcLength, start, length); }
  1749.  
  1750. inline UTextOffset 
  1751. UnicodeString::lastIndexOf(const UChar *srcChars,
  1752.                UTextOffset srcStart,
  1753.                int32_t srcLength,
  1754.                UTextOffset start,
  1755.                int32_t length) const
  1756. {
  1757.   UTextOffset pos = 0, myStart = start;
  1758.   int32_t myLength = length, limit = start + length;
  1759.  
  1760.   // cache for speed
  1761.   UChar ch = srcChars[srcStart];
  1762.  
  1763.   while( (pos = lastIndexOf(ch, myStart, myLength)) != -1 && myLength > 0) {
  1764.     if(compare(pos, srcLength, srcChars, srcStart, srcLength) == 0)
  1765.       return pos;
  1766.  
  1767.     myLength = pos - myStart - 1;
  1768.   }
  1769.  
  1770.   return -1;
  1771. }
  1772.  
  1773. inline UTextOffset 
  1774. UnicodeString::lastIndexOf(UChar c) const
  1775. { return doLastIndexOf(c, 0, fLength); }
  1776.  
  1777. inline UTextOffset 
  1778. UnicodeString::lastIndexOf(UChar c,
  1779.                UTextOffset start) const
  1780. { return doLastIndexOf(c, start, fLength - start); }
  1781.  
  1782. inline UTextOffset 
  1783. UnicodeString::lastIndexOf(UChar c,
  1784.                UTextOffset start,
  1785.                int32_t length) const
  1786. { return doLastIndexOf(c, start, length); }
  1787.  
  1788. inline bool_t 
  1789. UnicodeString::startsWith(const UnicodeString& text) const
  1790. { return compare(0, text.fLength, text, 0, text.fLength) == 0; }
  1791.  
  1792. inline bool_t 
  1793. UnicodeString::startsWith(const UnicodeString& srcText,
  1794.               UTextOffset srcStart,
  1795.               int32_t srcLength) const
  1796. { return doCompare(0, srcLength, srcText, srcStart, srcLength) == 0; }
  1797.  
  1798. inline bool_t 
  1799. UnicodeString::startsWith(const UChar *srcChars,
  1800.               int32_t srcLength) const
  1801. { return doCompare(0, srcLength, srcChars, 0, srcLength) == 0; }
  1802.  
  1803. inline bool_t 
  1804. UnicodeString::startsWith(const UChar *srcChars,
  1805.               UTextOffset srcStart,
  1806.               int32_t srcLength) const
  1807. { return doCompare(0, srcLength, srcChars, srcStart, srcLength) == 0;}
  1808.  
  1809. inline bool_t 
  1810. UnicodeString::endsWith(const UnicodeString& text) const
  1811. { return doCompare(fLength - text.fLength, text.fLength, 
  1812.            text, 0, text.fLength) == 0; }
  1813.  
  1814. inline bool_t 
  1815. UnicodeString::endsWith(const UnicodeString& srcText,
  1816.             UTextOffset srcStart,
  1817.             int32_t srcLength) const
  1818. { return doCompare(fLength - srcLength, srcLength, 
  1819.            srcText, srcStart, srcLength) == 0; }
  1820.  
  1821. inline bool_t 
  1822. UnicodeString::endsWith(const UChar *srcChars,
  1823.             int32_t srcLength) const
  1824. { return doCompare(fLength - srcLength, srcLength, 
  1825.            srcChars, 0, srcLength) == 0; }
  1826.  
  1827. inline bool_t 
  1828. UnicodeString::endsWith(const UChar *srcChars,
  1829.             UTextOffset srcStart,
  1830.             int32_t srcLength) const
  1831. { return doCompare(fLength - srcLength, srcLength, 
  1832.            srcChars, srcStart, srcLength) == 0;}
  1833. //========================================
  1834. // replace
  1835. //========================================
  1836. inline UnicodeString& 
  1837. UnicodeString::replace(UTextOffset start, 
  1838.                int32_t length, 
  1839.                const UnicodeString& srcText) 
  1840. { return doReplace(start, length, srcText, 0, srcText.fLength); }
  1841.  
  1842. inline UnicodeString& 
  1843. UnicodeString::replace(UTextOffset start, 
  1844.                int32_t length, 
  1845.                const UnicodeString& srcText, 
  1846.                UTextOffset srcStart, 
  1847.                int32_t srcLength)
  1848. { return doReplace(start, length, srcText, srcStart, srcLength); }
  1849.  
  1850. inline UnicodeString& 
  1851. UnicodeString::replace(UTextOffset start, 
  1852.                int32_t length, 
  1853.                const UChar *srcChars,
  1854.                int32_t srcLength)
  1855. { return doReplace(start, length, srcChars, 0, srcLength); }
  1856.  
  1857. inline UnicodeString& 
  1858. UnicodeString::replace(UTextOffset start, 
  1859.                int32_t length, 
  1860.                const UChar *srcChars, 
  1861.                UTextOffset srcStart, 
  1862.                int32_t srcLength)
  1863. { return doReplace(start, length, srcChars, srcStart, srcLength); }
  1864.  
  1865. inline UnicodeString& 
  1866. UnicodeString::replace(UTextOffset start, 
  1867.                int32_t length, 
  1868.                UChar srcChar)
  1869. { return doReplace(start, length, &srcChar, 0, 1); }
  1870.  
  1871. inline UnicodeString& 
  1872. UnicodeString::replaceBetween(UTextOffset start, 
  1873.                   UTextOffset limit, 
  1874.                   const UnicodeString& srcText)
  1875. { return doReplace(start, limit - start, srcText, 0, srcText.fLength); }
  1876.  
  1877. inline UnicodeString&
  1878. UnicodeString::replaceBetween(UTextOffset start, 
  1879.                   UTextOffset limit, 
  1880.                   const UnicodeString& srcText, 
  1881.                   UTextOffset srcStart, 
  1882.                   UTextOffset srcLimit)
  1883. { return doReplace(start, limit - start, srcText, srcStart, srcLimit - srcStart); }
  1884.  
  1885. inline UnicodeString& 
  1886. UnicodeString::findAndReplace(const UnicodeString& oldText,
  1887.                   const UnicodeString& newText)
  1888. { return findAndReplace(0, fLength, oldText, 0, oldText.fLength, 
  1889.             newText, 0, newText.fLength); }
  1890.  
  1891. inline UnicodeString& 
  1892. UnicodeString::findAndReplace(UTextOffset start,
  1893.                   int32_t length,
  1894.                   const UnicodeString& oldText,
  1895.                   const UnicodeString& newText)
  1896. { return findAndReplace(start, length, oldText, 0, oldText.fLength, 
  1897.             newText, 0, newText.fLength); }
  1898.  
  1899. inline UnicodeString& 
  1900. UnicodeString::findAndReplace(UTextOffset start,
  1901.                   int32_t length,
  1902.                   const UnicodeString& oldText,
  1903.                   UTextOffset oldStart,
  1904.                   int32_t oldLength,
  1905.                   const UnicodeString& newText,
  1906.                   UTextOffset newStart,
  1907.                   int32_t newLength)
  1908. {
  1909.   UTextOffset pos;
  1910.  
  1911.   for(UTextOffset i = start; i < start + length; ++i) {
  1912.     pos = indexOf(oldText, oldStart, oldLength, i, length - i + start);
  1913.     if(pos != -1) {
  1914.       replace(pos, oldLength, newText, newStart, newLength);
  1915.       i += newLength;
  1916.     }
  1917.   }
  1918.  
  1919.   return *this;
  1920. }
  1921.  
  1922. // ============================
  1923. // extract
  1924. // ============================
  1925. inline void
  1926. UnicodeString::doExtract(UTextOffset start,
  1927.              int32_t length,
  1928.              UnicodeString& target) const
  1929. { target.replace(0, target.fLength, *this, start, length); }
  1930.  
  1931. inline void  
  1932. UnicodeString::extract(UTextOffset start, 
  1933.                int32_t length, 
  1934.                UChar *dst, 
  1935.                UTextOffset dstStart) const
  1936. { doExtract(start, length, dst, dstStart); }
  1937.  
  1938. inline void 
  1939. UnicodeString::extract(UTextOffset start,
  1940.                int32_t length,
  1941.                UnicodeString& target) const
  1942. { doExtract(start, length, target); }
  1943.  
  1944. inline void  
  1945. UnicodeString::extractBetween(UTextOffset start, 
  1946.                   UTextOffset limit, 
  1947.                   UChar *dst, 
  1948.                   UTextOffset dstStart) const
  1949. { doExtract(start, limit - start, dst, dstStart); }
  1950.  
  1951. inline void 
  1952. UnicodeString::extractBetween(UTextOffset start,
  1953.                   UTextOffset limit,
  1954.                   UnicodeString& target) const
  1955. { doExtract(start, limit - start, target); }
  1956.  
  1957. inline UChar
  1958. UnicodeString::doCharAt(UTextOffset offset) const
  1959. {
  1960.   if(offset < 0 || offset >= fLength) 
  1961.     return fgInvalidUChar;
  1962.   // in ref-counted implementation, first char is ref count
  1963.   return fArray[ fRefCounted ? offset + 1 : offset ];
  1964. }
  1965.  
  1966. inline UChar
  1967. UnicodeString::charAt(UTextOffset offset) const
  1968. { return doCharAt(offset); }
  1969.  
  1970. inline UChar
  1971. UnicodeString::operator[] (UTextOffset offset) const
  1972. { return doCharAt(offset); }
  1973.  
  1974. inline bool_t
  1975. UnicodeString::empty() const
  1976. { return fLength == 0; }
  1977.  
  1978. //========================================
  1979. // Read-only implementation methods
  1980. //========================================
  1981. inline int32_t  
  1982. UnicodeString::length() const
  1983. { return fLength; }
  1984.  
  1985. inline int32_t 
  1986. UnicodeString::hashCode() const
  1987. { return (fHashCode == kInvalidHashCode 
  1988.     ? ((UnicodeString*)this)->doHashCode() : fHashCode); }
  1989.  
  1990. //========================================
  1991. // Write alias methods
  1992. //========================================
  1993. inline UnicodeString& 
  1994. UnicodeString::operator= (UChar ch) 
  1995. { return doReplace(0, fLength, &ch, 0, 1); }
  1996.  
  1997. inline UnicodeString& 
  1998. UnicodeString::setTo(const UnicodeString& srcText, 
  1999.              UTextOffset srcStart, 
  2000.              int32_t srcLength)
  2001. { return doReplace(0, fLength, srcText, srcStart, srcLength); }
  2002.  
  2003. inline UnicodeString& 
  2004. UnicodeString::setTo(const UnicodeString& srcText)
  2005. { return doReplace(0, fLength, srcText, 0, srcText.fLength); }
  2006.  
  2007. inline UnicodeString& 
  2008. UnicodeString::setTo(const UChar *srcChars, 
  2009.              UTextOffset srcStart, 
  2010.              int32_t srcLength)
  2011. { return doReplace(0, fLength, srcChars, srcStart, srcLength); }
  2012.  
  2013. inline UnicodeString& 
  2014. UnicodeString::setTo(const UChar *srcChars,
  2015.              int32_t srcLength)
  2016. { return doReplace(0, fLength, srcChars, 0, srcLength); }
  2017.  
  2018. inline UnicodeString& 
  2019. UnicodeString::setTo(UChar srcChar)
  2020. { return doReplace(0, fLength, &srcChar, 0, 1); }
  2021.  
  2022. inline UnicodeString& 
  2023. UnicodeString::operator+= (UChar ch)
  2024. { return doReplace(fLength, 0, &ch, 0, 1); }
  2025.  
  2026. inline UnicodeString& 
  2027. UnicodeString::operator+= (const UnicodeString& srcText)
  2028. { return doReplace(fLength, 0, srcText, 0, srcText.fLength); }
  2029.  
  2030. inline UnicodeString& 
  2031. UnicodeString::append(const UnicodeString& srcText, 
  2032.               UTextOffset srcStart, 
  2033.               int32_t srcLength)
  2034. { return doReplace(fLength, 0, srcText, srcStart, srcLength); }
  2035.  
  2036. inline UnicodeString& 
  2037. UnicodeString::append(const UnicodeString& srcText)
  2038. { return doReplace(fLength, 0, srcText, 0, srcText.fLength); }
  2039.  
  2040. inline UnicodeString& 
  2041. UnicodeString::append(const UChar *srcChars, 
  2042.               UTextOffset srcStart, 
  2043.               int32_t srcLength)
  2044. { return doReplace(fLength, 0, srcChars, srcStart, srcLength); }
  2045.  
  2046. inline UnicodeString& 
  2047. UnicodeString::append(const UChar *srcChars,
  2048.               int32_t srcLength)
  2049. { return doReplace(fLength, 0, srcChars, 0, srcLength); }
  2050.  
  2051. inline UnicodeString& 
  2052. UnicodeString::append(UChar srcChar)
  2053. { return doReplace(fLength, 0, &srcChar, 0, 1); }
  2054.  
  2055. inline UnicodeString& 
  2056. UnicodeString::insert(UTextOffset start, 
  2057.               const UnicodeString& srcText, 
  2058.               UTextOffset srcStart, 
  2059.               int32_t srcLength)
  2060. { return doReplace(start, 0, srcText, srcStart, srcLength); }
  2061.  
  2062. inline UnicodeString& 
  2063. UnicodeString::insert(UTextOffset start, 
  2064.               const UnicodeString& srcText)
  2065. { return doReplace(start, 0, srcText, 0, srcText.fLength); }
  2066.  
  2067. inline UnicodeString& 
  2068. UnicodeString::insert(UTextOffset start, 
  2069.               const UChar *srcChars, 
  2070.               UTextOffset srcStart, 
  2071.               int32_t srcLength)
  2072. { return doReplace(start, 0, srcChars, srcStart, srcLength); }
  2073.  
  2074. inline UnicodeString& 
  2075. UnicodeString::insert(UTextOffset start, 
  2076.               const UChar *srcChars,
  2077.               int32_t srcLength)
  2078. { return doReplace(start, 0, srcChars, 0, srcLength); }
  2079.  
  2080. inline UnicodeString& 
  2081. UnicodeString::insert(UTextOffset start, 
  2082.               UChar srcChar)
  2083. { return doReplace(start, 0, &srcChar, 0, 1); }
  2084.  
  2085.  
  2086. inline UnicodeString& 
  2087. UnicodeString::remove(UTextOffset start, 
  2088.              int32_t length)
  2089. { return doReplace(start, length, 0, 0, 0); }
  2090.  
  2091. inline UnicodeString& 
  2092. UnicodeString::remove()
  2093. { return doReplace(0, fLength, 0, 0, 0); }
  2094.  
  2095. inline UnicodeString& 
  2096. UnicodeString::removeBetween(UTextOffset start,
  2097.                 UTextOffset limit)
  2098. { return doReplace(start, limit - start, 0, 0, 0); }
  2099.  
  2100. inline bool_t 
  2101. UnicodeString::padLeading(int32_t targetLength,
  2102.               UChar padChar)
  2103. {
  2104.   if(fLength >= targetLength)
  2105.     return FALSE;
  2106.   else {
  2107.     int32_t len = fLength;
  2108.     for(int32_t i = 0; i < targetLength - len; ++i)
  2109.       doReplace(0, 0, &padChar, 0, 1);
  2110.     return TRUE;
  2111.   }
  2112. }
  2113.  
  2114. inline bool_t 
  2115. UnicodeString::padTrailing(int32_t targetLength,
  2116.                UChar padChar)
  2117. {
  2118.   if(fLength >= targetLength)
  2119.     return FALSE;
  2120.   else {
  2121.     int32_t len = fLength;
  2122.     for(int32_t i = 0; i < targetLength - len; ++i)
  2123.       doReplace(fLength, 0, &padChar, 0, 1);
  2124.     return TRUE;
  2125.   }
  2126. }
  2127.  
  2128. inline bool_t 
  2129. UnicodeString::truncate(int32_t targetLength)
  2130. {
  2131.   if(fLength < targetLength)
  2132.     return FALSE;
  2133.   else {
  2134.     doReplace(targetLength, fLength - targetLength, 0, 0, 0);
  2135.     return TRUE;
  2136.   }
  2137. }
  2138.  
  2139. inline UnicodeString& 
  2140. UnicodeString::trim()
  2141. {
  2142.   int32_t wsStart = 0;
  2143.   int32_t wsEnd = 0;
  2144.   UTextOffset start = 0;
  2145.   UTextOffset limit = fLength;
  2146.   UChar c = doCharAt(start);
  2147.  
  2148.   while(start < limit && 
  2149.     (c == 0x0020 || Unicode::getType(c) == Unicode::SPACE_SEPARATOR)) {
  2150.     ++wsStart;
  2151.     c = doCharAt(++start);
  2152.   }
  2153.  
  2154.   c = charAt(--limit);
  2155.   while(limit > start && 
  2156.     (c == 0x0020 || Unicode::getType(c) == Unicode::SPACE_SEPARATOR)) {
  2157.     ++wsEnd;
  2158.     c = doCharAt(--limit);
  2159.   }
  2160.  
  2161.   doReplace(0, wsStart, 0, 0, 0);
  2162.   doReplace(fLength - wsEnd, wsEnd, 0, 0, 0);
  2163.  
  2164.   return *this;
  2165. }
  2166.  
  2167. inline UnicodeString& 
  2168. UnicodeString::reverse()
  2169. { return doReverse(0, fLength); }
  2170.  
  2171. inline UnicodeString& 
  2172. UnicodeString::reverse(UTextOffset start,
  2173.                int32_t length)
  2174. { return doReverse(start, length); }
  2175.  
  2176.  
  2177. //========================================
  2178. // Write implementation methods
  2179. //========================================
  2180. inline bool_t 
  2181. UnicodeString::isBogus() const
  2182. { return fBogus; }
  2183.  
  2184.  
  2185. //========================================
  2186. // Privates
  2187. //========================================
  2188.  
  2189. inline UChar* 
  2190. UnicodeString::getArrayStart()
  2191. { return (fRefCounted ? fArray + 1 : fArray); }
  2192.  
  2193. inline const UChar* 
  2194. UnicodeString::getArrayStart() const
  2195. { return (fRefCounted ? fArray + 1 : fArray); }
  2196.  
  2197. inline int32_t 
  2198. UnicodeString::getCapacity() const
  2199. { return (fRefCounted ? fCapacity - 1 : fCapacity); }
  2200.  
  2201. inline uint16_t
  2202. UnicodeString::addRef()
  2203. { return ++(fArray[0]); }
  2204.  
  2205. inline uint16_t
  2206. UnicodeString::removeRef()
  2207. { return --(fArray[0]); }
  2208.  
  2209. inline uint16_t
  2210. UnicodeString::refCount() const
  2211. { return fArray[0]; }
  2212.  
  2213. inline uint16_t
  2214. UnicodeString::setRefCount(uint16_t count)
  2215. { fRefCounted = TRUE; return (fArray[0] = count); }
  2216.  
  2217.  
  2218. // deprecated API - remove later
  2219. inline int32_t
  2220. UnicodeString::size() const
  2221. { return fLength; }
  2222.  
  2223. inline const UChar*
  2224. UnicodeString::getUniChars() const
  2225. { return getUChars(); }
  2226.  
  2227. inline UnicodeString& 
  2228. UnicodeString::findAndReplace(const UnicodeString& oldText,
  2229.                   const UnicodeString& newText,
  2230.                   UTextOffset start,
  2231.                   int32_t length)
  2232. { return findAndReplace(start, length, oldText, newText); }
  2233.  
  2234. inline void*
  2235. UnicodeString::operator new(size_t size)
  2236. { return ::operator new(size); }
  2237.  
  2238. inline void* 
  2239. UnicodeString::operator new(size_t size, 
  2240.               void *location)
  2241. { return location; }
  2242.  
  2243. inline void
  2244. UnicodeString::operator delete(void *location)
  2245. { ::operator delete(location); }
  2246.  
  2247.  
  2248. //========================================
  2249. // Static members
  2250. //========================================
  2251. inline int32_t
  2252. UnicodeString::allocation(int32_t minSize)
  2253. { return minSize < kGrowSize ? kGrowSize 
  2254.     : (minSize * 2 + kGrowSize) & ~(kGrowSize - 1); }
  2255.  
  2256. inline UChar*
  2257. UnicodeString::allocate(int32_t minSize, int32_t& actualSize)
  2258. { actualSize = allocation(minSize); return new UChar[ actualSize ]; }
  2259.  
  2260. //========================================
  2261. // class UCharReference
  2262. //========================================
  2263. class UCharReference
  2264. {
  2265. public:
  2266.   UCharReference();
  2267.   inline UCharReference(UnicodeString *string,
  2268.          UTextOffset pos);
  2269.   inline UCharReference(const UCharReference& that);
  2270.   ~UCharReference();
  2271.  
  2272.   inline UCharReference& operator= (const UCharReference& that);
  2273.   inline UCharReference& operator= (UChar c);
  2274.  
  2275.   inline operator UChar();
  2276.  
  2277. private:
  2278.   UnicodeString *fString;
  2279.   UTextOffset fPos;
  2280. };
  2281.  
  2282.  
  2283. //========================================
  2284. // Inline members
  2285. //========================================
  2286. inline
  2287. UCharReference::UCharReference(UnicodeString *string, 
  2288.                    UTextOffset pos)
  2289.   : fString(string), fPos(pos)
  2290. {}
  2291.  
  2292. inline
  2293. UCharReference::UCharReference(const UCharReference& that)
  2294. { this->operator=(that); }
  2295.  
  2296. inline
  2297. UCharReference::~UCharReference()
  2298. {}
  2299.  
  2300. inline UCharReference&
  2301. UCharReference::operator= (const UCharReference& that)
  2302. { fString->setCharAt(fPos, that.fString->charAt(that.fPos)); return *this; }
  2303.  
  2304. inline UCharReference& 
  2305. UCharReference::operator= (UChar c)
  2306. { fString->setCharAt(fPos, c); return *this; }
  2307.  
  2308. inline
  2309. UCharReference::operator UChar()
  2310. { return fString->charAt(fPos); }
  2311.  
  2312. #endif
  2313.  
  2314.  
  2315.  
  2316.