ostring.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. /*
  24. * $XConsortium: ostring.h /main/3 1996/06/11 17:38:12 cde-hal $
  25. *
  26. * Copyright (c) 1992 HaL Computer Systems, Inc. All rights reserved.
  27. * UNPUBLISHED -- rights reserved under the Copyright Laws of the United
  28. * States. Use of a copyright notice is precautionary only and does not
  29. * imply publication or disclosure.
  30. *
  31. * This software contains confidential information and trade secrets of HaL
  32. * Computer Systems, Inc. Use, disclosure, or reproduction is prohibited
  33. * without the prior express written permission of HaL Computer Systems, Inc.
  34. *
  35. * RESTRICTED RIGHTS LEGEND
  36. * Use, duplication, or disclosure by the Government is subject to
  37. * restrictions as set forth in subparagraph (c)(l)(ii) of the Rights in
  38. * Technical Data and Computer Software clause at DFARS 252.227-7013.
  39. * HaL Computer Systems, Inc.
  40. * 1315 Dell Avenue, Campbell, CA 95008
  41. *
  42. */
  43. #ifndef _ostring_h
  44. #define _ostring_h 1
  45. #include "utility/funcs.h"
  46. class ostring {
  47. public:
  48. ostring();
  49. ostring(const int chunk_size);
  50. ostring(char* str, const int str_sz = -1); // -1 means take strlen(str)
  51. ostring(const ostring&);
  52. virtual ~ostring() { delete [] v_p; };
  53. // length of the string
  54. int size() const { return v_sz; };
  55. // length of the allocated chunk
  56. int alloc_size() const { return v_allo_sz; };
  57. ostring& operator +(ostring&); // merge of two strings
  58. int substr(ostring&); // substring matching
  59. // set string to content x
  60. Boolean set(const char* x) { return set(x, strlen(x)); };
  61. Boolean set(const char* x, int i); // set string to content x with length i
  62. Boolean append(const char* x, int l); // append a string x of length i
  63. Boolean update(const char* x, int l, int offset); // update a substring x of length i at 'offset'. offset + l should be sz
  64. //set alloc_sz to at least new_alloc_sz bytes
  65. // pre_zero = true -> zero new space before copy old content over
  66. Boolean expand(const int, Boolean pre_zero = false);
  67. void reset() { v_sz = 0; };
  68. void set_size(const int s) { v_sz = s; v_p[v_sz] = 0; };
  69. char* get() const { return v_p; }; // get char pointer p
  70. char* acquire() ; // return what is pointed at by p and reset
  71. // alloc_sz, sz, and p to 0;
  72. // append x to this and return this.
  73. ostring* operator+= (ostring* x);
  74. // concate all ostring arguments (ostring* 's) to this and return this.
  75. ostring* concate_with(...);
  76. Boolean string_LS(ostring&) const;
  77. Boolean string_EQ(ostring&) const;
  78. friend ostream& operator <<(ostream&, const ostring&);
  79. friend istream& operator >>(istream&, ostring&);
  80. protected:
  81. char *v_p; // memory chunk pointer
  82. int v_sz; // string size
  83. int v_allo_sz; // allocated memory chunk size
  84. #ifdef C_API
  85. static char* input_buf;
  86. friend void initialize_MMDB();
  87. friend void quit_MMDB();
  88. #else
  89. static char input_buf[LBUFSIZ];
  90. #endif
  91. };
  92. #endif