2 /* Copyright (C) 1989, 1990, 1991 Free Software Foundation, Inc.
3 Written by James Clark (jjc@jclark.uucp)
5 This file is part of groff.
7 groff is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 1, or (at your option) any later
12 groff is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License along
18 with groff; see the file LICENSE. If not, write to the Free Software
19 Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
28 string(const string
&);
30 string(const char *, int);
35 string
&operator=(const string
&);
36 string
&operator=(const char *);
37 string
&operator=(char);
39 string
&operator+=(const string
&);
40 string
&operator+=(const char *);
41 string
&operator+=(char);
42 void append(const char *, int);
46 int operator*() const;
48 string
substring(int i
, int n
) const;
50 char &operator[](int);
51 char operator[](int) const;
53 void set_length(int i
);
54 const char *contents() const;
55 int search(char) const;
56 char *extract() const;
60 friend string
operator+(const string
&, const string
&);
61 friend string
operator+(const string
&, const char *);
62 friend string
operator+(const char *, const string
&);
63 friend string
operator+(const string
&, char);
64 friend string
operator+(char, const string
&);
66 friend int operator==(const string
&, const string
&);
67 friend int operator!=(const string
&, const string
&);
68 friend int operator<=(const string
&, const string
&);
69 friend int operator<(const string
&, const string
&);
70 friend int operator>=(const string
&, const string
&);
71 friend int operator>(const string
&, const string
&);
78 string(const char *, int, const char *, int); // for use by operator+
83 inline char &string::operator[](int i
)
85 assert(i
>= 0 && i
< len
);
89 inline char string::operator[](int i
) const
91 assert(i
>= 0 && i
< len
);
95 inline int string::length() const
100 inline int string::empty() const
105 inline int string::operator*() const
110 inline const char *string::contents() const
115 inline string
operator+(const string
&s1
, const string
&s2
)
117 return string(s1
.ptr
, s1
.len
, s2
.ptr
, s2
.len
);
120 inline string
operator+(const string
&s1
, const char *s2
)
125 return string(s1
.ptr
, s1
.len
, s2
, strlen(s2
));
128 inline string
operator+(const char *s1
, const string
&s2
)
133 return string(s1
, strlen(s1
), s2
.ptr
, s2
.len
);
136 inline string
operator+(const string
&s
, char c
)
138 return string(s
.ptr
, s
.len
, &c
, 1);
141 inline string
operator+(char c
, const string
&s
)
143 return string(&c
, 1, s
.ptr
, s
.len
);
146 inline int operator==(const string
&s1
, const string
&s2
)
148 return (s1
.len
== s2
.len
149 && (s1
.len
== 0 || memcmp(s1
.ptr
, s2
.ptr
, s1
.len
) == 0));
152 inline int operator!=(const string
&s1
, const string
&s2
)
154 return (s1
.len
!= s2
.len
155 || (s1
.len
!= 0 && memcmp(s1
.ptr
, s2
.ptr
, s1
.len
) != 0));
158 inline string
string::substring(int i
, int n
) const
160 assert(i
>= 0 && i
+ n
<= len
);
161 return string(ptr
+ i
, n
);
164 inline string
&string::operator+=(char c
)
172 void put_string(const string
&, FILE *);
174 string
as_string(int);