home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 27 / IOPROG_27.ISO / SOFT / XSTRING.ZIP / XString.H < prev   
Encoding:
C/C++ Source or Header  |  1998-05-05  |  7.8 KB  |  190 lines

  1. /*****************************************************************************
  2.  *
  3.  * Autor:            Joachim Raidl
  4.  * Adresse:            Joachim.Raidl@iname.com
  5.  * Klasse:            XString
  6.  * JRRC:            %J%
  7.  *
  8.  ****************************************************************************/
  9.  
  10. #ifndef __XSTRING__
  11. #define __XSTRING__
  12.  
  13. class XString;
  14.  
  15. typedef const XString    XS;
  16.  
  17. class XString : public CString
  18. {
  19. //==============================================================================
  20. // Konstruktoren
  21. //==============================================================================
  22. public:
  23.     XString()                            : CString()                    {}
  24.     XString(const XString& xstr)        : CString(xstr)                {}
  25.     XString(const CString& cstr)        : CString(cstr)                {}
  26.     XString(TCHAR c, int nRepeat = 1)    : CString(c, nRepeat)        {}
  27.     XString(LPCTSTR lptstr, int nLength): CString(lptstr, nLength)    {}
  28.     XString(const unsigned char* psz )    : CString(psz)                {}
  29.     XString(LPCSTR lpstr )                : CString(lpstr)            {}
  30.     XString(const int i)                : CString(itoa(i))            {}
  31.     XString(const UINT u)                : CString(utoa(u))            {}
  32.     XString(const double d)                : CString(dtoa(d))            {}
  33.     XString(LPCWSTR lpwstr )            : CString(lpwstr)            {}
  34.  
  35. //==============================================================================
  36. // Operatoren
  37. //==============================================================================
  38. public:
  39.     operator CString () const            { return *this; }
  40.  
  41.     XString    operator--()                { *this = Left(GetLength() - 1); return *this; }
  42.     XString    operator--(int)                { XString copy(*this); *this = Left(GetLength() - 1); return copy; }
  43.     int        operator!() const            { return IsEmpty(); }
  44.  
  45. //==============================================================================
  46. // Funktionen
  47. //==============================================================================
  48. public:
  49.     double    Double() const                { return atof(m_pchData); }
  50.     int        Int() const                    { return atoi(m_pchData); }
  51.     char    Char() const                { return m_pchData[0]; }    // Kein Fehler bei Leerstring
  52.     bool    Bool() const                { return (Int() != 0); }
  53.  
  54.     XString    Remove(int von=0, int bis=-1) const;
  55.     XString    Remove(const XString& s) const;
  56.     XString    Remove(char c) const;
  57.  
  58.     XString    RemoveAll(const XString& s) const;
  59.     XString    RemoveAll(char c) const;
  60.  
  61.     XString    Insert(const XString& s, int at=0) const;
  62.  
  63.     XString    Replace(const XString& s, int von=0, int bis=-1) const;
  64.     XString    Replace(const XString& s, const XString& search) const;
  65.  
  66.     int        ReplaceAll(const XString& s, const XString& search);
  67.  
  68.     // NC... = NoCase... ==> Gro▀-/Kleinschreibung wird nicht beachtet
  69.     int        NCFind(const XString& s) const;
  70.     int        NCFind(char c) const;
  71.  
  72.     XString    NCRemove(const XString& s) const;
  73.     XString    NCRemove(char c) const;
  74.  
  75.     XString    NCRemoveAll(const XString& s) const;
  76.     XString    NCRemoveAll(char c) const;
  77.  
  78.     XString    NCReplace(const XString& s, const XString& search) const;
  79.     int        NCReplaceAll(const XString& s, const XString& search);
  80.  
  81.     XString    Reverse() const                { XString copy = *this; copy.MakeReverse(); return copy; }
  82.  
  83.     XString    Trim() const                { XString copy = *this; copy.TrimRight(); copy.TrimLeft(); return copy; }
  84.     XString    Lower() const                { XString copy = *this; copy.MakeLower(); return copy; }
  85.     XString    Upper() const                { XString copy = *this; copy.MakeUpper(); return copy; }                                       
  86.  
  87.     XString Left(int n) const            { return CString::Left(n); }
  88.     XString Mid(int i) const            { return CString::Mid(i); }
  89.     XString Mid(int i, int n) const        { return CString::Mid(i, n); }
  90.     XString Right(int n) const            { return CString::Right(n); }
  91.  
  92.     XString    Fill(int n) const;
  93.     XString    ReplaceTabs(int abstand = 4) const;
  94.  
  95.     int        Count(char c) const;
  96.     int        Count(const XString& str) const;
  97.     int        FindIndex(char c, int pos) const;
  98.     XString    ReplaceText(const XString& replace) const;
  99.  
  100.     XString FromTo(int von, int bis)    { return Mid(von, bis-von+1); }
  101.  
  102. //==============================================================================
  103. // Funktionen auf Element-Strings
  104. //==============================================================================
  105. public:
  106.     static    char SEP;
  107.     static    char OLDSEP;
  108.     static    char SetSeparator(char c)                { OLDSEP = SEP; SEP = c; return SEP; }
  109.     static    char RestoreSeparator()                    { SEP = OLDSEP; return SEP; }
  110.  
  111.     XString    Elements(int von, int bis = -1) const;
  112.     XString    Elements(int von, int bis, char sep) const;
  113.     XString    Element(int i) const                    { return Elements(i, i); }
  114.     XString    Element(int i, char sep) const;
  115.  
  116.     XString    operator()(int i) const                    { return Elements(i, i); }
  117.     XString    operator()(int von, int bis) const        { return Elements(von, bis); }
  118.  
  119.     XString    GetString(int i) const                    { return Element(i); }
  120.     double    GetDouble(int i) const                    { return Element(i).Double(); }
  121.     char    GetChar(int i) const                    { return Element(i).Char(); }
  122.     int        GetInt(int i) const                        { return Element(i).Int(); }
  123.     bool    GetBool(int i) const                    { return Element(i).Bool(); }
  124.  
  125.     void    Get(XString& ret, int i) const            { ret = GetString(i); }
  126.     void    Get(double& ret, int i) const            { ret = GetDouble(i); }
  127.     void    Get(char& ret, int i) const                { ret = GetChar(i); }
  128.     void    Get(int& ret, int i) const                { ret = GetInt(i); }
  129.     void    Get(bool& ret, int i) const                { ret = GetBool(i); }
  130.  
  131.     XString    GetString(int i, char sep) const        { return Element(i, sep); }
  132.     double    GetDouble(int i, char sep) const        { return Element(i, sep).Double(); }
  133.     char    GetChar(int i, char sep) const            { return Element(i, sep).Char(); }
  134.     int        GetInt(int i, char sep) const            { return Element(i, sep).Int(); }
  135.     bool    GetBool(int i, char sep) const            { return Element(i, sep).Bool(); }
  136.  
  137.     XString    SetElement(int pos, const XString& rep) const;
  138.     XString    SetElement(int pos, double rep) const    { return SetElement(pos, dtoa(rep)); }
  139.     XString    SetElement(int pos, char rep) const        { return SetElement(pos, XString(rep)); }
  140.     XString    SetElement(int pos, int rep) const        { return SetElement(pos, itoa(rep)); }
  141.     XString    SetElement(int pos, bool rep) const        { return SetElement(pos, itoa((int) rep)); }
  142.  
  143.     int        ElementIndex(const XString& such) const;
  144.     int        ElementIndex(double such) const;
  145.     int        ElementIndex(int such) const;
  146.     int        ElementIndex(char such) const;
  147.     int        ElementIndex(bool such) const;
  148.  
  149.     XString    ElementSortString() const;
  150.     XString    ElementSortChar() const;
  151.     XString    ElementSortInt() const;
  152.     XString    ElementSortDouble() const;
  153.     XString ElementSort() const                        { return ElementSortString(); }
  154.  
  155.     XString GetDoubleFormatString() const;
  156.  
  157. public:
  158.     friend    XString itoa(int i);
  159.     friend    XString utoa(UINT u);
  160.     friend    XString dtoa(double d);
  161.     friend    XString dtoa(double d, int n);
  162.  
  163.     friend    XString Repeat(char c, int n);
  164.     friend    XString Repeat(const XString& str, int n);
  165.     friend    XString GetDoubleFormatString(const XString& str);
  166.     friend    XString GetStringTableEntry(UINT id);
  167.  
  168.     friend    XString Concat(XS&,XS&);
  169.     friend    XString Concat(XS&,XS&,XS&);
  170.     friend    XString Concat(XS&,XS&,XS&,XS&);
  171.     friend    XString Concat(XS&,XS&,XS&,XS&,XS&);
  172.     friend    XString Concat(XS&,XS&,XS&,XS&,XS&,XS&);
  173.     friend    XString Concat(XS&,XS&,XS&,XS&,XS&,XS&,XS&);
  174.     friend    XString Concat(XS&,XS&,XS&,XS&,XS&,XS&,XS&,XS&);
  175.     friend    XString Concat(XS&,XS&,XS&,XS&,XS&,XS&,XS&,XS&,XS&);
  176.     friend    XString Concat(XS&,XS&,XS&,XS&,XS&,XS&,XS&,XS&,XS&,XS&);
  177.     friend    XString Concat(XS&,XS&,XS&,XS&,XS&,XS&,XS&,XS&,XS&,XS&,XS&);
  178.     friend    XString Concat(XS&,XS&,XS&,XS&,XS&,XS&,XS&,XS&,XS&,XS&,XS&,XS&);
  179.     friend    XString Concat(XS&,XS&,XS&,XS&,XS&,XS&,XS&,XS&,XS&,XS&,XS&,XS&,XS&);
  180.     friend    XString Concat(XS&,XS&,XS&,XS&,XS&,XS&,XS&,XS&,XS&,XS&,XS&,XS&,XS&,XS&);
  181.     friend    XString Concat(XS&,XS&,XS&,XS&,XS&,XS&,XS&,XS&,XS&,XS&,XS&,XS&,XS&,XS&,XS&);
  182.     friend    XString Concat(XS&,XS&,XS&,XS&,XS&,XS&,XS&,XS&,XS&,XS&,XS&,XS&,XS&,XS&,XS&,XS&);
  183. };
  184.  
  185. void AFXAPI SerializeElements(CArchive& ar, XString* pElements, int nCount);
  186.  
  187. extern XString STRERROR;
  188.  
  189. #endif // __XSTRING__
  190.