mistring.h

Go to the documentation of this file.
00001 /**
00002  * \file mistring.h <mi32/mistring.h>
00003  * \brief MISTRING class definition
00004  *
00005  * \if NODOC
00006  * $Id: mistring.h_v 1.69 2004/06/01 16:16:54 mju Exp $
00007  *
00008  * $Log: mistring.h_v $
00009  * Revision 1.69  2004/06/01 16:16:54  mju
00010  * Add STR_Strip0 operation enum.
00011  *
00012  * Revision 1.68  2004/03/31 21:31:52  dwilliss
00013  * Added Split and Join methods
00014  *
00015  * Revision 1.67  2004/02/16 20:58:28  mju
00016  * Warn on deprecated usage.
00017  *
00018  * Revision 1.66  2003/09/25 21:29:07  dwilliss
00019  * Don't capitalize enum any more. Genitor needed it, doxygen doesn't like it.
00020  *
00021  * Revision 1.65  2003/09/15 13:49:56  fileserver!dwilliss
00022  * Doxygen
00023  *
00024  * Revision 1.64  2003/09/10 16:24:11  dwilliss
00025  * Don't do CHECKSIZE on 64-bit platforms because padding causes it to fail
00026  *
00027  * Revision 1.63  2003/09/03 15:21:15  mju
00028  * Add static GetEmpty method.
00029  *
00030  * Revision 1.62  2003/08/15 21:10:19  mju
00031  * Add ctor/op= from STRUTF8.
00032  *
00033  * Revision 1.61  2003/07/02 20:11:59  mju
00034  * Exclude textid methods when building static library for Windows.
00035  *
00036  * Revision 1.60  2003/06/30 16:03:19  mju
00037  * Remove legacy mttext method.
00038  *
00039  * Revision 1.59  2003/05/05 15:22:00  mju
00040  * Remove format specifier parm from ctors from numerics.
00041  * Add << operators for INT64 and UINT64.
00042  * Add STR_FillD and indicate it is default.
00043  *
00044  * Revision 1.58  2003/01/28 16:42:00  mju
00045  * Add STR_FillSubs.
00046  *
00047  * Revision 1.56  2002/11/15 15:43:15  mju
00048  * Add Check/SetLineTermination.
00049  *
00050  * Revision 1.55  2002/10/16 17:01:09  mju
00051  * Add ConvertToDouble.
00052  *
00053  * Revision 1.54  2002/09/09 16:35:32  mju
00054  * Remove retired varargs methods.
00055  *
00056  * Revision 1.53  2002/09/03 21:02:11  mju
00057  * Allow implicit construction from TEXTID.
00058  *
00059  * Revision 1.52  2002/06/28 15:58:26  dwilliss
00060  * Oops.  Search methods should be const
00061  *
00062  * Revision 1.51  2002/06/28 15:46:04  dwilliss
00063  * Added Search methods
00064  *
00065  * Revision 1.50  2002/05/30 22:11:08  mju
00066  * Remove varargs methods unless building mistring module itself.
00067  *
00068  * Revision 1.49  2002/05/21 13:24:39  mju
00069  * Add STR_Pad formatting helper.
00070  *
00071  * Revision 1.48  2002/05/17 15:35:47  dwilliss
00072  * Don't leave dangling commas on the last item of an enum
00073  *
00074  * Revision 1.47  2002/05/16 16:24:11  dwilliss
00075  * Don't bother with the CHECKSIZE on SGI for now.  It fails but we don't care
00076  * because we don't use shared libs there
00077  *
00078  * Revision 1.46  2002/05/14 14:33:30  dwilliss
00079  * Changed checksize use to not expect sizeof(int) == sizeof(void*).  It's not
00080  * on the SGI any more
00081  *
00082  * Revision 1.45  2002/05/13 16:35:13  mju
00083  * Remove non-const array operators.
00084  * Add Replace method for single character.
00085  *
00086  * Revision 1.44  2002/04/09 13:05:58  mju
00087  * Fix parameter type.
00088  *
00089  * Revision 1.43  2002/04/08 20:44:26  mju
00090  * Add STR_Fill, STR_Precision, STR_Width formatting helpers.
00091  *
00092  * Revision 1.42  2002/04/08 17:50:35  mju
00093  * Add STR_FillA/B.
00094  *
00095  * Revision 1.41  2002/04/04 16:43:58  mju
00096  * Add STR_OP values to set bool format.
00097  *
00098  * Revision 1.40  2002/04/03 21:08:14  mju
00099  * Note that width setting only applies to one value.
00100  *
00101  * Revision 1.39  2002/04/03 17:05:43  mju
00102  * Change one of private 'dummy' members back to 'm_string' so can see string contents in debugger.
00103  *
00104  * Revision 1.38  2002/04/02 14:31:43  mju
00105  * Add STR_OPs for Fill and Width.
00106  *
00107  * Revision 1.37  2002/03/29 17:29:39  mju
00108  * Add STR_OP enum and << operator to support.
00109  *
00110  * Revision 1.36  2002/03/28 22:38:40  mju
00111  * Add FmtSet methods.
00112  *
00113  * Revision 1.34  2002/03/27 16:55:25  mju
00114  * Deprecate variable-argument methods.
00115  *
00116  * Revision 1.33  2002/03/26 21:16:52  mju
00117  * Add FmtEnableSubstitution and FmtSetPrecision.
00118  *
00119  * Revision 1.32  2002/03/26 17:48:52  mju
00120  * Move private members into private class pointer.
00121  * Support TEXTID.
00122  *
00123  * Revision 1.31  2002/03/25 21:54:58  mju
00124  * Add operator<<'s.
00125  *
00126  * Revision 1.28  2001/08/17 21:42:21  dwilliss
00127  * Added an Insert method
00128  *
00129  * Revision 1.27  2001/06/29 20:23:32  scowan
00130  * Added sub string comapre and compare no case methods.
00131  *
00132  * Revision 1.26  2001/05/23 20:29:10  scowan
00133  * Nothing.
00134  *
00135  * Revision 1.25  2001/02/15 21:23:37  scowan
00136  * Added ini read/write ML methods.
00137  *
00138  * Revision 1.24  2000/12/04 16:31:36  mju
00139  * Fix genitor 'end ignore' tag.
00140  *
00141  * Revision 1.23  2000/11/22 22:46:14  scowan
00142  * Added assign method from unicode strings.
00143  *
00144  * Revision 1.22  2000/10/13 16:44:13  dwilliss
00145  * Added array operator overloads taking long on Mac only to avoid stupid
00146  * ambiguous function overload error
00147  *
00148  * Revision 1.21  2000/08/16 16:56:40  mju
00149  * Add ctor from msg group/key.
00150  *
00151  * Revision 1.20  2000/07/11 17:35:28  mju
00152  * Undef CLASSLIBEXPORT at end.
00153  *
00154  * Revision 1.19  2000/07/07 15:12:49  dwilliss
00155  * Export MISTRINGLIST too
00156  *
00157  * Revision 1.18  2000/07/07 14:13:28  dwilliss
00158  * Use #pragma export to export class methods on the Macintosh
00159  *
00160  * Revision 1.17  2000/07/06 13:22:15  mju
00161  * Add AppendMsg/V.
00162  *
00163  * Revision 1.16  2000/06/26 21:17:32  mju
00164  * Change docs for Sprintf methods.
00165  *
00166  * Revision 1.12  2000/05/03 22:10:37  mju
00167  * Update docs for Genitor.
00168  *
00169  * Revision 1.11  2000/04/19 21:31:17  shovland
00170  * clarify "end" parameter of Replace method
00171  *
00172  * Revision 1.4  1999/11/15 16:20:53  scowan
00173  * Updated for DLL use and added many new methods.
00174  *
00175  * Revision 1.3  1999/10/20 14:29:03  mju
00176  * Initial implementation completed.
00177  *
00178  * Revision 1.2  1999/10/01  21:38:44  mju
00179  * Make more methods inline.
00180  *
00181  * Revision 1.1  1999/10/01  16:41:34  mju
00182  * Initial revision
00183  * \endif
00184 **/
00185 
00186 #ifndef  INC_MI32_MISTRING_H
00187 #define  INC_MI32_MISTRING_H
00188 
00189 #ifndef INC_MI32_UCSTRING_H
00190 #include <mi32/ucstring.h>
00191 #endif
00192 
00193 #ifndef INC_MI32_MILIST_H
00194 #include <mi32/milist.h>
00195 #endif
00196 
00197 #include <mi32/stdansic.h>
00198 
00199 #ifdef MISYSTEMDLL
00200    #define CLASSLIBEXPORT MI_DLLCLASSEXPORT
00201 #else
00202    #define CLASSLIBEXPORT MI_DLLCLASSIMPORT
00203 #endif
00204 
00205 
00206 #ifndef GENERATING_DOXYGEN_OUTPUT
00207 class STRUTF8;
00208 class UCREGEXP;
00209 #endif //!< GENERATING_DOXYGEN_OUTPUT
00210 
00211 
00212 //! Convenience MISTRING operation and formatting enumerations for use with << operator.
00213 enum STR_OP {
00214    STR_Clear = 0,             //!< Clear the string
00215    STR_BoolL = 1,             //!< Format bool as localized no/yes (default)
00216    STR_BoolM = 2,             //!< Format bool as localized No/Yes
00217    STR_BoolU = 3,             //!< Format bool as localized NO/YES
00218    STR_FillA = 4,             //!< Fill/pad AFTER value if width more than needed
00219    STR_FillB = 5,             //!< Fill/pad BEFORE value if width more than needed
00220    STR_FillD = 6,             //!< Fill/pad default (after strings, before numerics) (default)
00221    STR_Strip0 = 9,            //!< Strip trailing 0's after decimal point for next formatted value ('fixed' and 'general')
00222    STR_FillSubs = 10,         //!< Fill substitution placeholders with '???' to avoid unwanted formatting.
00223    STR_FltE = 11,             //!< Set floating format to 'exponential'
00224    STR_FltF = 12,             //!< Set floating format to 'fixed'
00225    STR_FltG = 13,             //!< Set floating format to 'general'
00226    STR_Bin = 14,              //!< Set integer base to 'binary' (2)
00227    STR_Dec = 15,              //!< Set integer base to 'decimal' (10)
00228    STR_Hex = 16,              //!< Set integer base to 'hexadecimal' (16)
00229    STR_FillSp = 17,           //!< Set fill character to ' ' (space)
00230    STR_Fill0 = 18,            //!< Set fill character to '0'
00231    STR_PrecA = 19,            //!< Set floating precision to 'automatic'
00232    STR_Prec0 = 20,            //!< Set floating precision to 0
00233    STR_Prec1 = 21,            //!< Set floating precision to 1
00234    STR_Prec2 = 22,
00235    STR_Prec3 = 23,
00236    STR_Prec4 = 24,
00237    STR_Prec5 = 25,
00238    STR_Prec6 = 26,
00239    STR_Prec7 = 27,
00240    STR_Prec8 = 28,
00241    STR_Prec9 = 29,
00242    STR_Prec10 = 30,
00243    STR_Prec11 = 31,
00244    STR_Prec12 = 32,
00245    STR_Prec13 = 33,
00246    STR_Prec14 = 34,
00247    STR_Prec15 = 35,
00248    STR_Prec16 = 36,           //!< Set floating precision to 16
00249    STR_Width0 = 40,           //!< Set width to minimum
00250    STR_Width1 = 41,           //!< Set minimum width to 1 for next formatted value only
00251    STR_Width2 = 42,           //!< Set minimum width to 2 for next formatted value only
00252    STR_Width3 = 43,
00253    STR_Width4 = 44,
00254    STR_Width5 = 45,
00255    STR_Width6 = 46,
00256    STR_Width7 = 47,
00257    STR_Width8 = 48,
00258    STR_Width9 = 49,
00259    STR_Width10 = 50,
00260    STR_Width11 = 51,
00261    STR_Width12 = 52,
00262    STR_Width13 = 53,
00263    STR_Width14 = 54,
00264    STR_Width15 = 55
00265    };
00266 
00267 
00268 //! General string class.
00269 //! Supports internationalization, Unicode and various character set encodings.
00270 //!
00271 //! MISTRING supports use of '<<' to 'put' values into the string similar to iostream.
00272 //! When using '<<' the current MISTRING is first searched for a formatting code or
00273 //! a substitution placeholder.  Formatting codes in the form %d, %s, %f, etc. are
00274 //! searched for first.  The first code compatible with the value being put into
00275 //! the string will be used.  Thus, if a number is being put then any %d, %u, %f,
00276 //! etc code will be used.  These formatting codes can also specify the width and
00277 //! precision if desired.  Thus, '%.8f' may be used to specify 8 decimal places of
00278 //! precision.  These settings only apply to the current value being put into the
00279 //! string.  If no width, precision, etc is specified then any previously set formatting
00280 //! state settings will apply.  If no %-style formatting code is found then a search
00281 //! is made for substitution placeholders in the form $1, $2, etc.  The lowest numbered
00282 //! placeholder will be replaced with the value being put into the string.  Finally,
00283 //! if no placeholder is found then the value being put will be appended to the end of
00284 //! the string.
00285 class CLASSLIBEXPORT MISTRING {
00286    public:
00287 
00288       enum FLOATFMT {
00289          FLOATFMT_General =      0,    //!< General (equivalent to "%G")
00290          FLOATFMT_Fixed =        1,    //!< Fixed (equivalent to "%f")
00291          FLOATFMT_Scientific =   2     //!< Scientific (equivalent to "%E")
00292          };
00293 
00294       enum LINETERM {
00295          LINETERM_LF =           0,    //!< Terminate lines with '\\n'
00296          LINETERM_CR =           1,    //!< Terminate lines with '\\r'
00297          LINETERM_CRLF =         2     //!< Terminate lines with '\\r\\n'
00298          };
00299 
00300       //! Default constructor.
00301       MISTRING (
00302          );
00303 
00304       //! Copy constructor.
00305       MISTRING (
00306          const MISTRING& rhs
00307          );
00308 
00309       //! Construct from UNICODE* string (implicit).
00310       MISTRING (
00311          const UNICODE *ustr
00312          );
00313       
00314       //! Construct from char* string.
00315       explicit MISTRING (
00316          const char *str
00317          );
00318 
00319       //! Construct from STRUTF8 string (implicit).
00320       MISTRING (
00321          const STRUTF8& rhs
00322          );
00323 
00324    #ifndef NODLLLINKAGE
00325       //! Construct from TEXTID (implicit).
00326       MISTRING (
00327          TEXTID textid                       //!< Messsage text ID
00328          );
00329    #endif
00330 
00331    #if !defined(DEPRECATE_GROUPKEY) || defined(MISTRING_DLL)
00332       //! Construct from message file group and key.
00333       //! Deprecated, use TEXTID instead.
00334       DEPRECATED MISTRING (
00335          const char *msggroup,               //!< Message file group
00336          const char *msgkey                  //!< Message file key
00337          );
00338    #endif
00339 
00340    #if 0    // Systems where wchar_t is not same as UINT16(UNICODE)
00341       #ifndef GENERATING_DOXYGEN_OUTPUT
00342       //! Construct from wchar_t* string using Unicode encoding.
00343       explicit MISTRING (
00344          const wchar_t *str
00345          );
00346       #endif //!< GENERATING_DOXYGEN_OUTPUT
00347    #endif
00348 
00349       //! Construct from string in specified encoding.
00350       MISTRING (
00351          const void *str,
00352          CHAR_ENCODING encoding
00353          );
00354 
00355       //! Construct from integer with default formatting.
00356       explicit MISTRING (
00357          int value
00358          );
00359 
00360       //! Construct from unsigned integer with default formatting.
00361       explicit MISTRING (
00362          unsigned int value
00363          );
00364 
00365       //! Construct from floating-point with default formatting.
00366       explicit MISTRING (
00367          double value
00368          );
00369 
00370       ~MISTRING (
00371          );
00372 
00373       //! Assignment from MISTRING.
00374       MISTRING& operator= (
00375          const MISTRING& rhs
00376          );
00377 
00378       //! Assignment from STRUTF8.
00379       MISTRING& operator= (
00380          const STRUTF8& rhs
00381          );
00382 
00383    #ifndef NODLLLINKAGE
00384       //! Assignment from TEXTID.
00385       MISTRING& operator= (
00386          TEXTID textid
00387          );
00388    #endif
00389 
00390       //! Assignment from UNICODE* string.
00391       MISTRING& operator= (
00392          const UNICODE* rhs
00393          );
00394 
00395       //! Assignment from char* (ASCII/ISO-Latin1).
00396       MISTRING& operator= (
00397          const char* rhs
00398          );
00399 
00400    #if 0    //!< Systems where wchar_t is not same as UINT16(UNICODE)
00401       #ifndef GENERATING_DOXYGEN_OUTPUT
00402       //! Assignment from wchar_t* using Unicode encoding.
00403       MISTRING& operator= (
00404          const wchar_t* rhs
00405          );
00406       #endif //!< GENERATING_DOXYGEN_OUTPUT
00407    #endif
00408 
00409       //! Concatenation from MISTRING.
00410       MISTRING& operator+= (
00411          const MISTRING& rhs
00412          );
00413 
00414       //! Concatenation from UNICODE* string.
00415       MISTRING& operator+= (
00416          const UNICODE* rhs
00417          );
00418 
00419       //! Concatenation from char* (ASCII/ISO-Latin1).
00420       MISTRING& operator+= (
00421          const char* rhs
00422          );
00423 
00424    #if 0    // Systems where wchar_t is not same as UINT16(UNICODE)
00425       #ifndef GENERATING_DOXYGEN_OUTPUT
00426       //! Concatenation from wchar_t* using Unicode encoding
00427       MISTRING& operator+= (
00428          const wchar_t* rhs
00429          );
00430       #endif //!< GENERATING_DOXYGEN_OUTPUT
00431    #endif
00432 
00433       //! Append single character (Unicode or ASCII).
00434       MISTRING& operator+= (
00435          UNICODE c
00436          );
00437 
00438       //! Perform operation on string.
00439       MISTRING& operator<< (STR_OP op);
00440 
00441       //! Format and put 'bool' value into string.
00442       MISTRING& operator<< (bool b);
00443 
00444       //! Format and put single character into string.
00445       MISTRING& operator<< (char c);
00446 
00447       //! Format and put INT8 (signed char) numeric value into string.
00448       MISTRING& operator<< (signed char n);
00449 
00450       //! Format and put UINT8 (unsigned char) numeric value into string.
00451       MISTRING& operator<< (unsigned char n);
00452 
00453       //! Format and put INT16 (short) value into string.
00454       MISTRING& operator<< (short n);
00455 
00456       //! Format and put INT32 (int) value into string.
00457       MISTRING& operator<< (int n);
00458 
00459       //! Format and put (long) value into string.
00460       MISTRING& operator<< (long n);
00461 
00462    #ifndef LONGS_ARE_64_BIT
00463       //! Format and put (INT64) value into string.
00464       MISTRING& operator<< (INT64 n);
00465    #endif
00466 
00467       //! Format and put UINT16 (unsigned short) value into string.
00468       //! Warning, use of UNICODE will result in numeric value being put into string.
00469       MISTRING& operator<< (unsigned short n);
00470 
00471       //! Format and put UINT32 (unsigned int) value into string.
00472       MISTRING& operator<< (unsigned int n);
00473 
00474       //! Format and put (unsigned long) value into string.
00475       MISTRING& operator<< (unsigned long n);
00476 
00477    #ifndef LONGS_ARE_64_BIT
00478       //! Format and put (UINT64) value into string.
00479       MISTRING& operator<< (UINT64 n);
00480    #endif
00481 
00482       //! Format and put (float) value into string.
00483       MISTRING& operator<< (float f);
00484 
00485       //! Format and put (double) value into string.
00486       MISTRING& operator<< (double f);
00487 
00488       //! Format and put ASCII string into string.
00489       MISTRING& operator<< (const char *s);
00490 
00491       //! Format and put UNICODE string into string.
00492       MISTRING& operator<< (const UNICODE *s);
00493 
00494    #ifndef NODLLLINKAGE
00495       //! Format and text from TEXTID put into string.
00496       MISTRING& operator<< (TEXTID textid);
00497    #endif
00498 
00499       //! Read array element.
00500       const UNICODE& operator[] (
00501          int idx
00502          ) const;
00503 
00504       //! Cast to (const UNICODE *).
00505       //! Cast to non-const is not supported as destruction cannot be enforced for temporaries.
00506       //! Cast to UINT8* or char* is not permitted as encoding cannot be specified.
00507       operator const UNICODE* (
00508          ) const;
00509 
00510       //! Append from MISTRING.
00511       void Append (
00512          const MISTRING& str,                //!< String to append
00513          int start = 0,                      //!< Starting position in 'str' to append to this string
00514          int end = INT32_MAX                 //!< Ending position in 'str' to append to this string
00515          );
00516 
00517       //! Assign from MISTRING.
00518       void Assign (
00519          const MISTRING& str,                //!< Buffer holding MISTRING
00520          int start = 0,                      //!< Starting position in 'str' to assign to this string
00521          int end = INT32_MAX                 //!< Ending position in 'str' to assign to this string
00522          );
00523 
00524       //! Assign from UNICODE string.
00525       void Assign (
00526          const UNICODE *str,                 //!< Buffer holding UNICODE string
00527          int start = 0,                      //!< Starting position in 'str' to assign to this string
00528          int end = INT32_MAX                 //!< Ending position in 'str' to assign to this string
00529          );
00530 
00531       //! Assign from string in specified encoding.
00532       //! Assign from partial char string is not supported due to character encoding
00533       void Assign (
00534          const void *str,                    //!< Buffer holding appropriately-terminated string
00535          CHAR_ENCODING encoding              //!< Encoding of string
00536          );
00537 
00538       //! Determine if string consistently uses specified line termination.
00539       //! @return true if specified termination used, false if not.
00540       bool CheckLineTermination (
00541          LINETERM lineterm                   //!< Line termination
00542          ) const;
00543 
00544       //! Clear the string.
00545       void Clear (
00546          );
00547 
00548       //! Case-sensitive comparison (similar to strcmp).
00549       //! @return 0 if strings equal, -1 if this < str, 1 if this > str.
00550       int Compare (
00551          const MISTRING& str                 //!< String to compare to
00552          ) const;
00553 
00554       //! Case-sensitive comparison, length limited (similar to strncmp).
00555       //! @return 0 if strings equal, -1 if this < str, 1 if this > str.
00556       int Compare (
00557          const MISTRING& str,                //!< String to compare to
00558          int len                             //!< Maximum number of characters to compare
00559          ) const;
00560 
00561       //! Case-sensitive comparison, length limited (similar to strncmp).
00562       //! @return 0 if strings equal, -1 if this < str, 1 if this > str.
00563       int Compare (
00564          int SrcStart,                       //!< Start position of 'this' string
00565          const MISTRING& str,                //!< String to compare to
00566          int OtherStart,                     //!< Start position of 'str'
00567          int len                             //!< Maximum number of characters to compare
00568          ) const;
00569 
00570       //! Case-insensitive comparison (similar to stricmp).
00571       //! @return 0 if strings equal, -1 if this < str, 1 if this > str.
00572       int CompareNoCase (
00573          const MISTRING& str                 //!< String to compare to
00574          ) const;
00575 
00576       //! Case-insensitive comparison, length limited (similar to strnicmp).
00577       //! @return 0 if equal, -1 if this < str, 1 if this > str.
00578       int CompareNoCase (
00579          const MISTRING& str,                //!< String to compare to
00580          int len                             //!< Maximum number of characters to compare
00581          ) const;
00582 
00583       //! Case-insensitive comparison, length limited (similar to strnicmp).
00584       //! @return 0 if equal, -1 if this < str, 1 if this > str.
00585       int CompareNoCase (
00586          int SrcStart,                       //!< Start position of 'this' string
00587          const MISTRING& str,                //!< String to compare to
00588          int OtherStart,                     //!< Start position of 'str'
00589          int len                             //!< Maximum number of characters to compare
00590          ) const;
00591 
00592       //! Convert string to double-precision numeric value.
00593       //! @return Converted value or 0.0 if unable to convert.
00594       double ConvertToDouble (
00595          ) const;
00596 
00597       //! Find next occurrence in given set of characters (similar to strpbrk).
00598       //! @return Character position or -1 if not found.
00599       int FindNextInSet (
00600          const MISTRING& chars,              //!< Characters to search for
00601          int start = 0                       //!< Starting position, default is start of string
00602          ) const;
00603 
00604       //! Find next occurrence not in given set of characters.
00605       //! @return Character position or -1 if not found.
00606       int FindNextNotInSet (
00607          const MISTRING& chars,              //!< Characters to search for
00608          int start = 0                       //!< Starting position, default is start of string
00609          ) const;
00610 
00611       //! Find next occurrence of given string (similar to strstr).
00612       //! @return Starting position of substring or -1 if not found.
00613       int FindNextOf (
00614          const MISTRING& str,                //!< String to search for
00615          int start = 0                       //!< Starting position, default is start of string
00616          ) const;
00617 
00618       //! Find next occurrence of given character (similar to strchr).
00619       //! @return Position of character or -1 if not found.
00620       int FindNextOf (
00621          UNICODE c,                          //!< Character to search for
00622          int start = 0                       //!< Starting position, default is start of string
00623          ) const;
00624 
00625       //! Find previous occurrence in given set of characters.
00626       //! @return Position or -1 if not found.
00627       int FindPrevInSet (
00628          const MISTRING& chars,              //!< Characters to search for
00629          int start = INT32_MAX               //!< Starting position, default is end of string
00630          ) const;
00631 
00632       //! Find previous occurrence not in given set of characters.
00633       //! @return Position or -1 if not found.
00634       int FindPrevNotInSet (
00635          const MISTRING& chars,              //!< Characters to search for
00636          int start = INT32_MAX               //!< Starting position, default is end of string
00637          ) const;
00638 
00639       //! Find previous occurrence of given character (similar to strrchr).
00640       //! @return Position of character or -1 if not found.
00641       int FindPrevOf (
00642          UNICODE c,                          //!< Character to search for
00643          int start = INT32_MAX               //!< Starting position, default is end of string
00644          ) const;
00645 
00646       //! Enable substitution during formatting.
00647       //! Initial default is enabled.
00648       void FmtEnableSubstitution (
00649          bool enable = true                  //!< 'true' to enable, 'false' to disable
00650          );
00651 
00652       //! Set integer base.
00653       void FmtSetBase (
00654          int base                            //!< Integer base 2-36
00655          );
00656 
00657       //! Set fill character for padding.
00658       void FmtSetFill (
00659          UNICODE fill                        //!< Fill character
00660          );
00661 
00662       //! Set floating point formatting mode
00663       void FmtSetFloat (
00664          FLOATFMT floatmode                  //!< Floating point formatting mode
00665          );
00666 
00667       //! Set precision (number of decimal places) for floating-point output.
00668       void FmtSetPrecision (
00669          int precision                       //!< Floating-point precision
00670          );
00671 
00672       //! Set whether to shown sign for positive numbers.
00673       //! Sign is only shown if integer base is 10.
00674       void FmtSetSign (
00675          bool sign                           //!< True to show sign, false to not
00676          );
00677 
00678       //! Set minimum width for next formatted value.
00679       //! Note that at width setting only applies to one value after which
00680       //! time it will reset to 0 (minimum).
00681       void FmtSetWidth (
00682          int width                           //!< Minimum width
00683          );
00684 
00685       //! Get string in specified encoding.
00686       //! @return Encoded string caller must free.
00687       void *GetEncoded (
00688          CHAR_ENCODING encoding              //!< Encoding
00689          ) const;
00690 
00691       //! Get reference to empty string.
00692       static const MISTRING& GetEmpty (
00693          );
00694 
00695       //! Get length in characters.
00696       //! @return Length in characters.
00697       int GetLength (
00698          ) const;
00699 
00700       //! Get string reference.  Used to avoid static_cast<const UNICODE*>(MISTRING).
00701       //! @return Pointer to internal string, do not free!
00702       const UNICODE *GetReference (
00703          ) const;
00704 
00705       //! Get allocated string.
00706       //! @return Pointer to string, caller must free
00707       UNICODE *GetString (
00708          ) const;
00709 
00710       //! Retrieve sub-string.
00711       //! @return Substring from position to end of string.
00712       MISTRING GetSubString (
00713          int start                           //!< Starting position
00714          ) const;
00715 
00716       //! Retrieve sub-string.
00717       //! @return Substring from position up to specified length.
00718       MISTRING GetSubString (
00719          int start,                          //!< Starting position
00720          int end                             //!< Ending position (inclusive)
00721          ) const;
00722 
00723       //! Read string from .ini file.
00724       //! @return true if entry in file, false if not
00725       bool IniRead (
00726          INIHANDLE handle,                   //!< Ini Handle created by IniOpen()
00727          const char *group,                  //!< Group to look for ini entry, App Name if =0
00728          const char *field                   //!< Field to read string from
00729          );
00730 
00731       //! Read multi-line string from .ini file.
00732       //! @return true if entry in file, false if not
00733       bool IniReadML (
00734          INIHANDLE handle,                   //!< Ini Handle created by IniOpen()
00735          const char *group,                  //!< Group to look for ini entry, App Name if =0
00736          const char *field                   //!< Field to read string from
00737          );
00738 
00739       //! Write string to .ini file.
00740       void IniWrite (
00741          INIHANDLE handle,                   //!< Ini Handle created by IniOpen()
00742          const char *group,                  //!< Group to write ini entry, App Name if =0
00743          const char *field                   //!< Field to write string to
00744          ) const;
00745 
00746       //! Write multi-line string to .ini file.
00747       void IniWriteML (
00748          INIHANDLE handle,                   //!< Ini Handle created by IniOpen()
00749          const char *group,                  //!< Group to write ini entry, App Name if =0
00750          const char *field                   //!< Field to write string to
00751          ) const;
00752 
00753       //! Determine if string is empty.
00754       //! @return true if string is empty, false if not.
00755       bool IsEmpty (
00756          ) const;
00757 
00758       //! Insert all or part of another string at specified position.
00759       void Insert (
00760          int start,                          //!< Position to insert before
00761          const MISTRING& str,                //!< String to insert
00762          int strstart = 0,                   //!< Start of replace string
00763          int strend = INT32_MAX              //!< End of replace string
00764          );
00765 
00766 
00767       //! Join all the strings in an MISTRINGLIST into one string
00768       void Join (
00769          const MILIST<MISTRING>& list,
00770          const UNICODE* sep
00771          );
00772 
00773       //! Join all the strings in an MISTRINGLIST into one string
00774       //! The char* variant of this function exists because most often, you
00775       //! want to join the strings together with simple whitespace or commas.
00776       void Join (
00777          const MILIST<MISTRING>& list,
00778          const char* sep = ""
00779          );
00780 
00781       //! Pad with specified character.
00782       void Pad (
00783          UNICODE c,                          //!< Character to pad with
00784          int numchars                        //!< Number of characters to pad
00785          );
00786 
00787       //! Pad with specified character to given length.
00788       void PadToLength (
00789          UNICODE c,                          //!< Character to pad with
00790          int length                          //!< Length to pad to
00791          );
00792 
00793       //! Remove a section of the string.
00794       void Remove (
00795          int start,                          //!< Starting index to remove sub-string
00796          int end                             //!< Ending index to remove sub-string
00797          );
00798 
00799       //! Replace single character at specified position.
00800       //! This cannot be used to truncate or extend the string, attempts to do so will be ignored.
00801       void Replace (
00802          int index,                          //!< Index from start of string, must be from 0 to GetLength()-1
00803          UNICODE c                           //!< Character value to replace with, will ignore if 0
00804          );
00805 
00806       //! Replace a section of a string with another sub-string.
00807       void Replace (
00808          int start,                          //!< Start of string section to replace
00809          int end,                            //!< End of string section to replace
00810          const MISTRING& str,                //!< String to replace with
00811          int strstart = 0,                   //!< Start of replace string
00812          int strend = INT32_MAX              //!< End of replace string
00813          );
00814 
00815       //! Reserve enough memory for specified number of characters.
00816       ERRVALUE Reserve (
00817          int numchars                        //!< Number of characters
00818          );
00819 
00820       //! Search for a regular expression.
00821       //!
00822       //! Returns true if the given regular expression could be found,
00823       //! false if not.  MatchStart/MatchEnd values returned are only
00824       //! meaningful if a match was found.
00825       //! 
00826       //! If you plan to search multiple strings for the same expression,
00827       //! it's more effecient to use the version of Search that takes
00828       //! a reference to a UCREGEXP.
00829       //! 
00830       //! Note: If the string to search for is just a simple string, you're
00831       //! better off calling FindNextOf() instead.
00832       //!
00833       //! For details of RE syntax, see mi32/ucregexp.h or the documentation
00834       //! for the class UCREGEXP.
00835       bool Search (
00836          const UNICODE* str,        //!< Regular expression to search for
00837          UINT32& MatchStart,        //!< Start of match RETURNED
00838          UINT32& MatchEnd,          //!< End of match RETURNED
00839          bool bIgnoreCase = false,  //!< Ignore case if true
00840          UINT32 Start = 0           //!< Where to start in source string
00841          ) const;
00842       
00843       //! Search for a regular expression.
00844       //!
00845       //! Returns true if the given regular expression could be found,
00846       //! false if not.  MatchStart/MatchEnd values returned are only
00847       //! meaningful if a match was found.
00848       //! 
00849       //! Note, this version doesn't have the bIgnoreCase parameter because
00850       //! that is specified when you create the UCREGEXP that you pass in.
00851       //!
00852       //! For details of RE syntax, see mi32/ucregexp.h or the documentation
00853       //! for the class UCREGEXP.
00854       bool Search (
00855          const UCREGEXP& regex,     //!< Regular expression to search for
00856          UINT32& MatchStart,        //!< Start of match RETURNED
00857          UINT32& MatchEnd,          //!< End of match RETURNED
00858          UINT32 Start = 0           //!< Where to start in source string
00859          ) const;
00860       
00861       //! Set string to use specified line termination.
00862       //! Note, this does not affect future additions to the string.
00863       //! @return true if string changed, false if not.
00864       bool SetLineTermination (
00865          LINETERM lineterm                   //!< Line termination
00866          );
00867 
00868       //! Set all characters to lowercase.
00869       void SetLowerCase (
00870          int start = 0                       //!< Starting position to lowercase string
00871          );
00872 
00873       //! Set all characters to uppercase.
00874       void SetUpperCase (
00875          int start = 0                       //!< Starting position to uppercase string
00876          );
00877 
00878       //! Split a string up into a list of strings
00879       //!
00880       //! @param ch Delimiter
00881       //! @param list The list of strings returned
00882       //! @param maxitems The maximum number of items to split out.  If 0 (the
00883       //!   default), it will split all items.  
00884       //! @return number of strings in list 
00885       int Split (
00886          UNICODE ch,             
00887          MILIST<MISTRING>& list, 
00888          int maxitems = 0        
00889          ) const;
00890 
00891       //! Split a string up into a list of strings
00892       //!
00893       //! @param regexp Regular Expression to match delimiters
00894       //! @param list The list of strings returned
00895       //! @param maxitems The maximum number of items to split out.  If 0 (the
00896       //!   default), it will split all items.  
00897       //! @return number of strings in list 
00898       int Split (
00899          const UNICODE *regexp,              
00900          MILIST<MISTRING>& list, 
00901          int maxitems = 0        
00902          ) const;
00903 
00904       //! Truncate to specified number of characters.
00905       void Truncate (
00906          int length                          //!< Length to truncate to
00907          );
00908 
00909       #ifndef GENERATING_DOXYGEN_OUTPUT
00910       class PRIV;
00911       #endif //!< GENERATING_DOXYGEN_OUTPUT
00912 
00913    private:
00914       #ifndef GENERATING_DOXYGEN_OUTPUT
00915       static const UNICODE s_zero;        //!< Used when read array element out of range
00916       static UNICODE s_dummy;             //!< Used when write array element out of range
00917 
00918       const UNICODE *m_string;
00919       int dummy2;
00920       PRIV *m_pPriv;
00921 
00922       void GetExclusive ();
00923 
00924 #if !defined(SGI) && !defined(LONGS_ARE_64_BIT)
00925       //! This fails on SGI because it ends up padding between dummy2 and m_pPriv
00926       //! but we don't use shared libs there, so we don't care
00927       //! Also fails on any 64-bit platforms
00928       CHECKSIZE(sizeof(int) + 2*sizeof(void*));
00929 #endif
00930 
00931       friend class MISTRING::PRIV;
00932       #endif // GENERATING_DOXYGEN_OUTPUT
00933    };
00934 
00935 #if defined(WIN32)
00936 #if !defined(MISYSTEMDLL) && !defined(NODLLLINKAGE)
00937 #pragma warning(disable:4231) /* the extern before template is a non-standard extension */
00938 
00939 extern template class CLASSLIBEXPORT MILIST<MISTRING>;      //! Template instantiation
00940 
00941 #pragma warning(default:4231) /* restore previous warning */
00942 #endif      //!< _DLL
00943 #endif      //!< WIN32
00944 
00945 typedef MILIST<MISTRING> MISTRINGLIST;
00946 
00947 
00948 //! Concatenation of MISTRINGs.
00949 inline MISTRING operator+ (
00950    const MISTRING& lhs,
00951    const MISTRING& rhs
00952    ) {
00953    MISTRING result(lhs);
00954    result += rhs;
00955    return (result);
00956    }
00957 
00958 //! Equality.
00959 inline bool operator== (
00960    const MISTRING& lhs,
00961    const MISTRING& rhs
00962    ) {
00963    return (lhs.Compare(rhs) == 0);
00964    }
00965 
00966 //! Inequality.
00967 inline bool operator!= (
00968    const MISTRING& lhs,
00969    const MISTRING& rhs
00970    ) {
00971    return (lhs.Compare(rhs) != 0);
00972    }
00973 
00974 //! Less than.
00975 inline bool operator< (
00976    const MISTRING& lhs,
00977    const MISTRING& rhs
00978    ) {
00979    return (lhs.Compare(rhs) < 0);
00980    }
00981 
00982 //! Less than or equal.
00983 inline bool operator<= (
00984    const MISTRING& lhs,
00985    const MISTRING& rhs
00986    ) {
00987    return (lhs.Compare(rhs) <= 0);
00988    }
00989 
00990 //! Greater than.
00991 inline bool operator> (
00992    const MISTRING& lhs,
00993    const MISTRING& rhs
00994    ) {
00995    return (lhs.Compare(rhs) > 0);
00996    }
00997 
00998 //! Greater than or equal.
00999 inline bool operator>= (
01000    const MISTRING& lhs,
01001    const MISTRING& rhs
01002    ) {
01003    return (lhs.Compare(rhs) >= 0);
01004    }
01005 
01006 
01007 //! Formatting manipulators.
01008 
01009 #ifndef GENERATING_DOXYGEN_OUTPUT
01010 
01011 struct STR_FILL {
01012    UNICODE m_fill;
01013    STR_FILL (UNICODE fill) : m_fill(fill) { }
01014    };
01015 
01016 inline MISTRING& operator<< (
01017    MISTRING& lhs,
01018    const STR_FILL& rhs
01019    ) { lhs.FmtSetFill(rhs.m_fill); return (lhs); }
01020 
01021 struct STR_PAD {
01022    UNICODE m_c;
01023    int m_n;
01024    STR_PAD (UNICODE c, int n) : m_c(c), m_n(n) { }
01025    };
01026 
01027 inline MISTRING& operator<< (
01028    MISTRING& lhs,
01029    const STR_PAD& rhs
01030    ) { lhs.Pad(rhs.m_c,rhs.m_n); return (lhs); }
01031 
01032 struct STR_PREC {
01033    int m_precision;
01034    STR_PREC (int precision) : m_precision(precision) { }
01035    };
01036 
01037 inline MISTRING& operator<< (
01038    MISTRING& lhs,
01039    const STR_PREC& rhs
01040    ) { lhs.FmtSetPrecision(rhs.m_precision); return (lhs); }
01041 
01042 struct STR_WIDTH {
01043    int m_width;
01044    STR_WIDTH (int width) : m_width(width) { }
01045    };
01046 
01047 inline MISTRING& operator<< (
01048    MISTRING& lhs,
01049    const STR_WIDTH& rhs
01050    ) { lhs.FmtSetWidth(rhs.m_width); return (lhs); }
01051 
01052 #endif //!< GENERATING_DOXYGEN_OUTPUT
01053 
01054 //! String formatting helper to set fill character via << operator.
01055 //! Use as str << STR_Fill(fill).
01056 inline STR_FILL STR_Fill (
01057    UNICODE fill
01058    ) { return (STR_FILL(fill)); }
01059 
01060 //! String formatting helper to pad specified number of characters.
01061 //! Use as str << STR_Pad(c,numchars).
01062 inline STR_PAD STR_Pad (
01063    UNICODE c,                                //!< Character to pad with
01064    int numchars                              //!< Number of characters to pad
01065    ) { return (STR_PAD(c,numchars)); }
01066 
01067 //! String formatting helper to set precision via << operator.
01068 //! Use as str << STR_Prec(precision).
01069 inline STR_PREC STR_Prec (
01070    int precision
01071    ) { return (STR_PREC(precision)); }
01072 
01073 //! String formatting helper to set width via << operator.
01074 //! Use as str << STR_Width(width).
01075 inline STR_WIDTH STR_Width (
01076    int width
01077    ) { return (STR_WIDTH(width)); }
01078 
01079 #undef   CLASSLIBEXPORT
01080 
01081 #endif   //!< INC_MI32_MISTRING_H

Generated on Tue Dec 14 13:18:29 2004 for TNTsdk by  doxygen 1.3.8-20040913