2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
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)
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
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /*%% (c) Copyright 1993, 1994 Hewlett-Packard Company */
24 /*%% (c) Copyright 1993, 1994 International Business Machines Corp. */
25 /*%% (c) Copyright 1993, 1994 Sun Microsystems, Inc. */
26 /*%% (c) Copyright 1993, 1994 Novell, Inc. */
27 /*%% $XConsortium: tt_string.h /main/5 1996/09/24 10:06:16 drk $ */
30 * @(#)tt_string.h 1.27 @(#)
34 * Copyright (c) 1990 by Sun Microsystems, Inc.
36 * Headers for tt string class.
41 #include "tt_options.h"
42 #if defined(OPT_BUG_SUNOS_4) && defined(__GNUG__)
47 #if defined(OPT_BUG_HPUX)
51 #elif defined(OPT_BUG_SUNOS_5) || defined(OPT_BUG_USL) || defined(OPT_BUG_UXP)
54 #elif defined(OPT_BUG_AIX)
56 #elif defined(__osf__)
61 #include "util/tt_list.h"
62 #include "util/tt_object.h"
68 const int _Tt_string_unlimited = -1;
69 const int _Tt_string_user_width = -2;
71 declare_list_of(_Tt_string_buf)
72 class _Tt_string_buf : public _Tt_object {
73 friend class _Tt_string;
80 _Tt_string_buf(const _Tt_string_buf &b);
81 virtual ~_Tt_string_buf();
82 void set(const unsigned char*s, int len);
83 bool_t operator==(const _Tt_string_buf &b);
84 bool_t xdr(XDR *xdrs);
85 bool_t xdr_1(XDR *xdrs);
86 bool_t xdr_2(XDR *xdrs);
87 // _Tt_string_unlimited: no limit
88 // _Tt_string_user_width: use $TT_ARG_TRACE_WIDTH or $_SUN_TT_ARG_TRACE_WIDTH
89 void print(const _Tt_ostream &os,
90 int max_print_width = 80000,
91 int quote_it = 0) const;
94 int length; // includes null byte (length=strlen()+1)
97 class _Tt_string : public _Tt_string_buf_ptr {
100 _Tt_string(const _Tt_string_buf_ptr &s) : _Tt_string_buf_ptr(s) {};
101 _Tt_string(const _Tt_string &s);
102 _Tt_string(const char *s);
103 _Tt_string(const unsigned char *s, int len);
104 _Tt_string(int len); // Used by cat/substring to make result cells
106 _Tt_string& operator=(const char *s);
107 _Tt_string& operator=(const _Tt_string_buf_ptr &s)
108 {*(_Tt_string_buf_ptr *)this = s; return *this;}
109 _Tt_string& operator=(const _Tt_string &s)
110 {*(_Tt_string_buf_ptr *)this = s; return *this;}
111 _Tt_string& set(const unsigned char*s, int len);
112 char& operator[](int offset);
113 const char& operator[](int offset) const;
115 // XXX char *() should not be const, but so much of UNIX takes char *
116 // instead of const char *
118 operator char *() const;
119 operator const char *() const;
120 _Tt_string left(int len) const;
121 _Tt_string right(int len) const;
122 _Tt_string mid(int offset, int len) const;
123 _Tt_string split(int index, _Tt_string &prefix) const;
124 _Tt_string split(char c, _Tt_string &prefix) const;
125 _Tt_string split(const char *s, _Tt_string &prefix) const;
126 _Tt_string rsplit(char c, _Tt_string &prefix) const;
127 _Tt_string quote_nulls() const;
128 _Tt_string unquote_nulls() const;
129 _Tt_string cat(const _Tt_string &s) const;
130 _Tt_string cat(char c) const;
131 _Tt_string cat(int i) const;
132 _Tt_string cat(unsigned int i) const;
133 _Tt_string cat(long i) const;
134 _Tt_string cat(unsigned long i) const;
135 _Tt_string replace(const char *old, const _Tt_string &with) const;
137 return (*this)->length;
139 int operator==(const _Tt_string& s) const {
140 return((*this)->length==s->length &&
141 0==memcmp((*this)->content, s->content,
144 int operator==(const char *s) const {return 0==cmp(s);}
145 int operator<(const _Tt_string& s) const
146 {return -1==cmp(s->content, s->length);}
147 int operator<(const char *s) const {return -1==cmp(s);}
148 int operator>(const _Tt_string& s) const
149 {return +1==cmp(s->content, s->length);}
150 int operator>(const char *s) const {return +1==cmp(s);}
151 int operator!=(const _Tt_string &s) const {return !(*this==s);}
152 int operator!=(const char *s) const {return !(*this==s);}
153 int operator<=(const _Tt_string &s) const {return !(*this>s);}
154 int operator<=(const char *s) const {return !(*this>s);}
155 int operator>=(const _Tt_string &s) const {return !(*this<s);}
156 int operator>=(const char *s) const {return !(*this<s);}
157 int sh_match(const _Tt_string &pattern) const;
158 #ifdef _DEBUG_MALLOC_INC
159 int DBindex(char *fname, int lnum, char c) const;
160 int DBrindex(char *fname, int lnum, char c) const;
162 int index(char c) const;
163 int index(const char *s) const;
164 int rindex(char c) const;
165 int strchr(char c) const;
166 int strchr(const char *s) const;
167 int strrchr(char c) const;
169 int hash(int max_buckets) const;
170 bool_t xdr(XDR *xdrs);
171 void print(void) const;
172 void print(const _Tt_ostream &os, int max_print_width = 80000,
173 int quote_it = 0) const;
174 int cmp(const _Tt_string &s) const {return cmp(s->content, s->length);}
175 int cmp(const char *q, int qlen = -1) const;
178 // Since _Tt_string is "just a _Tt_string_buf_ptr" with some extra operations,
179 // a _Tt_string_list and associated classes are just the _Tt_string_buf_list
180 // class and associated classes.
182 void _tt_string_print(const _Tt_ostream &os, const _Tt_object *obj);
183 class _Tt_string_list : public _Tt_string_buf_list {
186 _Tt_string_list(const _Tt_string_list &l);
187 _Tt_string_list(const _Tt_string_buf_list &l);
191 class _Tt_string_list_ptr : public _Tt_string_buf_list_ptr {
193 _Tt_string_list_ptr();
194 _Tt_string_list_ptr(_Tt_string_list *s) :
195 _Tt_string_buf_list_ptr((_Tt_string_buf_list *)s) {};
196 _Tt_string_list_ptr(const _Tt_string_list_ptr &p) :
197 _Tt_string_buf_list_ptr(p) {};
198 ~_Tt_string_list_ptr();
199 _Tt_string_list_ptr &operator=(_Tt_string_list *s);
200 _Tt_string_list_ptr &operator=(const _Tt_string_list_ptr &s);
203 class _Tt_string_list_cursor: public _Tt_string_buf_list_cursor {
205 _Tt_string_list_cursor();
206 _Tt_string_list_cursor(const _Tt_string_list_cursor &c);
207 _Tt_string_list_cursor(const _Tt_string_list_ptr &l);
208 ~_Tt_string_list_cursor();
209 _Tt_string operator *() const;
210 _Tt_string operator ->() const;
213 int _tt_xdr_encode(xdrproc_t xdr_fn, void *data, _Tt_string &opaque_string);
214 int _tt_xdr_decode(xdrproc_t xdr_fn, void *data, _Tt_string opaque_string);
215 bool_t tt_xdr_string(XDR *xdrs, _Tt_string *s);
216 bool_t _tt_xdr_string_list(XDR *xdrs, _Tt_string_list_ptr *strings_ptr);
217 void _tt_print_escaped_string(const _Tt_ostream &os,
218 const char *s, int length,
219 int max_print_width = 8000,
222 #include "util/tt_iostream.h"