3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS.
13 #include "support/trivstring.h"
14 #include "support/docstring.h"
16 #ifdef STD_STRING_USES_COW
23 template trivial_string<char>::trivial_string(trivial_string const &);
24 template trivial_string<char_type>::trivial_string(trivial_string const &);
25 template<typename Char>
26 trivial_string<Char>::trivial_string(trivial_string const & that) : size_(that.size_)
29 copy(that.data_sso(), that.data_sso() + size_ + 1, data_sso());
31 data_ = new Char[size_ + 1];
32 copy(that.data_, that.data_ + size_ + 1, data_);
34 // else Happens only for really big Char types
38 template trivial_string<char>::trivial_string(string const &);
39 template trivial_string<char_type>::trivial_string(docstring const &);
40 template<typename Char>
41 trivial_string<Char>::trivial_string(
42 basic_string<Char, char_traits<Char>, allocator<Char> > const & that)
43 : size_(that.length())
46 copy(that.begin(), that.end(), data_sso());
47 data_sso()[size_] = '\0';
48 } else if (size_ > 0) {
49 data_ = new Char[size_ + 1];
50 copy(that.begin(), that.end(), data_);
53 // else Happens only for really big Char types
57 template trivial_string<char> &
58 trivial_string<char>::operator=(trivial_string const &);
59 template trivial_string<char_type> &
60 trivial_string<char_type>::operator=(trivial_string const &);
61 template<typename Char>
62 trivial_string<Char> & trivial_string<Char>::operator=(trivial_string const & that)
70 copy(that.data_sso(), that.data_sso() + size_ + 1, data_sso());
72 data_ = new Char[size_ + 1];
73 copy(that.data_, that.data_ + size_ + 1, data_);
75 // Happens only for really big Char types
82 template trivial_string<char> &
83 trivial_string<char>::operator=(string const &);
84 template trivial_string<char_type> &
85 trivial_string<char_type>::operator=(docstring const &);
86 template<typename Char>
87 trivial_string<Char> &
88 trivial_string<Char>::operator=(basic_string<Char, char_traits<Char>, allocator<Char> > const & that)
94 copy(that.begin(), that.end(), data_sso());
95 data_sso()[size_] = '\0';
96 } else if (size_ > 0) {
97 data_ = new Char[size_ + 1];
98 copy(that.begin(), that.end(), data_);
100 // Happens only for really big Char types
108 trivial_string<char>::swap(trivial_string<char> &);
110 trivial_string<char_type>::swap(trivial_string<char_type> &);
111 template<typename Char>
112 void trivial_string<Char>::swap(trivial_string & that)
114 size_t const sizetmp = that.size_;
117 Char * const datatmp = that.data_;
123 template<typename Char>
124 int trivial_string<Char>::compare(trivial_string const & other) const
126 size_t const lsize = this->length();
127 size_t const rsize = other.length();
128 size_t const len = min(lsize, rsize);
129 int r = char_traits<Char>::compare(c_str(), other.c_str(), len);
133 else if (lsize < rsize)
140 template trivial_string<char>::operator string() const;
141 template trivial_string<char_type>::operator docstring() const;
142 template<typename Char>
143 trivial_string<Char>::operator basic_string<Char, char_traits<Char>, allocator<Char> >() const
146 return basic_string<Char, char_traits<Char>, allocator<Char> >(
149 return basic_string<Char, char_traits<Char>, allocator<Char> >(
151 // Happens only for really big Char types
152 return basic_string<Char, char_traits<Char>, allocator<Char> >();
156 template char const * trivial_string<char>::c_str() const;
157 template char_type const * trivial_string<char_type>::c_str() const;
158 template<typename Char> Char const * trivial_string<Char>::c_str() const
164 // Happens only for really big Char types
165 static const Char empty_char = '\0';
170 template bool operator<(trivial_string<char> const &,
171 trivial_string<char> const &);
172 template bool operator<(trivial_string<char_type> const &,
173 trivial_string<char_type> const &);
174 template <typename Char>
175 bool operator<(trivial_string<Char> const & lhs, trivial_string<Char> const & rhs)
177 return lhs.compare(rhs) < 0;
181 template bool operator==(trivial_string<char> const &,
182 trivial_string<char> const &);
183 template bool operator==(trivial_string<char_type> const &,
184 trivial_string<char_type> const &);
185 template <typename Char>
186 bool operator==(trivial_string<Char> const & lhs, trivial_string<Char> const & rhs)
188 return lhs.compare(rhs) == 0;
192 template bool operator==(trivial_string<char> const &, char const *);
193 template bool operator==(trivial_string<char_type> const &, char_type const *);
194 template <typename Char>
195 bool operator==(trivial_string<Char> const & lhs, Char const * rhs)
197 return lhs.compare(trivial_string<Char>(rhs)) == 0;
201 template bool operator==(char const *, trivial_string<char> const &);
202 template bool operator==(char_type const *, trivial_string<char_type> const &);
203 template <typename Char>
204 bool operator==(Char const * lhs, trivial_string<Char> const & rhs)
206 return rhs.compare(trivial_string<Char>(lhs)) == 0;
210 template ostream & operator<<(ostream &, trivial_string<char> const &);
211 template odocstream & operator<<(odocstream &, trivial_string<char_type> const &);
212 template <typename Char>
213 basic_ostream<Char, char_traits<Char> > &
214 operator<<(basic_ostream<Char, char_traits<Char> > & os, trivial_string<Char> const & s)
216 return os << basic_string<Char, char_traits<Char>, allocator<Char> >(s);