2 /* Copyright (C) 1989-2018 Free Software Foundation, Inc.
3 Written by James Clark (jjc@jclark.com)
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 3 of the License, or
10 (at your option) any later version.
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
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
24 // Ensure that the first declaration of functions that are later
25 // declared as inline declares them as inline.
29 inline string operator+(const string &, const string &);
30 inline string operator+(const string &, const char *);
31 inline string operator+(const char *, const string &);
32 inline string operator+(const string &, char);
33 inline string operator+(char, const string &);
34 inline int operator==(const string &, const string &);
35 inline int operator!=(const string &, const string &);
40 string(const string &);
42 string(const char *, int);
47 string &operator=(const string &);
48 string &operator=(const char *);
49 string &operator=(char);
51 string &operator+=(const string &);
52 string &operator+=(const char *);
53 string &operator+=(char);
54 void append(const char *, int);
58 int operator*() const;
60 string substring(int i, int n) const;
62 char &operator[](int);
63 char operator[](int) const;
65 void set_length(int i);
66 const char *contents() const;
67 int search(char) const;
68 char *extract() const;
73 friend string operator+(const string &, const string &);
74 friend string operator+(const string &, const char *);
75 friend string operator+(const char *, const string &);
76 friend string operator+(const string &, char);
77 friend string operator+(char, const string &);
79 friend int operator==(const string &, const string &);
80 friend int operator!=(const string &, const string &);
81 friend int operator<=(const string &, 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 &);
91 string(const char *, int, const char *, int); // for use by operator+
96 inline char &string::operator[](int i)
98 assert(i >= 0 && i < len);
102 inline char string::operator[](int i) const
104 assert(i >= 0 && i < len);
108 inline int string::length() const
113 inline int string::empty() const
118 inline int string::operator*() const
123 inline const char *string::contents() const
128 inline string operator+(const string &s1, const string &s2)
130 return string(s1.ptr, s1.len, s2.ptr, s2.len);
133 inline string operator+(const string &s1, const char *s2)
139 return string(s1.ptr, s1.len, s2, strlen(s2));
141 return s2 == 0 ? s1 : string(s1.ptr, s1.len, s2, strlen(s2));
145 inline string operator+(const char *s1, const string &s2)
151 return string(s1, strlen(s1), s2.ptr, s2.len);
153 return s1 == 0 ? s2 : string(s1, strlen(s1), s2.ptr, s2.len);
157 inline string operator+(const string &s, char c)
159 return string(s.ptr, s.len, &c, 1);
162 inline string operator+(char c, const string &s)
164 return string(&c, 1, s.ptr, s.len);
167 inline int operator==(const string &s1, const string &s2)
169 return (s1.len == s2.len
170 && (s1.len == 0 || memcmp(s1.ptr, s2.ptr, s1.len) == 0));
173 inline int operator!=(const string &s1, const string &s2)
175 return (s1.len != s2.len
176 || (s1.len != 0 && memcmp(s1.ptr, s2.ptr, s1.len) != 0));
179 inline string string::substring(int i, int n) const
181 assert(i >= 0 && i + n <= len);
182 return string(ptr + i, n);
185 inline string &string::operator+=(char c)
193 void put_string(const string &, FILE *);
195 string as_string(int);