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 libraries and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* $XConsortium: StringOf.h /main/1 1996/07/29 17:05:21 cde-hp $ */
24 // Copyright (c) 1994, 1996 James Clark
25 // See the file COPYING for copying permission.
27 #ifndef StringOf_INCLUDED
28 #define StringOf_INCLUDED 1
30 // The file is called StringOf to distinguish it from string.h on
31 // case-insensitive file systems.
33 // This offers a subset of the interface offered by the standard C++
34 // basic_string class as defined in the Jan 96 WP.
35 // Code in SP currently assumes that size_type is size_t.
42 namespace SP_NAMESPACE {
48 typedef size_t size_type;
50 typedef const T *const_iterator;
52 ~String() { if (ptr_) delete [] ptr_; }
53 String(const T *, size_t);
54 String(const String<T> &);
55 String<T> &operator=(const String<T> &);
56 size_t size() const { return length_; }
57 String<T> &assign(const T *, size_t);
58 String<T> &insert(size_t i, const String<T> &s);
59 void swap(String<T> &str);
60 T operator[](size_t i) const { return ptr_[i]; }
61 T &operator[](size_t i) { return ptr_[i]; }
62 iterator begin() { return ptr_; }
63 const_iterator begin() const { return ptr_; }
64 const T *data() const { return ptr_; }
65 String<T> &operator+=(T c) {
66 if (length_ >= alloc_)
71 String<T> &operator+=(const String<T> &s) {
72 append(s.ptr_, s.length_);
75 String<T> &append(const T *, size_t);
76 Boolean operator==(const String<T> &s) const {
77 return (length_ == s.length_
80 && (memcmp(ptr_ + 1, s.ptr_ + 1, (length_ - 1)*sizeof(T))
83 Boolean operator!=(const String<T> &str) const {
84 return !(*this == str);
86 void resize(size_t n);
98 #endif /* not StringOf_INCLUDED */
100 #ifdef SP_DEFINE_TEMPLATES
101 #include "StringOf.C"