cstring.h 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * CDE - Common Desktop Environment
  3. *
  4. * Copyright (c) 1993-2012, The Open Group. All rights reserved.
  5. *
  6. * These libraries and programs are free software; you can
  7. * redistribute them and/or modify them under the terms of the GNU
  8. * Lesser General Public License as published by the Free Software
  9. * Foundation; either version 2 of the License, or (at your option)
  10. * any later version.
  11. *
  12. * These libraries and programs are distributed in the hope that
  13. * they will be useful, but WITHOUT ANY WARRANTY; without even the
  14. * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  15. * PURPOSE. See the GNU Lesser General Public License for more
  16. * details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with these libraries and programs; if not, write
  20. * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
  21. * Floor, Boston, MA 02110-1301 USA
  22. */
  23. /* $XConsortium: cstring.h /main/3 1995/11/03 12:34:22 rswiston $ */
  24. /*******************************************************************
  25. ** (c) Copyright Hewlett-Packard Company, 1990, 1991, 1992, 1993.
  26. ** All rights are reserved. Copying or other reproduction of this
  27. ** program except for archival purposes is prohibited without prior
  28. ** written consent of Hewlett-Packard Company.
  29. ********************************************************************
  30. ****************************<+>*************************************/
  31. #ifndef _CSTRING_H_
  32. #define _CSTRING_H_
  33. #include <iostream>
  34. #include <string.h>
  35. class CString {
  36. public:
  37. CString();
  38. CString(const char * s, unsigned char = 1);
  39. CString(const char, unsigned char = 1);
  40. CString(const CString &);
  41. ~CString();
  42. int length() const { return strlen(contents); }
  43. char * data() const { return contents; }
  44. CString & operator= (const CString &);
  45. CString & operator= (const char *);
  46. CString & operator+= (const CString &);
  47. CString & operator+= (const char *);
  48. int operator!= (const CString &) const;
  49. int operator== (const CString &) const;
  50. char & operator[](int) const;
  51. friend CString operator+ (const CString & s1, const CString & s2);
  52. friend CString operator+ (const CString & s, const char * cs);
  53. friend CString operator+ (const char * cs, const CString & s);
  54. CString copy (unsigned int, const char *);
  55. CString copy (const char *, const char *);
  56. CString find (const char *);
  57. int contains (const char *, const char * = "", const char * = "") const;
  58. int contains (const CString &, const char * = "", const char * = "") const;
  59. int isNull() const;
  60. void replace (const CString &, const CString &);
  61. friend std::ostream & operator<< (std::ostream &, const CString &);
  62. protected:
  63. char * contents;
  64. unsigned char skipWhiteSpace;
  65. };
  66. class CTokenizedString : public CString {
  67. public:
  68. CTokenizedString();
  69. CTokenizedString(const CTokenizedString &);
  70. CTokenizedString(const CString &, char *, unsigned char = 1);
  71. ~CTokenizedString();
  72. int Finished() { return finished == 1; }
  73. CString next();
  74. private:
  75. char * cursor;
  76. char * delimiter;
  77. int finished;
  78. };
  79. #endif