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