CC_String.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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: CC_String.h /main/5 1996/08/21 15:48:50 drk $ */
  24. #ifndef _CC_STRING_H_
  25. #define _CC_STRING_H_
  26. #include <string.h>
  27. #include "dti_cc/types.h"
  28. class CC_String {
  29. public: // functions
  30. CC_String (const CC_String& x);
  31. CC_String (const char *string)
  32. {
  33. int len = strlen(string);
  34. f_string = new char[len + 1];
  35. *((char *) memcpy(f_string, string, len) + len) = '\0';
  36. }
  37. CC_String()
  38. {
  39. f_string = NULL;
  40. }
  41. virtual ~CC_String () { delete [] f_string; }
  42. CC_Boolean isNull() const {
  43. return( f_string[0] == '\0' );
  44. }
  45. unsigned int hash() const; /* This returns a hash value
  46. * used by the hash funcion
  47. */
  48. size_t length() const { /* Used strlen, so expect string terminated by
  49. * \0. The library in RW takes care of non-null
  50. * terminated string. I assume this is not
  51. * the case here.
  52. */
  53. return(strlen(f_string));
  54. }
  55. enum caseCompare { exact, ignoreCase };
  56. int compareTo(const char *, caseCompare = exact) const;
  57. int compareTo(const CC_String &cs, caseCompare CaseSensitive = exact) const
  58. {
  59. return(compareTo((const char *)cs, CaseSensitive));
  60. }
  61. CC_Boolean operator ==(const CC_String &k) const
  62. {
  63. return (compareTo(k) == 0) ? TRUE : FALSE;
  64. }
  65. operator const char *() const { return f_string; }
  66. const char *data() const { return f_string; }
  67. private:
  68. char *f_string;
  69. };
  70. #endif