Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

121 lines
3.2 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1997 - 1997
  6. //
  7. // File: bnstr.h
  8. //
  9. //--------------------------------------------------------------------------
  10. //
  11. // BNSTR.HXX: Generic string class.
  12. //
  13. #if !defined(_BNSTR_HXX_)
  14. #define _BNSTR_HXX_
  15. #include "basics.h"
  16. class BNSTR
  17. {
  18. public:
  19. BNSTR ( const BNSTR & str ) ;
  20. BNSTR ( SZC sz = NULL ) ;
  21. ~ BNSTR () ;
  22. SZC Szc () const { return _sz ; }
  23. // Allow use of a BNSTR anywhere an SZC is allowed
  24. operator const char * () const
  25. { return _sz ; }
  26. // Prefix or suffix the string with the given string or character
  27. SZC Prefix ( SZC szPrefix ) ;
  28. SZC Suffix ( SZC szSuffix ) ;
  29. SZC Suffix ( char chSuffix );
  30. // Clear the string to empty
  31. void Reset () ;
  32. // Return the current length of the string
  33. UINT Length () const
  34. { return _cchStr ; }
  35. // Return the maximum allowable length of the string
  36. UINT Max () const
  37. { return _cchMax ; }
  38. // Truncate the string to the given length.
  39. void Trunc ( UINT cchLen ) ;
  40. // Destructive assignment: release the current buffer and reset the BNSTR
  41. SZ Transfer () ;
  42. void Transfer ( BNSTR & str ) ;
  43. // Assignment operators
  44. BNSTR & operator = ( const BNSTR & str )
  45. { Update( str ); return *this ; }
  46. BNSTR & operator = ( SZC szSource )
  47. { Update( szSource ) ; return *this; }
  48. // Assignment function (for error checking)
  49. bool Assign ( SZC szcSource )
  50. { return Update( szcSource ) ; }
  51. bool Assign ( SZC szcData, UINT cchLen ) ;
  52. // Concatenation operators
  53. BNSTR & operator += ( SZC szSource )
  54. { Suffix( szSource ) ; return *this ; }
  55. BNSTR & operator += ( char chSource )
  56. { Suffix( chSource ) ; return *this ; }
  57. // Comparison: functions and operators
  58. // Standard low/eq/high plus case comparator.
  59. INT Compare ( SZC szSource, bool bIgnoreCase = false ) const ;
  60. bool operator == ( SZC szSource ) const ;
  61. bool operator != ( SZC szSource ) const ;
  62. char operator [] ( UINT iChar ) const ;
  63. // Formating
  64. bool Vsprintf ( SZC szcFmt, va_list valist ) ;
  65. bool Sprintf ( SZC szcFmt, ... ) ;
  66. bool SprintfAppend ( SZC szcFmt, ... ) ;
  67. // Cr/Lf expansion or contraction
  68. bool ExpandNl () ;
  69. bool ContractNl () ;
  70. bool ExpandEscaped ();
  71. bool ContractEscaped ();
  72. // Expand the string to the given length; make it a blank, null terminated
  73. // string.
  74. bool Pad ( UINT cchLength ) ;
  75. // Change all alphabetic characters to the given case
  76. void UpCase ( bool bToUpper = true ) ;
  77. bool ReplaceSymName ( SZC szcSymName,
  78. SZC szcSymNameNew,
  79. bool bCaseInsensitive = true );
  80. // Find the next occurrence of the given character in the string;
  81. // Return -1 if not found.
  82. INT Index ( char chFind, UINT uiOffset = 0 ) const ;
  83. // Convert the string to a floating-point number.
  84. double Atof ( UINT uiOffset = 0 ) const ;
  85. UINT CbyteCPT() const
  86. { return _cchMax + 1 ; }
  87. protected:
  88. bool Update ( SZC szc ) ;
  89. bool Grow ( UINT cchNewSize = 0, SZ * ppszNew = NULL ) ;
  90. UINT _cchMax ;
  91. UINT _cchStr ;
  92. SZ _sz ;
  93. private:
  94. void DeleteSz () ;
  95. static SZC _pmt ;
  96. };
  97. #endif // !defined(_STR_HXX_)
  98. // End of BNSTR.HXX