The Battle for Wesnoth  1.15.0-dev
string_view.hpp
Go to the documentation of this file.
1 /*
2  Copyright (c) Marshall Clow 2012-2015.
3  Copyright (c) Beman Dawes 2015
4  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY.
12 
13  See the COPYING file for more details.
14 */
15 
16 /* This file is the Boost string_view implementation in a single header file.
17 We have an in-tree copy because not all versions of Boost we support have
18 that class. */
19 
20 #pragma once
21 
22 #include <boost/version.hpp>
23 #include <cstdint>
24 
25 #if BOOST_VERSION > 106100
26 
27 /* Boost string_view is available, so we can just use it. */
28 #include <boost/utility/string_view.hpp>
29 
30 namespace utils {
32 typedef boost::basic_string_view<uint8_t, std::char_traits<uint8_t>> byte_string_view;
33 }
34 
35 #else
36 
37 #include <boost/config.hpp>
38 #include <boost/detail/workaround.hpp>
39 #include <boost/throw_exception.hpp>
40 
41 #include <cstddef>
42 #include <stdexcept>
43 #include <algorithm>
44 #include <iterator>
45 #include <string>
46 #include <cstring>
47 #include <iosfwd>
48 
49 #if BOOST_VERSION <= 105600
50 # define BOOST_CXX14_CONSTEXPR
51 #endif
52 
53 namespace utils {
54 
55 namespace detail {
56 // A helper functor because sometimes we don't have lambdas
57 template <typename charT, typename traits>
59 public:
60  string_view_traits_eq(charT ch) : ch_(ch) {}
61  bool operator()(charT val) const { return traits::eq(ch_, val); }
62  charT ch_;
63 };
64 }
65 
66 template<typename charT, typename traits = std::char_traits<charT>> class basic_string_view;
67 
68 template<typename charT, typename traits>
69 class basic_string_view {
70 public:
71  // types
72  typedef traits traits_type;
73  typedef charT value_type;
74  typedef charT* pointer;
75  typedef const charT* const_pointer;
76  typedef charT& reference;
77  typedef const charT& const_reference;
78  typedef const_pointer const_iterator; // impl-defined
79  typedef const_iterator iterator;
80  typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
81  typedef const_reverse_iterator reverse_iterator;
82  typedef std::size_t size_type;
83  typedef std::ptrdiff_t difference_type;
84  static BOOST_CONSTEXPR_OR_CONST size_type npos = size_type(-1);
85 
86  // construct/copy
87  BOOST_CONSTEXPR basic_string_view() BOOST_NOEXCEPT
88  : ptr_(NULL), len_(0) {}
89 
90  // by defaulting these functions, basic_string_ref becomes
91  // trivially copy/move constructible.
92  BOOST_CONSTEXPR basic_string_view(const basic_string_view &rhs) BOOST_NOEXCEPT = default;
93 
94  basic_string_view& operator=(const basic_string_view &rhs) BOOST_NOEXCEPT = default;
95 
96  template<typename Allocator>
97  basic_string_view(const std::basic_string<charT, traits, Allocator>& str) BOOST_NOEXCEPT
98  : ptr_(str.data()), len_(str.length()) {}
99 
100  // #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && !defined(BOOST_NO_CXX11_DELETED_FUNCTIONS)
101  // // Constructing a string_view from a temporary string is a bad idea
102  // template<typename Allocator>
103  // basic_string_view( std::basic_string<charT, traits, Allocator>&&)
104  // = delete;
105  // #endif
106 
107  BOOST_CONSTEXPR basic_string_view(const charT* str)
108  : ptr_(str), len_(traits::length(str)) {}
109 
110  BOOST_CONSTEXPR basic_string_view(const charT* str, size_type len)
111  : ptr_(str), len_(len) {}
112 
113  // iterators
114  BOOST_CONSTEXPR const_iterator begin() const BOOST_NOEXCEPT { return ptr_; }
115  BOOST_CONSTEXPR const_iterator cbegin() const BOOST_NOEXCEPT { return ptr_; }
116  BOOST_CONSTEXPR const_iterator end() const BOOST_NOEXCEPT { return ptr_ + len_; }
117  BOOST_CONSTEXPR const_iterator cend() const BOOST_NOEXCEPT { return ptr_ + len_; }
118  const_reverse_iterator rbegin() const BOOST_NOEXCEPT { return const_reverse_iterator(end()); }
119  const_reverse_iterator crbegin() const BOOST_NOEXCEPT { return const_reverse_iterator(end()); }
120  const_reverse_iterator rend() const BOOST_NOEXCEPT { return const_reverse_iterator(begin()); }
121  const_reverse_iterator crend() const BOOST_NOEXCEPT { return const_reverse_iterator(begin()); }
122 
123  // capacity
124  BOOST_CONSTEXPR size_type size() const BOOST_NOEXCEPT { return len_; }
125  BOOST_CONSTEXPR size_type length() const BOOST_NOEXCEPT { return len_; }
126  BOOST_CONSTEXPR size_type max_size() const BOOST_NOEXCEPT { return len_; }
127  BOOST_CONSTEXPR bool empty() const BOOST_NOEXCEPT { return len_ == 0; }
128 
129  // element access
130  BOOST_CONSTEXPR const_reference operator[](size_type pos) const BOOST_NOEXCEPT { return ptr_[pos]; }
131 
132  const_reference at(std::size_t pos) const {
133  return pos >= len_ ? BOOST_THROW_EXCEPTION(std::out_of_range("boost::string_view::at")), ptr_[0] : ptr_[pos];
134  }
135 
136  BOOST_CONSTEXPR const_reference front() const { return ptr_[0]; }
137  BOOST_CONSTEXPR const_reference back() const { return ptr_[len_ - 1]; }
138  BOOST_CONSTEXPR const_pointer data() const BOOST_NOEXCEPT { return ptr_; }
139 
140  // modifiers
141  void clear() BOOST_NOEXCEPT{ len_ = 0; } // Boost extension
142 
144  if(n > len_)
145  n = len_;
146  ptr_ += n;
147  len_ -= n;
148  }
149 
151  if(n > len_)
152  n = len_;
153  len_ -= n;
154  }
155 
157  std::swap(ptr_, s.ptr_);
158  std::swap(len_, s.len_);
159  }
160 
161  // basic_string_view string operations
162 #ifndef BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS
163  template<typename Allocator>
164  explicit operator std::basic_string<charT, traits, Allocator>() const {
165  return std::basic_string<charT, traits, Allocator>(begin(), end());
166  }
167 #endif
168 
169 #ifndef BOOST_NO_CXX11_FUNCTION_TEMPLATE_DEFAULT_ARGS
170  template<typename Allocator = std::allocator<charT>>
171  std::basic_string<charT, traits, Allocator> to_string(const Allocator& a = Allocator()) const {
172  return std::basic_string<charT, traits, Allocator>(begin(), end(), a);
173  }
174 #else
175  std::basic_string<charT, traits> to_string() const {
176  return std::basic_string<charT, traits>(begin(), end());
177  }
178 
179  template<typename Allocator>
180  std::basic_string<charT, traits, Allocator> to_string(const Allocator& a) const {
181  return std::basic_string<charT, traits, Allocator>(begin(), end(), a);
182  }
183 #endif
184 
185  size_type copy(charT* s, size_type n, size_type pos = 0) const {
186  if(pos > size())
187  BOOST_THROW_EXCEPTION(std::out_of_range("string_view::copy"));
188  size_type rlen = (std::min)(n, len_ - pos);
189  traits_type::copy(s, data() + pos, rlen);
190  return rlen;
191  }
192 
193  BOOST_CXX14_CONSTEXPR basic_string_view substr(size_type pos, size_type n = npos) const {
194  if(pos > size())
195  BOOST_THROW_EXCEPTION(std::out_of_range("string_view::substr"));
196  return basic_string_view(data() + pos, (std::min)(size() - pos, n));
197  }
198 
199  BOOST_CXX14_CONSTEXPR int compare(basic_string_view x) const BOOST_NOEXCEPT {
200  const int cmp = traits::compare(ptr_, x.ptr_, (std::min)(len_, x.len_));
201  return cmp != 0 ? cmp : (len_ == x.len_ ? 0 : len_ < x.len_ ? -1 : 1);
202  }
203 
204  BOOST_CXX14_CONSTEXPR int compare(size_type pos1, size_type n1, basic_string_view x)
205  const BOOST_NOEXCEPT {
206  return substr(pos1, n1).compare(x);
207  }
208 
209  BOOST_CXX14_CONSTEXPR int compare(size_type pos1, size_type n1,
210  basic_string_view x, size_type pos2, size_type n2) const {
211  return substr(pos1, n1).compare(x.substr(pos2, n2));
212  }
213 
214  BOOST_CXX14_CONSTEXPR int compare(const charT* x) const {
215  return compare(basic_string_view(x));
216  }
217 
218  BOOST_CXX14_CONSTEXPR int compare(size_type pos1, size_type n1, const charT* x) const {
219  return substr(pos1, n1).compare(basic_string_view(x));
220  }
221 
222  BOOST_CXX14_CONSTEXPR int compare(size_type pos1, size_type n1,
223  const charT* x, size_type n2) const {
224  return substr(pos1, n1).compare(basic_string_view(x, n2));
225  }
226 
227  // Searches
228  BOOST_CONSTEXPR bool starts_with(charT c) const BOOST_NOEXCEPT { // Boost extension
229  return !empty() && traits::eq(c, front());
230  }
231 
232  BOOST_CONSTEXPR bool starts_with(basic_string_view x) const BOOST_NOEXCEPT { // Boost extension
233  return len_ >= x.len_ && traits::compare(ptr_, x.ptr_, x.len_) == 0;
234  }
235 
236  BOOST_CONSTEXPR bool ends_with(charT c) const BOOST_NOEXCEPT { // Boost extension
237  return !empty() && traits::eq(c, back());
238  }
239 
240  BOOST_CONSTEXPR bool ends_with(basic_string_view x) const BOOST_NOEXCEPT { // Boost extension
241  return len_ >= x.len_ &&
242  traits::compare(ptr_ + len_ - x.len_, x.ptr_, x.len_) == 0;
243  }
244 
245  // find
246  BOOST_CXX14_CONSTEXPR size_type find(basic_string_view s, size_type pos = 0) const BOOST_NOEXCEPT {
247  if(pos > size())
248  return npos;
249  if(s.empty())
250  return pos;
251  const_iterator iter = std::search(this->cbegin() + pos, this->cend(),
252  s.cbegin(), s.cend(), traits::eq);
253  return iter == this->cend() ? npos : std::distance(this->cbegin(), iter);
254  }
255  BOOST_CXX14_CONSTEXPR size_type find(charT c, size_type pos = 0) const BOOST_NOEXCEPT
256  { return find(basic_string_view(&c, 1), pos); }
257  BOOST_CXX14_CONSTEXPR size_type find(const charT* s, size_type pos, size_type n) const BOOST_NOEXCEPT
258  { return find(basic_string_view(s, n), pos); }
259  BOOST_CXX14_CONSTEXPR size_type find(const charT* s, size_type pos = 0) const BOOST_NOEXCEPT
260  { return find(basic_string_view(s), pos); }
261 
262  // rfind
263  BOOST_CXX14_CONSTEXPR size_type rfind(basic_string_view s, size_type pos = npos) const BOOST_NOEXCEPT {
264  if(len_ < s.len_)
265  return npos;
266  if(pos > len_ - s.len_)
267  pos = len_ - s.len_;
268  if(s.len_ == 0u) // an empty string is always found
269  return pos;
270  for(const charT* cur = ptr_ + pos;; --cur) {
271  if(traits::compare(cur, s.ptr_, s.len_) == 0)
272  return cur - ptr_;
273  if(cur == ptr_)
274  return npos;
275  };
276  }
277  BOOST_CXX14_CONSTEXPR size_type rfind(charT c, size_type pos = npos) const BOOST_NOEXCEPT
278  { return rfind(basic_string_view(&c, 1), pos); }
279  BOOST_CXX14_CONSTEXPR size_type rfind(const charT* s, size_type pos, size_type n) const BOOST_NOEXCEPT
280  { return rfind(basic_string_view(s, n), pos); }
281  BOOST_CXX14_CONSTEXPR size_type rfind(const charT* s, size_type pos = npos) const BOOST_NOEXCEPT
282  { return rfind(basic_string_view(s), pos); }
283 
284  // find_first_of
285  BOOST_CXX14_CONSTEXPR size_type find_first_of(basic_string_view s, size_type pos = 0) const BOOST_NOEXCEPT {
286  if(pos >= len_ || s.len_ == 0)
287  return npos;
288  const_iterator iter = std::find_first_of
289  (this->cbegin() + pos, this->cend(), s.cbegin(), s.cend(), traits::eq);
290  return iter == this->cend() ? npos : std::distance(this->cbegin(), iter);
291  }
292  BOOST_CXX14_CONSTEXPR size_type find_first_of(charT c, size_type pos = 0) const BOOST_NOEXCEPT
293  { return find_first_of(basic_string_view(&c, 1), pos); }
294  BOOST_CXX14_CONSTEXPR size_type find_first_of(const charT* s, size_type pos, size_type n) const BOOST_NOEXCEPT
295  { return find_first_of(basic_string_view(s, n), pos); }
296  BOOST_CXX14_CONSTEXPR size_type find_first_of(const charT* s, size_type pos = 0) const BOOST_NOEXCEPT
297  { return find_first_of(basic_string_view(s), pos); }
298 
299  // find_last_of
300  BOOST_CXX14_CONSTEXPR size_type find_last_of(basic_string_view s, size_type pos = npos) const BOOST_NOEXCEPT {
301  if(s.len_ == 0u)
302  return npos;
303  if(pos >= len_)
304  pos = 0;
305  else
306  pos = len_ - (pos + 1);
307  const_reverse_iterator iter = std::find_first_of
308  (this->crbegin() + pos, this->crend(), s.cbegin(), s.cend(), traits::eq);
309  return iter == this->crend() ? npos : reverse_distance(this->crbegin(), iter);
310  }
311  BOOST_CXX14_CONSTEXPR size_type find_last_of(charT c, size_type pos = npos) const BOOST_NOEXCEPT
312  { return find_last_of(basic_string_view(&c, 1), pos); }
313  BOOST_CXX14_CONSTEXPR size_type find_last_of(const charT* s, size_type pos, size_type n) const BOOST_NOEXCEPT
314  { return find_last_of(basic_string_view(s, n), pos); }
315  BOOST_CXX14_CONSTEXPR size_type find_last_of(const charT* s, size_type pos = npos) const BOOST_NOEXCEPT
316  { return find_last_of(basic_string_view(s), pos); }
317 
318  // find_first_not_of
319  BOOST_CXX14_CONSTEXPR size_type find_first_not_of(basic_string_view s, size_type pos = 0) const BOOST_NOEXCEPT {
320  if(pos >= len_)
321  return npos;
322  if(s.len_ == 0)
323  return pos;
324  const_iterator iter = find_not_of(this->cbegin() + pos, this->cend(), s);
325  return iter == this->cend() ? npos : std::distance(this->cbegin(), iter);
326  }
327  BOOST_CXX14_CONSTEXPR size_type find_first_not_of(charT c, size_type pos = 0) const BOOST_NOEXCEPT
328  { return find_first_not_of(basic_string_view(&c, 1), pos); }
329  BOOST_CXX14_CONSTEXPR size_type find_first_not_of(const charT* s, size_type pos, size_type n) const BOOST_NOEXCEPT
330  { return find_first_not_of(basic_string_view(s, n), pos); }
331  BOOST_CXX14_CONSTEXPR size_type find_first_not_of(const charT* s, size_type pos = 0) const BOOST_NOEXCEPT
332  { return find_first_not_of(basic_string_view(s), pos); }
333 
334  // find_last_not_of
335  BOOST_CXX14_CONSTEXPR size_type find_last_not_of(basic_string_view s, size_type pos = npos) const BOOST_NOEXCEPT {
336  if(pos >= len_)
337  pos = len_ - 1;
338  if(s.len_ == 0u)
339  return pos;
340  pos = len_ - (pos + 1);
341  const_reverse_iterator iter = find_not_of(this->crbegin() + pos, this->crend(), s);
342  return iter == this->crend() ? npos : reverse_distance(this->crbegin(), iter);
343  }
344  BOOST_CXX14_CONSTEXPR size_type find_last_not_of(charT c, size_type pos = npos) const BOOST_NOEXCEPT
345  { return find_last_not_of(basic_string_view(&c, 1), pos); }
346  BOOST_CXX14_CONSTEXPR size_type find_last_not_of(const charT* s, size_type pos, size_type n) const BOOST_NOEXCEPT
347  { return find_last_not_of(basic_string_view(s, n), pos); }
348  BOOST_CXX14_CONSTEXPR size_type find_last_not_of(const charT* s, size_type pos = npos) const BOOST_NOEXCEPT
349  { return find_last_not_of(basic_string_view(s), pos); }
350 
351 private:
352  template <typename r_iter>
353  size_type reverse_distance(r_iter first, r_iter last) const BOOST_NOEXCEPT {
354  // Portability note here: std::distance is not noexcept, but calling it with a string_view::reverse_iterator will not throw.
355  return len_ - 1 - std::distance(first, last);
356  }
357 
358  template <typename Iterator>
359  Iterator find_not_of(Iterator first, Iterator last, basic_string_view s) const BOOST_NOEXCEPT {
360  for(; first != last; ++first)
361  if(0 == traits::find(s.ptr_, s.len_, *first))
362  return first;
363  return last;
364  }
365 
366  const charT *ptr_;
367  std::size_t len_;
368 };
369 
370 
371 // Comparison operators
372 // Equality
373 template<typename charT, typename traits>
375  basic_string_view<charT, traits> y) BOOST_NOEXCEPT {
376  if(x.size() != y.size()) return false;
377  return x.compare(y) == 0;
378 }
379 
380 // Inequality
381 template<typename charT, typename traits>
383  basic_string_view<charT, traits> y) BOOST_NOEXCEPT {
384  if(x.size() != y.size()) return true;
385  return x.compare(y) != 0;
386 }
387 
388 // Less than
389 template<typename charT, typename traits>
390 inline bool operator<(basic_string_view<charT, traits> x,
391  basic_string_view<charT, traits> y) BOOST_NOEXCEPT {
392  return x.compare(y) < 0;
393 }
394 
395 // Greater than
396 template<typename charT, typename traits>
398  basic_string_view<charT, traits> y) BOOST_NOEXCEPT {
399  return x.compare(y) > 0;
400 }
401 
402 // Less than or equal to
403 template<typename charT, typename traits>
404 inline bool operator<=(basic_string_view<charT, traits> x,
405  basic_string_view<charT, traits> y) BOOST_NOEXCEPT {
406  return x.compare(y) <= 0;
407 }
408 
409 // Greater than or equal to
410 template<typename charT, typename traits>
412  basic_string_view<charT, traits> y) BOOST_NOEXCEPT {
413  return x.compare(y) >= 0;
414 }
415 
416 // "sufficient additional overloads of comparison functions"
417 template<typename charT, typename traits, typename Allocator>
419  const std::basic_string<charT, traits, Allocator> & y) BOOST_NOEXCEPT {
420  return x == basic_string_view<charT, traits>(y);
421 }
422 
423 template<typename charT, typename traits, typename Allocator>
424 inline bool operator==(const std::basic_string<charT, traits, Allocator> & x,
425  basic_string_view<charT, traits> y) BOOST_NOEXCEPT {
426  return basic_string_view<charT, traits>(x) == y;
427 }
428 
429 template<typename charT, typename traits>
431  const charT * y) BOOST_NOEXCEPT {
432  return x == basic_string_view<charT, traits>(y);
433 }
434 
435 template<typename charT, typename traits>
436 inline bool operator==(const charT * x,
437  basic_string_view<charT, traits> y) BOOST_NOEXCEPT {
438  return basic_string_view<charT, traits>(x) == y;
439 }
440 
441 template<typename charT, typename traits, typename Allocator>
443  const std::basic_string<charT, traits, Allocator> & y) BOOST_NOEXCEPT {
444  return x != basic_string_view<charT, traits>(y);
445 }
446 
447 template<typename charT, typename traits, typename Allocator>
448 inline bool operator!=(const std::basic_string<charT, traits, Allocator> & x,
449  basic_string_view<charT, traits> y) BOOST_NOEXCEPT {
450  return basic_string_view<charT, traits>(x) != y;
451 }
452 
453 template<typename charT, typename traits>
455  const charT * y) BOOST_NOEXCEPT {
456  return x != basic_string_view<charT, traits>(y);
457 }
458 
459 template<typename charT, typename traits>
460 inline bool operator!=(const charT * x,
461  basic_string_view<charT, traits> y) BOOST_NOEXCEPT {
462  return basic_string_view<charT, traits>(x) != y;
463 }
464 
465 template<typename charT, typename traits, typename Allocator>
466 inline bool operator<(basic_string_view<charT, traits> x,
467  const std::basic_string<charT, traits, Allocator> & y) BOOST_NOEXCEPT {
468  return x < basic_string_view<charT, traits>(y);
469 }
470 
471 template<typename charT, typename traits, typename Allocator>
472 inline bool operator<(const std::basic_string<charT, traits, Allocator> & x,
473  basic_string_view<charT, traits> y) BOOST_NOEXCEPT {
474  return basic_string_view<charT, traits>(x) < y;
475 }
476 
477 template<typename charT, typename traits>
478 inline bool operator<(basic_string_view<charT, traits> x,
479  const charT * y) BOOST_NOEXCEPT {
480  return x < basic_string_view<charT, traits>(y);
481 }
482 
483 template<typename charT, typename traits>
484 inline bool operator<(const charT * x,
485  basic_string_view<charT, traits> y) BOOST_NOEXCEPT {
486  return basic_string_view<charT, traits>(x) < y;
487 }
488 
489 template<typename charT, typename traits, typename Allocator>
491  const std::basic_string<charT, traits, Allocator> & y) BOOST_NOEXCEPT {
492  return x > basic_string_view<charT, traits>(y);
493 }
494 
495 template<typename charT, typename traits, typename Allocator>
496 inline bool operator>(const std::basic_string<charT, traits, Allocator> & x,
497  basic_string_view<charT, traits> y) BOOST_NOEXCEPT {
498  return basic_string_view<charT, traits>(x) > y;
499 }
500 
501 template<typename charT, typename traits>
503  const charT * y) BOOST_NOEXCEPT {
504  return x > basic_string_view<charT, traits>(y);
505 }
506 
507 template<typename charT, typename traits>
508 inline bool operator>(const charT * x,
509  basic_string_view<charT, traits> y) BOOST_NOEXCEPT {
510  return basic_string_view<charT, traits>(x) > y;
511 }
512 
513 template<typename charT, typename traits, typename Allocator>
514 inline bool operator<=(basic_string_view<charT, traits> x,
515  const std::basic_string<charT, traits, Allocator> & y) BOOST_NOEXCEPT {
516  return x <= basic_string_view<charT, traits>(y);
517 }
518 
519 template<typename charT, typename traits, typename Allocator>
520 inline bool operator<=(const std::basic_string<charT, traits, Allocator> & x,
521  basic_string_view<charT, traits> y) BOOST_NOEXCEPT {
522  return basic_string_view<charT, traits>(x) <= y;
523 }
524 
525 template<typename charT, typename traits>
526 inline bool operator<=(basic_string_view<charT, traits> x,
527  const charT * y) BOOST_NOEXCEPT {
528  return x <= basic_string_view<charT, traits>(y);
529 }
530 
531 template<typename charT, typename traits>
532 inline bool operator<=(const charT * x,
533  basic_string_view<charT, traits> y) BOOST_NOEXCEPT {
534  return basic_string_view<charT, traits>(x) <= y;
535 }
536 
537 template<typename charT, typename traits, typename Allocator>
539  const std::basic_string<charT, traits, Allocator> & y) BOOST_NOEXCEPT {
540  return x >= basic_string_view<charT, traits>(y);
541 }
542 
543 template<typename charT, typename traits, typename Allocator>
544 inline bool operator>=(const std::basic_string<charT, traits, Allocator> & x,
545  basic_string_view<charT, traits> y) BOOST_NOEXCEPT {
546  return basic_string_view<charT, traits>(x) >= y;
547 }
548 
549 template<typename charT, typename traits>
551  const charT * y) BOOST_NOEXCEPT {
552  return x >= basic_string_view<charT, traits>(y);
553 }
554 
555 template<typename charT, typename traits>
556 inline bool operator>=(const charT * x,
557  basic_string_view<charT, traits> y) BOOST_NOEXCEPT {
558  return basic_string_view<charT, traits>(x) >= y;
559 }
560 
561 namespace detail {
562 
563 template<class charT, class traits>
564 inline void sv_insert_fill_chars(std::basic_ostream<charT, traits>& os, std::size_t n) {
565  enum { chunk_size = 8 };
566  charT fill_chars[chunk_size];
567  std::fill_n(fill_chars, static_cast< std::size_t >(chunk_size), os.fill());
568  for(; n >= chunk_size && os.good(); n -= chunk_size)
569  os.write(fill_chars, static_cast< std::size_t >(chunk_size));
570  if(n > 0 && os.good())
571  os.write(fill_chars, n);
572 }
573 
574 template<class charT, class traits>
575 void sv_insert_aligned(std::basic_ostream<charT, traits>& os, const basic_string_view<charT, traits>& str) {
576  const std::size_t size = str.size();
577  const std::size_t alignment_size = static_cast< std::size_t >(os.width()) - size;
578  const bool align_left = (os.flags() & std::basic_ostream<charT, traits>::adjustfield) == std::basic_ostream<charT, traits>::left;
579  if(!align_left) {
580  detail::sv_insert_fill_chars(os, alignment_size);
581  if(os.good())
582  os.write(str.data(), size);
583  } else {
584  os.write(str.data(), size);
585  if(os.good())
586  detail::sv_insert_fill_chars(os, alignment_size);
587  }
588 }
589 
590 } // namespace detail
591 
592 // Inserter
593 template<class charT, class traits>
594 inline std::basic_ostream<charT, traits>&
595 operator<<(std::basic_ostream<charT, traits>& os,
597  if(os.good()) {
598  const std::size_t size = str.size();
599  const std::size_t w = static_cast< std::size_t >(os.width());
600  if(w <= size)
601  os.write(str.data(), size);
602  else
603  detail::sv_insert_aligned(os, str);
604  os.width(0);
605  }
606  return os;
607 }
608 
612 
613 #ifndef BOOST_NO_CXX11_CHAR16_T
615 #endif
616 
617 #ifndef BOOST_NO_CXX11_CHAR32_T
619 #endif
620 
621 }
622 
623 #endif
BOOST_CXX14_CONSTEXPR size_type find_last_of(const charT *s, size_type pos, size_type n) const BOOST_NOEXCEPT
bool operator<(basic_string_view< charT, traits > x, basic_string_view< charT, traits > y) BOOST_NOEXCEPT
BOOST_CXX14_CONSTEXPR void remove_suffix(size_type n)
bool operator==(basic_string_view< charT, traits > x, basic_string_view< charT, traits > y) BOOST_NOEXCEPT
BOOST_CONSTEXPR basic_string_view() BOOST_NOEXCEPT
Definition: string_view.hpp:87
BOOST_CXX14_CONSTEXPR size_type find(basic_string_view s, size_type pos=0) const BOOST_NOEXCEPT
BOOST_CXX14_CONSTEXPR size_type find_last_not_of(basic_string_view s, size_type pos=npos) const BOOST_NOEXCEPT
size_type reverse_distance(r_iter first, r_iter last) const BOOST_NOEXCEPT
bool operator!=(basic_string_view< charT, traits > x, basic_string_view< charT, traits > y) BOOST_NOEXCEPT
BOOST_CONSTEXPR bool starts_with(charT c) const BOOST_NOEXCEPT
BOOST_CXX14_CONSTEXPR size_type find_first_of(const charT *s, size_type pos=0) const BOOST_NOEXCEPT
BOOST_CXX14_CONSTEXPR size_type rfind(const charT *s, size_type pos=npos) const BOOST_NOEXCEPT
BOOST_CONSTEXPR bool ends_with(basic_string_view x) const BOOST_NOEXCEPT
BOOST_CXX14_CONSTEXPR size_type rfind(charT c, size_type pos=npos) const BOOST_NOEXCEPT
#define a
int compare(const std::string &s1, const std::string &s2)
Case-sensitive lexicographical comparison.
Definition: gettext.cpp:458
const_reverse_iterator rbegin() const BOOST_NOEXCEPT
BOOST_CXX14_CONSTEXPR void remove_prefix(size_type n)
const_iterator iterator
Definition: string_view.hpp:79
BOOST_CXX14_CONSTEXPR int compare(basic_string_view x) const BOOST_NOEXCEPT
basic_string_view(const std::basic_string< charT, traits, Allocator > &str) BOOST_NOEXCEPT
Definition: string_view.hpp:97
BOOST_CXX14_CONSTEXPR size_type find_first_not_of(charT c, size_type pos=0) const BOOST_NOEXCEPT
#define BOOST_CXX14_CONSTEXPR
Definition: string_view.hpp:50
BOOST_CXX14_CONSTEXPR size_type find_last_not_of(const charT *s, size_type pos=npos) const BOOST_NOEXCEPT
BOOST_CXX14_CONSTEXPR basic_string_view substr(size_type pos, size_type n=npos) const
bool operator()(charT val) const
Definition: string_view.hpp:61
BOOST_CONSTEXPR const_iterator cbegin() const BOOST_NOEXCEPT
BOOST_CONSTEXPR size_type length() const BOOST_NOEXCEPT
BOOST_CXX14_CONSTEXPR size_type find_last_of(const charT *s, size_type pos=npos) const BOOST_NOEXCEPT
basic_string_view< char, std::char_traits< char > > string_view
basic_string_view< wchar_t, std::char_traits< wchar_t > > wstring_view
BOOST_CONSTEXPR const_reference operator[](size_type pos) const BOOST_NOEXCEPT
const charT * const_pointer
Definition: string_view.hpp:75
BOOST_CXX14_CONSTEXPR int compare(size_type pos1, size_type n1, const charT *x) const
size_type copy(charT *s, size_type n, size_type pos=0) const
std::basic_string< charT, traits, Allocator > to_string(const Allocator &a=Allocator()) const
BOOST_CONSTEXPR const_pointer data() const BOOST_NOEXCEPT
basic_string_view< char16_t, std::char_traits< char16_t > > u16string_view
Iterator find_not_of(Iterator first, Iterator last, basic_string_view s) const BOOST_NOEXCEPT
basic_string_view< char32_t, std::char_traits< char32_t > > u32string_view
std::size_t size(const std::string &str)
Length in characters of a UTF-8 string.
Definition: unicode.cpp:86
BOOST_CXX14_CONSTEXPR void swap(basic_string_view &s) BOOST_NOEXCEPT
BOOST_CXX14_CONSTEXPR size_type find_first_not_of(basic_string_view s, size_type pos=0) const BOOST_NOEXCEPT
BOOST_CXX14_CONSTEXPR size_type find_first_of(charT c, size_type pos=0) const BOOST_NOEXCEPT
BOOST_CONSTEXPR basic_string_view(const charT *str, size_type len)
const_pointer const_iterator
Definition: string_view.hpp:78
BOOST_CXX14_CONSTEXPR int compare(const charT *x) const
BOOST_CONSTEXPR bool empty() const BOOST_NOEXCEPT
void swap(config &lhs, config &rhs)
Implement non-member swap function for std::swap (calls config::swap).
Definition: config.cpp:1339
BOOST_CXX14_CONSTEXPR int compare(size_type pos1, size_type n1, basic_string_view x, size_type pos2, size_type n2) const
BOOST_CXX14_CONSTEXPR size_type find_last_not_of(const charT *s, size_type pos, size_type n) const BOOST_NOEXCEPT
BOOST_CONSTEXPR size_type size() const BOOST_NOEXCEPT
const_reverse_iterator rend() const BOOST_NOEXCEPT
BOOST_CXX14_CONSTEXPR size_type find_first_not_of(const charT *s, size_type pos=0) const BOOST_NOEXCEPT
BOOST_CXX14_CONSTEXPR size_type find_last_of(basic_string_view s, size_type pos=npos) const BOOST_NOEXCEPT
BOOST_CXX14_CONSTEXPR size_type find(charT c, size_type pos=0) const BOOST_NOEXCEPT
BOOST_CONSTEXPR const_reference back() const
BOOST_CONSTEXPR const_iterator begin() const BOOST_NOEXCEPT
BOOST_CXX14_CONSTEXPR size_type rfind(const charT *s, size_type pos, size_type n) const BOOST_NOEXCEPT
static map_location::DIRECTION s
bool operator>=(basic_string_view< charT, traits > x, basic_string_view< charT, traits > y) BOOST_NOEXCEPT
void sv_insert_aligned(std::basic_ostream< charT, traits > &os, const basic_string_view< charT, traits > &str)
std::reverse_iterator< const_iterator > const_reverse_iterator
Definition: string_view.hpp:80
BOOST_CXX14_CONSTEXPR size_type find_first_of(const charT *s, size_type pos, size_type n) const BOOST_NOEXCEPT
BOOST_CONSTEXPR basic_string_view(const charT *str)
int w
void clear() BOOST_NOEXCEPT
BOOST_CONSTEXPR const_iterator cend() const BOOST_NOEXCEPT
const charT & const_reference
Definition: string_view.hpp:77
const_reverse_iterator crend() const BOOST_NOEXCEPT
BOOST_CXX14_CONSTEXPR size_type rfind(basic_string_view s, size_type pos=npos) const BOOST_NOEXCEPT
bool operator<=(basic_string_view< charT, traits > x, basic_string_view< charT, traits > y) BOOST_NOEXCEPT
BOOST_CONSTEXPR const_reference front() const
BOOST_CXX14_CONSTEXPR int compare(size_type pos1, size_type n1, const charT *x, size_type n2) const
BOOST_CONSTEXPR const_iterator end() const BOOST_NOEXCEPT
BOOST_CXX14_CONSTEXPR size_type find(const charT *s, size_type pos=0) const BOOST_NOEXCEPT
lu_byte left
Definition: lparser.cpp:1026
basic_string_view< uint8_t, std::char_traits< uint8_t > > byte_string_view
BOOST_CXX14_CONSTEXPR size_type find_last_not_of(charT c, size_type pos=npos) const BOOST_NOEXCEPT
BOOST_CXX14_CONSTEXPR size_type find_first_not_of(const charT *s, size_type pos, size_type n) const BOOST_NOEXCEPT
BOOST_CXX14_CONSTEXPR size_type find_first_of(basic_string_view s, size_type pos=0) const BOOST_NOEXCEPT
bool operator>(basic_string_view< charT, traits > x, basic_string_view< charT, traits > y) BOOST_NOEXCEPT
BOOST_CXX14_CONSTEXPR size_type find(const charT *s, size_type pos, size_type n) const BOOST_NOEXCEPT
BOOST_CONSTEXPR bool starts_with(basic_string_view x) const BOOST_NOEXCEPT
void sv_insert_fill_chars(std::basic_ostream< charT, traits > &os, std::size_t n)
const_reverse_iterator crbegin() const BOOST_NOEXCEPT
BOOST_CONSTEXPR bool ends_with(charT c) const BOOST_NOEXCEPT
mock_char c
std::ptrdiff_t difference_type
Definition: string_view.hpp:83
static map_location::DIRECTION n
const_reverse_iterator reverse_iterator
Definition: string_view.hpp:81
BOOST_CXX14_CONSTEXPR size_type find_last_of(charT c, size_type pos=npos) const BOOST_NOEXCEPT
BOOST_CONSTEXPR size_type max_size() const BOOST_NOEXCEPT
const_reference at(std::size_t pos) const
BOOST_CXX14_CONSTEXPR int compare(size_type pos1, size_type n1, basic_string_view x) const BOOST_NOEXCEPT