source: vendor/emx/current/src/pmgdb/string.h

Last change on this file was 18, checked in by bird, 22 years ago

Initial revision

  • Property cvs2svn:cvs-rev set to 1.1
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 3.6 KB
Line 
1/* string.h -*- C++ -*-
2 Copyright (c) 1996 Eberhard Mattes
3
4This file is part of pmgdb.
5
6pmgdb is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2, or (at your option)
9any later version.
10
11pmgdb is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with pmgdb; see the file COPYING. If not, write to
18the Free Software Foundation, 59 Temple Place - Suite 330,
19Boston, MA 02111-1307, USA. */
20
21
22class bstring
23{
24public:
25 bstring () { str = NULL; }
26 virtual ~bstring () { delete[] str; }
27 char * modify () { return str; }
28 virtual void set (const char *s, int len) = 0;
29 virtual void set (int len) = 0;
30 virtual void set_null () = 0;
31 bool is_null () const { return str == NULL; }
32 int length () const { return strlen (str); }
33 void set (const char *s) { set (s, strlen (s)); }
34 operator const char * () const { return str; }
35 operator const unsigned char * () const { return (unsigned char *)str; }
36 const char operator [] (int index) const { return str[index]; }
37 bool operator == (const bstring &b) const;
38 bool operator != (const bstring &b) const { return !operator== (b); }
39
40protected:
41 char *str;
42};
43
44// A vstring is expected to be modified quite often
45
46class vstring : public bstring
47{
48public:
49 vstring () { alloc = 0; }
50 ~vstring () {}
51 void set (const char *s) { bstring::set (s); }
52 void set (const char *s, int len);
53 void set (int len);
54 void set_null ();
55 vstring &operator = (const char *s) { set (s); return *this; }
56 vstring &operator = (const vstring &src);
57
58protected:
59 int alloc;
60};
61
62// An fstring is expected to be set only once
63
64class fstring : public bstring
65{
66public:
67 fstring () {}
68 ~fstring () {}
69 void set (const char *s) { bstring::set (s); }
70 void set (const char *s, int len);
71 void set (int len);
72 void set_null ();
73 fstring &operator = (const char *s) { set (s); return *this; }
74 fstring &operator = (const fstring &src);
75};
76
77
78// An astring is expected to be appended to
79
80class astring : public vstring
81{
82private:
83 typedef vstring parent;
84public:
85 astring () { cur_len = 0; }
86 ~astring () {}
87 void set (const char *s) { bstring::set (s); }
88 void set (const char *s, int len) { parent::set (s, len); cur_len = len; }
89 void set (int len) { parent::set (len); if (len < cur_len) cur_len = len; }
90 void set_null () { parent::set_null (); cur_len = 0; }
91 void append (const char *s, int len);
92 void append (const char *s) { append (s, strlen (s)); }
93 vstring &operator = (const char *s) { set (s); return *this; }
94 astring &operator = (const astring &src);
95 int length () const { return cur_len; }
96 void remove_trailing (char c);
97
98private:
99 int cur_len;
100};
101
102
103// String consisting of lines
104
105class lstring
106{
107public:
108 lstring () { str = NULL; vec = NULL; n = 0; }
109 lstring (const char *s);
110 lstring (const bstring &s);
111 lstring (const lstring &s);
112 ~lstring ();
113 lstring &operator = (const lstring &s);
114 void set (const char *s, size_t len);
115 void set (const char *s) { set (s, strlen (s)); }
116 int get_lines () const { return n; }
117 const char *operator [] (int index) const
118 { return (index >= 0 && index < n) ? vec[index] : NULL; }
119 void sort (int (*compare) (const char *, const char *));
120 void sort ();
121
122private:
123 void assign (const lstring &s);
124 char *str;
125 const char **vec;
126 int n;
127 size_t str_len;
128};
Note: See TracBrowser for help on using the repository browser.