Subversion Repositories autosfx

Rev

Blame | Last modification | View Log | RSS feed

  1. //---------------------------------------------------------------------------
  2.  
  3. #ifndef DZ_StrWH
  4. #define DZ_StrWH
  5.  
  6. #include <windows.h>
  7. #include <malloc.h>
  8. #include <string.h>
  9. #include <stdarg.h>
  10.  
  11. //#define BAD_MEM_EXCEPT -999
  12.  
  13. /* DZ_StrW.H *
  14.  
  15.  Copyright (C) 2009, 2010  by Russell J. Peters, Roger Aelbrecht
  16.  
  17.    This file is part of TZipMaster Version 1.9.
  18.  
  19.     TZipMaster is free software: you can redistribute it and/or modify
  20.     it under the terms of the GNU Lesser General Public License as published by
  21.     the Free Software Foundation, either version 3 of the License, or
  22.     (at your option) any later version.
  23.  
  24.     TZipMaster is distributed in the hope that it will be useful,
  25.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  26.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  27.     GNU Lesser General Public License for more details.
  28.  
  29.     You should have received a copy of the GNU Lesser General Public License
  30.     along with TZipMaster.  If not, see <http://www.gnu.org/licenses/>.
  31.  
  32.     contact: problems@delphizip.org (include ZipMaster in the subject).
  33.     updates: http://www.delphizip.org
  34.     DelphiZip maillist subscribe at http://www.freelists.org/list/delphizip
  35. ************************************************************************/
  36.  
  37. class DZStrA;
  38.  
  39. #pragma pack(push, 4)
  40.     struct dzstrw_imp
  41.     {
  42.         long refs;          // reference counter
  43.         unsigned  capacity; // characters
  44.         unsigned  len;      // string length
  45.         wchar_t data[1];    // the actual data + end 0
  46.     };
  47. #pragma pack(pop)
  48.  
  49. class DZStrW
  50. {
  51.     private:
  52.         wchar_t* imp; // -->dzstrw_imp.data
  53.  
  54.     protected:
  55. inline   wchar_t* __fastcall _IMP_Data(dzstrw_imp* _imp) const
  56.         {
  57.             return  _imp ? (wchar_t*)((wchar_t*)_imp + 6) : NULL;
  58.         }
  59. inline    dzstrw_imp* __fastcall _IMP_Ptr(wchar_t* p) const
  60.         {
  61.             return  p ? (dzstrw_imp*)(p - 6) : NULL;
  62.         }
  63.  
  64.                 dzstrw_imp* __fastcall NewImp(unsigned siz);
  65.         dzstrw_imp* __fastcall NewImp(const wchar_t* src, int maxLen = -1);
  66.         dzstrw_imp* __fastcall NewImp(const char* src, int maxLen = -1);
  67.         unsigned __fastcall _Capacity(dzstrw_imp* _imp) const;
  68.         unsigned __fastcall _Length(dzstrw_imp* _imp) const;
  69.         unsigned __fastcall _IncImpRefs(dzstrw_imp* _imp);
  70.         unsigned __fastcall _DecImpRefs(dzstrw_imp* _imp);
  71.         void __fastcall _ReleaseImp(dzstrw_imp* _imp);
  72.         void __fastcall Release(void);
  73.         int __fastcall IncRefs(void);
  74.         int __fastcall DecRefs(void);
  75.         // maxSpace is max characters
  76.         void __fastcall _Assign(const wchar_t* src, int maxLen = -1);
  77.         void __fastcall _Assign(const char* src, int maxLen = -1);
  78.         void __fastcall _Append(const wchar_t* src, int maxSpace = -1);
  79.         void __fastcall _Append(const char* src, int maxSpace = -1);
  80.         void __fastcall _Append(wchar_t ch);
  81.         dzstrw_imp* Unique(void);
  82.     public:
  83.         __fastcall DZStrW(void): imp(0){}
  84.         __fastcall DZStrW(const DZStrW& other);
  85.         __fastcall DZStrW(const DZStrA& other);
  86.         __fastcall DZStrW(const wchar_t* str, int len = -1);
  87.                 __fastcall DZStrW(const char* str, int len = -1);
  88.                 __fastcall DZStrW(UINT cp, const char* str, int len = -1);
  89.         __fastcall DZStrW(wchar_t ch, unsigned cnt);
  90.                 __fastcall ~DZStrW(void);
  91.  inline void __fastcall Append(const wchar_t* src, int maxSpace = -1) {_Append(src, maxSpace);}
  92.         unsigned __fastcall Capacity(void) const;
  93.         unsigned __fastcall Length(void) const;
  94.         unsigned __fastcall length(void) const {return Length();}
  95.  inline bool IsEmpty(void) const {return !imp || !*imp;}
  96.         void Empty(void) {Release();}
  97.  inline bool empty(void) {return IsEmpty();}
  98.                 wchar_t * __fastcall GetBuffer(int minsize = -1);
  99.                 void __fastcall ReleaseBuffer(int newlen = -1);
  100.         void __cdecl  AppendFormat(const wchar_t *fmt, ...);
  101.                 bool __fastcall BadDOS(void) const;
  102.                 int __fastcall Compare(const wchar_t *other) const;
  103.                 int __fastcall CompareNoCase(const wchar_t *other) const;
  104.                 int __fastcall Delete(unsigned pos, unsigned cnt = 1);
  105.                 int __fastcall Find(const wchar_t *sub, unsigned start = 0) const;
  106.                 int __fastcall Find(wchar_t ch, unsigned start = 0) const;
  107.         int __fastcall FindOneOf(const wchar_t *chars, unsigned start = 0) const;
  108.         int __cdecl Format(const wchar_t *fmt, ...);
  109.         int __cdecl FormatV(const wchar_t *fmt, void *arglist);
  110.         int __fastcall Insert(unsigned pos, wchar_t ch);
  111.         wchar_t LastChar(void) const;
  112.                 DZStrW __fastcall Left(unsigned len) const;
  113.                 DZStrW __fastcall Mid(unsigned pos, unsigned len = MAXINT) const;
  114.         int __fastcall ReverseFind(wchar_t ch, unsigned int pos = MAXINT) const;
  115.         DZStrW __fastcall Right(unsigned cnt)const {return Mid(Length() - cnt, cnt);}
  116.                 DZStrA __fastcall SafeAnsi(void) const;
  117.                 DZStrA __fastcall SafeAnsi(int &bad) const;
  118.                 DZStrA __fastcall SafeNarrow(unsigned cp) const;
  119.                 DZStrA __fastcall SafeNarrow(unsigned cp, int &bad) const;
  120.                 DZStrW& __fastcall ToUpper(void);
  121.                 DZStrW& __fastcall Trim(void);
  122.         DZStrW& __fastcall TrimLeft(void);
  123.         DZStrW& __fastcall TrimLeft(wchar_t ch);
  124.         DZStrW& __fastcall TrimRight(void);
  125.         const wchar_t* c_str(void)const {return imp;}
  126.         operator const wchar_t*()const {return imp;}
  127.         DZStrW& __fastcall operator =(const DZStrW& other);
  128.         DZStrW& __fastcall operator =(const wchar_t* str);
  129.         DZStrW& __fastcall operator =(const char* str);
  130.         DZStrW __fastcall operator +(const DZStrW& other);
  131.         DZStrW __fastcall operator +(const wchar_t* str);
  132.         DZStrW& __fastcall operator +=(const DZStrW& other);
  133.         DZStrW& __fastcall operator +=(const wchar_t* str);
  134.         DZStrW& __fastcall operator +=(wchar_t ch);
  135.         wchar_t __fastcall operator [](unsigned idx) const;
  136.         bool operator !()const {return !imp;}
  137. };
  138.  
  139. #pragma pack(push, 4)
  140.     struct dzstra_imp
  141.     {
  142.         long refs;          // reference counter
  143.         unsigned  capacity; // characters
  144.         unsigned  len;      // string length
  145.         char data[1];    // the actual data + end 0
  146.     };
  147. #pragma pack(pop)
  148.  
  149. class DZStrA
  150. {
  151.     private:
  152.         char* imp; // -->dzstra_imp.data
  153.  
  154.     protected:
  155. inline   char* __fastcall _IMP_Data(dzstra_imp* _imp) const
  156.         {
  157.             return  _imp ? (char*)((char*)_imp + 12) : NULL;
  158.         }
  159. inline    dzstra_imp* __fastcall _IMP_Ptr(char* p) const
  160.         {
  161.             return  p ? (dzstra_imp*)(p - 12) : NULL;
  162.         }
  163.  
  164.                 dzstra_imp* __fastcall NewImp(unsigned siz);
  165.         dzstra_imp* __fastcall NewImp(const char* src, int maxLen = -1);
  166.         unsigned __fastcall _Capacity(dzstra_imp* _imp) const;
  167.         unsigned __fastcall _Length(dzstra_imp* _imp) const;
  168.         unsigned __fastcall _IncImpRefs(dzstra_imp* _imp);
  169.         unsigned __fastcall _DecImpRefs(dzstra_imp* _imp);
  170.         void __fastcall _ReleaseImp(dzstra_imp* _imp);
  171.         void __fastcall Release(void);
  172.         int __fastcall IncRefs(void);
  173.         int __fastcall DecRefs(void);
  174.         // maxSpace is max characters
  175.         void __fastcall _Assign(const char* src, int maxLen = -1);
  176.     public:
  177.         void __fastcall _Append(const char* src, int maxSpace = -1);
  178.         __fastcall DZStrA(void): imp(0){}
  179.         __fastcall DZStrA(const DZStrA& other);
  180.         __fastcall DZStrA(const DZStrW& other);
  181.         __fastcall DZStrA(const char* str, int len = -1);
  182.         __fastcall DZStrA(const wchar_t* wstr);
  183.         __fastcall DZStrA(unsigned val, unsigned cnt);
  184.                 __fastcall ~DZStrA(void);
  185.                 unsigned __fastcall Capacity(void) const;
  186.         unsigned __fastcall Length(void) const;
  187.         unsigned __fastcall length(void) const {return Length();}
  188.  inline bool IsEmpty(void) const {return !imp || !*imp;}
  189.         void Empty(void) {Release();}
  190.  inline bool empty(void) const {return IsEmpty();}
  191.                 char * __fastcall GetBuffer(int minsize = -1);
  192.         bool __fastcall BadDOS(void) const;
  193.         int __fastcall Compare(const char* other) const;
  194.         int __fastcall CompareNoCase(const char* other) const;
  195.                 DZStrA __fastcall Left(unsigned len) const;
  196.                 DZStrA __fastcall Mid(unsigned pos, unsigned len = MAXINT) const;
  197.                 void __fastcall ReleaseBuffer(int newlen = -1);
  198.         int __fastcall Find(char ch) const;
  199.         int __fastcall FindOneOf(const char *chars, unsigned start = 0) const;
  200.         int __fastcall ReverseFind(char ch, unsigned int pos = MAXINT) const;
  201.                 DZStrA& __fastcall ToUpper(void);
  202.         const char* c_str(void)const {return imp;}
  203.         operator const char*()const {return imp;}
  204.         DZStrA& __fastcall operator =(const DZStrA& other);
  205.         DZStrA& __fastcall operator =(const char* str);
  206.         DZStrA __fastcall operator +(const DZStrA& other);
  207.         DZStrA __fastcall operator +(const char* str);
  208.         DZStrA& __fastcall operator +=(const DZStrA& other);
  209.         DZStrA& __fastcall operator +=(const char* str);
  210.         DZStrA& __fastcall operator +=(char ch);
  211.         char __fastcall operator [](unsigned idx) const;
  212.         bool operator !()const {return !imp;}
  213. };
  214. #endif
  215.