home *** CD-ROM | disk | FTP | other *** search
/ Magazyn Internet 2000 May / MICD_2000_05.iso / CBuilder5 / INSTALL / DATA1.CAB / Program_Built_Files / Include / Vcl / wstring.h < prev    next >
C/C++ Source or Header  |  2000-02-01  |  3KB  |  115 lines

  1. //    wstring.h - support for delphi widestrings in c++
  2. //                (WideString)
  3. // $Revision:   1.12  $
  4. //    copyright (c) 1997, 1999 Borland International
  5.  
  6. #ifndef WSTRING_H
  7. #define WSTRING_H
  8.  
  9. #pragma delphiheader begin
  10.  
  11. #include <wtypes.h>
  12. #include <sysmac.h>
  13. #include <dstring.h>
  14.  
  15. namespace System
  16. {
  17.   // NOTE: WideString uses BSTRs as its underlying implementation (i.e. SysAlloc/FreeString etc.)
  18.   //
  19.   class RTL_DELPHIRETURN WideString
  20.   {
  21.     friend WideString __fastcall PACKAGE operator +(const wchar_t*, const WideString& rhs); //!! not implemented?
  22.   public:
  23.     // Constructors
  24.     //
  25.     __fastcall WideString(): Data(0) {}
  26.     __fastcall WideString(const char* src);
  27.     __fastcall WideString(const WideString& src);
  28.     __fastcall WideString(const AnsiString& src);
  29.     __fastcall WideString(const wchar_t* src, int len);
  30.     __fastcall WideString(const wchar_t* src);
  31.     __fastcall WideString(const wchar_t  src);
  32.  
  33.     // Destructor
  34.     //
  35.     __fastcall ~WideString();
  36.  
  37.     // Assignments
  38.     //
  39.     WideString& __fastcall operator =(const WideString& rhs);
  40.     WideString& __fastcall operator =(BSTR              rhs);
  41.     WideString& __fastcall operator =(const char*       rhs);
  42.     WideString& __fastcall operator =(const AnsiString& rhs);
  43.     WideString& __fastcall operator +=(const WideString& rhs);
  44.  
  45.     // Comparisons
  46.     //
  47.     bool __fastcall operator ==(const WideString& rhs) const;
  48.     bool __fastcall operator !=(const WideString& rhs) const;
  49.     bool __fastcall operator < (const WideString& rhs) const;
  50.     bool __fastcall operator > (const WideString& rhs) const;
  51.     bool __fastcall operator <=(const WideString& rhs) const;
  52.     bool __fastcall operator >=(const WideString& rhs) const;
  53.  
  54.     // Index
  55.     //
  56.     wchar_t& __fastcall operator [](const int idx) { return Data[idx-1]; }
  57.  
  58.     // Concatenation
  59.     //
  60.     WideString __fastcall operator +(const WideString& rhs) const;
  61.  
  62.     // Access Data
  63.     //
  64.     BSTR __fastcall c_bstr() const { return Data; }
  65.     operator BSTR() const          { return Data; }
  66.  
  67.     // Access internal data (Be careful when using!!)
  68.     //
  69.     BSTR* __fastcall operator& ()
  70.     {
  71.       return &Data;
  72.     }
  73.  
  74.     // Attach/Detach from BSTR, Empty Object
  75.     //
  76.     void __fastcall Attach(BSTR src);
  77.     BSTR __fastcall Detach();
  78.     void __fastcall Empty();
  79.  
  80.     // Retrieve copy of data
  81.     //
  82.     static wchar_t* __fastcall Copy(wchar_t* src);
  83.  
  84.     wchar_t* __fastcall Copy() const
  85.     {
  86.       return Copy(Data);
  87.     }
  88.  
  89.     // Query attributes of object
  90.     //
  91.     int  __fastcall Length() const;
  92.     bool __fastcall IsEmpty() const;
  93.  
  94.     // Modify string
  95.     //
  96.     void __fastcall Insert(const WideString& str, int index);
  97.     void __fastcall Delete(int index, int count);
  98.     void __fastcall SetLength(int newLength);
  99.  
  100.     int  __fastcall Pos(const WideString& subStr) const;
  101.     WideString __fastcall SubString(int index, int count) const;
  102.  
  103.   private:
  104.     wchar_t *Data;
  105.   };
  106. }
  107. using namespace System;
  108. #pragma delphiheader end.
  109.  
  110. #endif
  111.  
  112.  
  113.  
  114.  
  115.