4 /* Copyright (C) 1989, 1990, 1991, 1992, 2002 Free Software Foundation, Inc.
5 Written by James Clark (jjc@jclark.com)
7 This file is part of groff.
9 groff is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License as published by the Free
11 Software Foundation; either version 2, or (at your option) any later
14 groff is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 You should have received a copy of the GNU General Public License along
20 with groff; see the file COPYING. If not, write to the Free Software
21 Foundation, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. */
27 // Ensure that the first declaration of functions that are later
28 // declared as inline declares them as inline.
32 inline string
operator+(const string
&, const string
&);
33 inline string
operator+(const string
&, const char *);
34 inline string
operator+(const char *, const string
&);
35 inline string
operator+(const string
&, char);
36 inline string
operator+(char, const string
&);
37 inline int operator==(const string
&, const string
&);
38 inline int operator!=(const string
&, const string
&);
43 string(const string
&);
45 string(const char *, int);
50 string
&operator=(const string
&);
51 string
&operator=(const char *);
52 string
&operator=(char);
54 string
&operator+=(const string
&);
55 string
&operator+=(const char *);
56 string
&operator+=(char);
57 void append(const char *, int);
61 int operator*() const;
63 string
substring(int i
, int n
) const;
65 char &operator[](int);
66 char operator[](int) const;
68 void set_length(int i
);
69 const char *contents() const;
70 int search(char) const;
71 char *extract() const;
76 friend string
operator+(const string
&, const string
&);
77 friend string
operator+(const string
&, const char *);
78 friend string
operator+(const char *, const string
&);
79 friend string
operator+(const string
&, char);
80 friend string
operator+(char, const string
&);
82 friend int operator==(const string
&, const string
&);
83 friend int operator!=(const string
&, const string
&);
84 friend int operator<=(const string
&, const string
&);
85 friend int operator<(const string
&, const string
&);
86 friend int operator>=(const string
&, const string
&);
87 friend int operator>(const string
&, const string
&);
94 string(const char *, int, const char *, int); // for use by operator+
99 inline char &string::operator[](int i
)
101 assert(i
>= 0 && i
< len
);
105 inline char string::operator[](int i
) const
107 assert(i
>= 0 && i
< len
);
111 inline int string::length() const
116 inline int string::empty() const
121 inline int string::operator*() const
126 inline const char *string::contents() const
131 inline string
operator+(const string
&s1
, const string
&s2
)
133 return string(s1
.ptr
, s1
.len
, s2
.ptr
, s2
.len
);
136 inline string
operator+(const string
&s1
, const char *s2
)
142 return string(s1
.ptr
, s1
.len
, s2
, strlen(s2
));
144 return s2
== 0 ? s1
: string(s1
.ptr
, s1
.len
, s2
, strlen(s2
));
148 inline string
operator+(const char *s1
, const string
&s2
)
154 return string(s1
, strlen(s1
), s2
.ptr
, s2
.len
);
156 return s1
== 0 ? s2
: string(s1
, strlen(s1
), s2
.ptr
, s2
.len
);
160 inline string
operator+(const string
&s
, char c
)
162 return string(s
.ptr
, s
.len
, &c
, 1);
165 inline string
operator+(char c
, const string
&s
)
167 return string(&c
, 1, s
.ptr
, s
.len
);
170 inline int operator==(const string
&s1
, const string
&s2
)
172 return (s1
.len
== s2
.len
173 && (s1
.len
== 0 || memcmp(s1
.ptr
, s2
.ptr
, s1
.len
) == 0));
176 inline int operator!=(const string
&s1
, const string
&s2
)
178 return (s1
.len
!= s2
.len
179 || (s1
.len
!= 0 && memcmp(s1
.ptr
, s2
.ptr
, s1
.len
) != 0));
182 inline string
string::substring(int i
, int n
) const
184 assert(i
>= 0 && i
+ n
<= len
);
185 return string(ptr
+ i
, n
);
188 inline string
&string::operator+=(char c
)
196 void put_string(const string
&, FILE *);
198 string
as_string(int);