-
Notifications
You must be signed in to change notification settings - Fork 219
/
string_view.hpp
1287 lines (1075 loc) · 47.9 KB
/
string_view.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//////////////////////////////////////////////////////////////////////////////////////////
// A multi-platform support c++11 library with focus on asynchronous socket I/O for any
// client application.
//////////////////////////////////////////////////////////////////////////////////////////
/*
The MIT License (MIT)
Copyright (c) 2012-2024 HALX99
Copyright (c) 2016 Matthew Rodusek([email protected]) <http://rodusek.me>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
See: https://github.com/bitwizeshift/string_view-standalone
*/
#ifndef YASIO__STRING_VIEW_HPP
#define YASIO__STRING_VIEW_HPP
#include <ctype.h>
#include <string.h>
#include <wchar.h>
#include <string>
#include "yasio/impl/char_traits.hpp"
#include "yasio/compiler/feature_test.hpp"
/// wcsncasecmp workaround for android API level < 23, copy from msvc ucrt 10.0.18362.0 'wcsnicmp'
#if (defined(__ANDROID_API__) && __ANDROID_API__ < 23) || defined(__MINGW32__)
inline int wcsncasecmp(wchar_t const* const lhs, wchar_t const* const rhs, size_t const count)
{
if (count == 0)
{
return 0;
}
wchar_t const* lhs_ptr = reinterpret_cast<wchar_t const*>(lhs);
wchar_t const* rhs_ptr = reinterpret_cast<wchar_t const*>(rhs);
int result;
int lhs_value;
int rhs_value;
size_t remaining = count;
do
{
lhs_value = ::towlower(*lhs_ptr++);
rhs_value = ::towlower(*rhs_ptr++);
result = lhs_value - rhs_value;
} while (result == 0 && lhs_value != 0 && --remaining != 0);
return result;
}
#endif
/// string_view workaround on c++11
#if YASIO__HAS_CXX17
# if __has_include(<string_view>)
# include <string_view>
# endif
#else
# include <algorithm>
# include <exception>
# include <stdexcept>
namespace cxx17
{
////////////////////////////////////////////////////////////////////////////
/// \brief A wrapper around non-owned strings.
///
/// This is an implementation of the C++17 string_view proposal
///
/// \ingroup core
////////////////////////////////////////////////////////////////////////////
template <typename _CharT, typename _Traits = std::char_traits<_CharT>>
class basic_string_view;
template <typename _CharT, typename _Traits>
class basic_string_view {
//------------------------------------------------------------------------
// Public Member Types
//------------------------------------------------------------------------
public:
using char_type = _CharT;
using traits_type = _Traits;
using size_type = size_t;
using value_type = _CharT;
using reference = value_type&;
using const_reference = const value_type&;
using pointer = value_type*;
using const_pointer = const value_type*;
using iterator = const _CharT*;
using const_iterator = const _CharT*;
//------------------------------------------------------------------------
// Public Members
//------------------------------------------------------------------------
public:
static const size_type npos = size_type(-1);
//------------------------------------------------------------------------
// Constructors
//------------------------------------------------------------------------
public:
/// \brief Default constructs a basic_string_view without any content
basic_string_view();
/// \brief Constructs a basic_string_view from a std::basic_string
///
/// \param str the string to view
template <typename Allocator>
basic_string_view(const std::basic_string<_CharT, _Traits, Allocator>& str);
/// \brief Constructs a basic_string_view from an ansi-string
///
/// \param str the string to view
basic_string_view(const char_type* str);
/// \brief Constructs a basic_string_view from an ansi string of a given size
///
/// \param str the string to view
/// \param count the size of the string
basic_string_view(const char_type* str, size_type count);
//------------------------------------------------------------------------
// Assignment
//------------------------------------------------------------------------
public:
//------------------------------------------------------------------------
// Capacity
//------------------------------------------------------------------------
public:
/// \brief Returns the length of the string, in terms of bytes
///
/// \return the length of the string, in terms of bytes
size_type size() const;
/// \copydoc basic_string_view::size
size_type length() const;
/// \brief The largest possible number of char-like objects that can be
/// referred to by a basic_string_view.
/// \return Maximum number of characters
size_type max_size() const;
/// \brief Returns whether the basic_string_view is empty
/// (i.e. whether its length is 0).
///
/// \return whether the basic_string_view is empty
bool empty() const;
//------------------------------------------------------------------------
// Element Access
//------------------------------------------------------------------------
public:
/// \brief Gets the ansi-string of the current basic_string_view
///
/// \return the ansi-string pointer
const char_type* c_str() const;
/// \brief Gets the data of the current basic_string_view
///
/// \note This is an alias of #c_str
///
/// \return the data this basic_string_view contains
const char_type* data() const;
/// \brief Accesses the element at index \p pos
///
/// \param pos the index to access
/// \return const reference to the character
const_reference operator[](size_t pos) const;
/// \brief Accesses the element at index \p pos
///
/// \param pos the index to access
/// \return const reference to the character
const_reference at(size_t pos) const;
/// \brief Access the first character of the string
///
/// \note Undefined behavior if basic_string_view is empty
///
/// \return reference to the first character of the string
const_reference front() const;
/// \brief References the last character of the string
///
/// \note Undefined behavior if basic_string_view is empty
///
/// \return reference to the last character of the string
const_reference back() const;
//------------------------------------------------------------------------
// Modifiers
//------------------------------------------------------------------------
public:
/// \brief Moves the start of the view forward by n characters.
///
/// The behavior is undefined if n > size().
///
/// \param n number of characters to remove from the start of the view
void remove_prefix(size_type n);
/// \brief Moves the end of the view back by n characters.
///
/// The behavior is undefined if n > size().
///
/// \param n number of characters to remove from the end of the view
void remove_suffix(size_type n);
/// \brief Exchanges the view with that of v.
///
/// \param v view to swap with
void swap(basic_string_view& v);
//------------------------------------------------------------------------
// Conversions
//------------------------------------------------------------------------
public:
/// \brief Creates a basic_string with a copy of the content of the current
/// view.
///
/// \tparam Allocator type used to allocate internal storage
/// \param a Allocator instance to use for allocating the new string
///
/// \return A basic_string containing a copy of the characters of the current
/// view.
template <class Allocator = std::allocator<_CharT>>
std::basic_string<_CharT, _Traits, Allocator> to_string(const Allocator& a = Allocator()) const;
/// \copydoc basic_string_view::to_string
template <class Allocator>
explicit operator std::basic_string<_CharT, _Traits, Allocator>() const;
//------------------------------------------------------------------------
// Operations
//------------------------------------------------------------------------
public:
/// \brief Copies the substring [pos, pos + rcount) to the character string
/// pointed
/// to by dest, where rcount is the smaller of count and size() - pos.
///
/// \param dest pointer to the destination character string
/// \param count requested substring length
/// \param pos position of the first character
size_type copy(char_type* dest, size_type count = npos, size_type pos = 0) const;
/// \brief Returns a substring of this viewed string
///
/// \param pos the position of the first character in the substring
/// \param len the length of the substring
/// \return the created substring
basic_string_view substr(size_t pos = 0, size_t len = npos) const;
//------------------------------------------------------------------------
/// \brief Compares two character sequences
///
/// \param v view to compare
/// \return negative value if this view is less than the other character
/// sequence, zero if the both character sequences are equal, positive
/// value if this view is greater than the other character sequence.
int compare(basic_string_view v) const;
/// \brief Compares two character sequences
///
/// \param pos position of the first character in this view to compare
/// \param count number of characters of this view to compare
/// \param v view to compare
/// \return negative value if this view is less than the other character
/// sequence, zero if the both character sequences are equal, positive
/// value if this view is greater than the other character sequence.
int compare(size_type pos, size_type count, basic_string_view v) const;
/// \brief Compares two character sequences
///
/// \param pos1 position of the first character in this view to compare
/// \param count1 number of characters of this view to compare
/// \param v view to compare
/// \param pos2 position of the second character in this view to compare
/// \param count2 number of characters of the given view to compare
/// \return negative value if this view is less than the other character
/// sequence, zero if the both character sequences are equal, positive
/// value if this view is greater than the other character sequence.
int compare(size_type pos1, size_type count1, basic_string_view v, size_type pos2, size_type count2) const;
/// \brief Compares two character sequences
///
/// \param s pointer to the character string to compare to
/// \return negative value if this view is less than the other character
/// sequence, zero if the both character sequences are equal, positive
/// value if this view is greater than the other character sequence.
int compare(const char_type* s) const;
/// \brief Compares two character sequences
///
/// \param pos position of the first character in this view to compare
/// \param count number of characters of this view to compare
/// \param s pointer to the character string to compare to
/// \return negative value if this view is less than the other character
/// sequence, zero if the both character sequences are equal, positive
/// value if this view is greater than the other character sequence.
int compare(size_type pos, size_type count, const char_type* s) const;
/// \brief Compares two character sequences
///
/// \param pos position of the first character in this view to compare
/// \param count1 number of characters of this view to compare
/// \param s pointer to the character string to compare to
/// \param count2 number of characters of the given view to compare
/// \return negative value if this view is less than the other character
/// sequence, zero if the both character sequences are equal, positive
/// value if this view is greater than the other character sequence.
int compare(size_type pos, size_type count1, const char_type* s, size_type count2) const;
//------------------------------------------------------------------------
size_type find(basic_string_view v, size_type pos = 0) const;
size_type find(char_type c, size_type pos = 0) const;
size_type find(const char_type* s, size_type pos, size_type count) const;
size_type find(const char_type* s, size_type pos = 0) const;
//------------------------------------------------------------------------
size_type rfind(basic_string_view v, size_type pos = npos) const;
size_type rfind(char_type c, size_type pos = npos) const;
size_type rfind(const char_type* s, size_type pos, size_type count) const;
size_type rfind(const char_type* s, size_type pos = npos) const;
//------------------------------------------------------------------------
size_type find_first_of(basic_string_view v, size_type pos = 0) const;
size_type find_first_of(char_type c, size_type pos = 0) const;
size_type find_first_of(const char_type* s, size_type pos, size_type count) const;
size_type find_first_of(const char_type* s, size_type pos = 0) const;
//------------------------------------------------------------------------
size_type find_last_of(basic_string_view v, size_type pos = npos) const;
size_type find_last_of(char_type c, size_type pos = npos) const;
size_type find_last_of(const char_type* s, size_type pos, size_type count) const;
size_type find_last_of(const char_type* s, size_type pos = npos) const;
//------------------------------------------------------------------------
size_type find_first_not_of(basic_string_view v, size_type pos = 0) const;
size_type find_first_not_of(char_type c, size_type pos = 0) const;
size_type find_first_not_of(const char_type* s, size_type pos, size_type count) const;
size_type find_first_not_of(const char_type* s, size_type pos = 0) const;
//------------------------------------------------------------------------
size_type find_last_not_of(basic_string_view v, size_type pos = npos) const;
size_type find_last_not_of(char_type c, size_type pos = npos) const;
size_type find_last_not_of(const char_type* s, size_type pos, size_type count) const;
size_type find_last_not_of(const char_type* s, size_type pos = npos) const;
//------------------------------------------------------------------------
// Iterators
//------------------------------------------------------------------------
public:
/// \brief Retrieves the begin iterator for this basic_string_view
///
/// \return the begin iterator
const_iterator begin() const;
/// \brief Retrieves the end iterator for this basic_string_view
///
/// \return the end iterator
const_iterator end() const;
/// \copydoc basic_string_view::begin()
const_iterator cbegin() const;
/// \copydoc basic_string_view::end()
const_iterator cend() const;
//------------------------------------------------------------------------
// Private Member
//------------------------------------------------------------------------
private:
const char_type* m_str; ///< The internal string type
size_type m_size; ///< The size of this string
};
//--------------------------------------------------------------------------
// Type Aliases
//--------------------------------------------------------------------------
using string_view = basic_string_view<char>;
# if defined(__cpp_lib_char8_t)
using u8string_view = basic_string_view<char8_t>;
# endif
using wstring_view = basic_string_view<wchar_t>;
using u16string_view = basic_string_view<char16_t>;
using u32string_view = basic_string_view<char32_t>;
//--------------------------------------------------------------------------
// Inline Definitions
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
// Constructor
//--------------------------------------------------------------------------
template <typename _CharT, typename _Traits>
inline basic_string_view<_CharT, _Traits>::basic_string_view() : m_str(nullptr), m_size(0)
{}
template <typename _CharT, typename _Traits>
template <typename Allocator>
inline basic_string_view<_CharT, _Traits>::basic_string_view(const std::basic_string<_CharT, _Traits, Allocator>& str) : m_str(str.c_str()), m_size(str.size())
{}
template <typename _CharT, typename _Traits>
inline basic_string_view<_CharT, _Traits>::basic_string_view(const char_type* str) : m_str(str), m_size(traits_type::length(str))
{}
template <typename _CharT, typename _Traits>
inline basic_string_view<_CharT, _Traits>::basic_string_view(const char_type* str, size_type count) : m_str(str), m_size(count)
{}
//--------------------------------------------------------------------------
// Capacity
//--------------------------------------------------------------------------
template <typename _CharT, typename _Traits>
inline typename basic_string_view<_CharT, _Traits>::size_type basic_string_view<_CharT, _Traits>::size() const
{
return m_size;
}
template <typename _CharT, typename _Traits>
inline typename basic_string_view<_CharT, _Traits>::size_type basic_string_view<_CharT, _Traits>::length() const
{
return size();
}
template <typename _CharT, typename _Traits>
inline typename basic_string_view<_CharT, _Traits>::size_type basic_string_view<_CharT, _Traits>::max_size() const
{
return npos - 1;
}
template <typename _CharT, typename _Traits>
inline bool basic_string_view<_CharT, _Traits>::empty() const
{
return m_size == 0;
}
//--------------------------------------------------------------------------
// Element Access
//--------------------------------------------------------------------------
template <typename _CharT, typename _Traits>
inline const typename basic_string_view<_CharT, _Traits>::char_type* basic_string_view<_CharT, _Traits>::c_str() const
{
return m_str;
}
template <typename _CharT, typename _Traits>
inline const typename basic_string_view<_CharT, _Traits>::char_type* basic_string_view<_CharT, _Traits>::data() const
{
return m_str;
}
template <typename _CharT, typename _Traits>
inline typename basic_string_view<_CharT, _Traits>::const_reference basic_string_view<_CharT, _Traits>::operator[](size_t pos) const
{
return m_str[pos];
}
template <typename _CharT, typename _Traits>
inline typename basic_string_view<_CharT, _Traits>::const_reference basic_string_view<_CharT, _Traits>::at(size_t pos) const
{
if (yasio__unlikely(pos >= m_size))
YASIO__THROW(std::out_of_range("Input out of range in basic_string_view::at"), 0);
return m_str[pos];
}
template <typename _CharT, typename _Traits>
inline typename basic_string_view<_CharT, _Traits>::const_reference basic_string_view<_CharT, _Traits>::front() const
{
return *m_str;
}
template <typename _CharT, typename _Traits>
inline typename basic_string_view<_CharT, _Traits>::const_reference basic_string_view<_CharT, _Traits>::back() const
{
return m_str[m_size - 1];
}
//--------------------------------------------------------------------------
// Modifiers
//--------------------------------------------------------------------------
template <typename _CharT, typename _Traits>
inline void basic_string_view<_CharT, _Traits>::remove_prefix(size_type n)
{
m_str += n, m_size -= n;
}
template <typename _CharT, typename _Traits>
inline void basic_string_view<_CharT, _Traits>::remove_suffix(size_type n)
{
m_size -= n;
}
template <typename _CharT, typename _Traits>
inline void basic_string_view<_CharT, _Traits>::swap(basic_string_view& v)
{
using std::swap;
swap(m_size, v.m_size);
swap(m_str, v.m_str);
}
//--------------------------------------------------------------------------
// Conversions
//--------------------------------------------------------------------------
template <typename _CharT, typename _Traits>
template <class Allocator>
inline std::basic_string<_CharT, _Traits, Allocator> basic_string_view<_CharT, _Traits>::to_string(const Allocator& a) const
{
return std::basic_string<_CharT, _Traits, Allocator>(m_str, m_size, a);
}
template <typename _CharT, typename _Traits>
template <class Allocator>
inline basic_string_view<_CharT, _Traits>::operator std::basic_string<_CharT, _Traits, Allocator>() const
{
return std::basic_string<_CharT, _Traits, Allocator>(m_str, m_size);
}
//--------------------------------------------------------------------------
// String Operations
//--------------------------------------------------------------------------
template <typename _CharT, typename _Traits>
inline typename basic_string_view<_CharT, _Traits>::size_type basic_string_view<_CharT, _Traits>::copy(char_type* dest, size_type count, size_type pos) const
{
if (yasio__unlikely(pos >= m_size))
YASIO__THROW(std::out_of_range("Index out of range in basic_string_view::copy"), 0);
const size_type rcount = (std::min)(m_size - pos, count + 1);
std::copy(m_str + pos, m_str + pos + rcount, dest);
return rcount;
}
template <typename _CharT, typename _Traits>
inline basic_string_view<_CharT, _Traits> basic_string_view<_CharT, _Traits>::substr(size_t pos, size_t len) const
{
const size_type max_length = pos > m_size ? 0 : m_size - pos;
if (yasio__unlikely(pos >= m_size))
YASIO__THROW(std::out_of_range("Index out of range in basic_string_view::substr"), (basic_string_view<_CharT, _Traits>{}));
return basic_string_view<_CharT, _Traits>(m_str + pos, len > max_length ? max_length : len);
}
//--------------------------------------------------------------------------
template <typename _CharT, typename _Traits>
inline int basic_string_view<_CharT, _Traits>::compare(basic_string_view v) const
{
const size_type rlen = (std::min)(m_size, v.m_size);
const int compare = _Traits::compare(m_str, v.m_str, rlen);
return (compare ? compare : (m_size < v.m_size ? -1 : (m_size > v.m_size ? 1 : 0)));
}
template <typename _CharT, typename _Traits>
inline int basic_string_view<_CharT, _Traits>::compare(size_type pos, size_type count, basic_string_view v) const
{
return substr(pos, count).compare(v);
}
template <typename _CharT, typename _Traits>
inline int basic_string_view<_CharT, _Traits>::compare(size_type pos1, size_type count1, basic_string_view v, size_type pos2, size_type count2) const
{
return substr(pos1, count1).compare(v.substr(pos2, count2));
}
template <typename _CharT, typename _Traits>
inline int basic_string_view<_CharT, _Traits>::compare(const char_type* s) const
{
return compare(basic_string_view<_CharT, _Traits>(s));
}
template <typename _CharT, typename _Traits>
inline int basic_string_view<_CharT, _Traits>::compare(size_type pos, size_type count, const char_type* s) const
{
return substr(pos, count).compare(basic_string_view<_CharT, _Traits>(s));
}
template <typename _CharT, typename _Traits>
inline int basic_string_view<_CharT, _Traits>::compare(size_type pos, size_type count1, const char_type* s, size_type count2) const
{
return substr(pos, count1).compare(basic_string_view<_CharT, _Traits>(s, count2));
}
//--------------------------------------------------------------------------
template <typename _CharT, typename _Traits>
inline typename basic_string_view<_CharT, _Traits>::size_type basic_string_view<_CharT, _Traits>::find(basic_string_view v, size_type pos) const
{
return __xxtraits_find<_Traits>(m_str, m_size, pos, v.m_str, v.m_size);
}
template <typename _CharT, typename _Traits>
inline typename basic_string_view<_CharT, _Traits>::size_type basic_string_view<_CharT, _Traits>::find(char_type c, size_type pos) const
{
return find(basic_string_view<_CharT, _Traits>(&c, 1), pos);
}
template <typename _CharT, typename _Traits>
inline typename basic_string_view<_CharT, _Traits>::size_type basic_string_view<_CharT, _Traits>::find(const char_type* s, size_type pos, size_type count) const
{
return find(basic_string_view<_CharT, _Traits>(s, count), pos);
}
template <typename _CharT, typename _Traits>
inline typename basic_string_view<_CharT, _Traits>::size_type basic_string_view<_CharT, _Traits>::find(const char_type* s, size_type pos) const
{
return find(basic_string_view<_CharT, _Traits>(s), pos);
}
//--------------------------------------------------------------------------
template <typename _CharT, typename _Traits>
inline typename basic_string_view<_CharT, _Traits>::size_type basic_string_view<_CharT, _Traits>::rfind(basic_string_view v, size_type pos) const
{
return __xxtraits_rfind<_Traits>(m_str, m_size, pos, v.m_str, v.m_size);
}
template <typename _CharT, typename _Traits>
inline typename basic_string_view<_CharT, _Traits>::size_type basic_string_view<_CharT, _Traits>::rfind(char_type c, size_type pos) const
{
return rfind(basic_string_view<_CharT, _Traits>(&c, 1), pos);
}
template <typename _CharT, typename _Traits>
inline typename basic_string_view<_CharT, _Traits>::size_type basic_string_view<_CharT, _Traits>::rfind(const char_type* s, size_type pos,
size_type count) const
{
return rfind(basic_string_view<_CharT, _Traits>(s, count), pos);
}
template <typename _CharT, typename _Traits>
inline typename basic_string_view<_CharT, _Traits>::size_type basic_string_view<_CharT, _Traits>::rfind(const char_type* s, size_type pos) const
{
return rfind(basic_string_view<_CharT, _Traits>(s), pos);
}
//--------------------------------------------------------------------------
template <typename _CharT, typename _Traits>
inline typename basic_string_view<_CharT, _Traits>::size_type basic_string_view<_CharT, _Traits>::find_first_of(basic_string_view v, size_type pos) const
{
return __xxtraits_find_first_of<_Traits>(m_str, m_size, pos, v.m_str, v.m_size);
}
template <typename _CharT, typename _Traits>
inline typename basic_string_view<_CharT, _Traits>::size_type basic_string_view<_CharT, _Traits>::find_first_of(char_type c, size_type pos) const
{
return __xxtraits_find_ch<_Traits>(m_str, m_size, pos, c);
}
template <typename _CharT, typename _Traits>
inline typename basic_string_view<_CharT, _Traits>::size_type basic_string_view<_CharT, _Traits>::find_first_of(const char_type* s, size_type pos,
size_type count) const
{
return find_first_of(basic_string_view<_CharT, _Traits>(s, count), pos);
}
template <typename _CharT, typename _Traits>
inline typename basic_string_view<_CharT, _Traits>::size_type basic_string_view<_CharT, _Traits>::find_first_of(const char_type* s, size_type pos) const
{
return find_first_of(basic_string_view<_CharT, _Traits>(s), pos);
}
//--------------------------------------------------------------------------
template <typename _CharT, typename _Traits>
inline typename basic_string_view<_CharT, _Traits>::size_type basic_string_view<_CharT, _Traits>::find_last_of(basic_string_view v, size_type pos) const
{
return __xxtraits_find_last_of<_Traits>(m_str, m_size, pos, v.m_str, v.m_size);
}
template <typename _CharT, typename _Traits>
inline typename basic_string_view<_CharT, _Traits>::size_type basic_string_view<_CharT, _Traits>::find_last_of(char_type c, size_type pos) const
{
return __xxtraits_rfind_ch<_Traits>(m_str, m_size, pos, c);
}
template <typename _CharT, typename _Traits>
inline typename basic_string_view<_CharT, _Traits>::size_type basic_string_view<_CharT, _Traits>::find_last_of(const char_type* s, size_type pos,
size_type count) const
{
return find_last_of(basic_string_view<_CharT, _Traits>(s, count), pos);
}
template <typename _CharT, typename _Traits>
inline typename basic_string_view<_CharT, _Traits>::size_type basic_string_view<_CharT, _Traits>::find_last_of(const char_type* s, size_type pos) const
{
return find_last_of(basic_string_view<_CharT, _Traits>(s), pos);
}
//--------------------------------------------------------------------------
template <typename _CharT, typename _Traits>
inline typename basic_string_view<_CharT, _Traits>::size_type basic_string_view<_CharT, _Traits>::find_first_not_of(basic_string_view v, size_type pos) const
{
return __xxtraits_find_first_not_of<_Traits>(m_str, m_size, pos, v.m_str, v.m_size, pos);
}
template <typename _CharT, typename _Traits>
inline typename basic_string_view<_CharT, _Traits>::size_type basic_string_view<_CharT, _Traits>::find_first_not_of(char_type c, size_type pos) const
{
return __xxtraits_find_not_ch<_Traits>(m_str, m_size, pos, c);
}
template <typename _CharT, typename _Traits>
inline typename basic_string_view<_CharT, _Traits>::size_type basic_string_view<_CharT, _Traits>::find_first_not_of(const char_type* s, size_type pos,
size_type count) const
{
return find_first_not_of(basic_string_view<_CharT, _Traits>(s, count), pos);
}
template <typename _CharT, typename _Traits>
inline typename basic_string_view<_CharT, _Traits>::size_type basic_string_view<_CharT, _Traits>::find_first_not_of(const char_type* s, size_type pos) const
{
return find_first_not_of(basic_string_view<_CharT, _Traits>(s), pos);
}
//--------------------------------------------------------------------------
template <typename _CharT, typename _Traits>
inline typename basic_string_view<_CharT, _Traits>::size_type basic_string_view<_CharT, _Traits>::find_last_not_of(basic_string_view v, size_type pos) const
{
return __xxtraits_find_last_not_of<_Traits>(m_str, m_size, pos, v.m_str, v.m_size);
}
template <typename _CharT, typename _Traits>
inline typename basic_string_view<_CharT, _Traits>::size_type basic_string_view<_CharT, _Traits>::find_last_not_of(char_type c, size_type pos) const
{
return __xxtraits_rfind_not_ch<_Traits>(m_str, m_size, pos, c);
}
template <typename _CharT, typename _Traits>
inline typename basic_string_view<_CharT, _Traits>::size_type basic_string_view<_CharT, _Traits>::find_last_not_of(const char_type* s, size_type pos,
size_type count) const
{
return find_last_not_of(basic_string_view<_CharT, _Traits>(s, count), pos);
}
template <typename _CharT, typename _Traits>
inline typename basic_string_view<_CharT, _Traits>::size_type basic_string_view<_CharT, _Traits>::find_last_not_of(const char_type* s, size_type pos) const
{
return find_last_not_of(basic_string_view<_CharT, _Traits>(s), pos);
}
//--------------------------------------------------------------------------
// Iterator
//--------------------------------------------------------------------------
template <typename _CharT, typename _Traits>
inline typename basic_string_view<_CharT, _Traits>::const_iterator basic_string_view<_CharT, _Traits>::begin() const
{
return m_str;
}
template <typename _CharT, typename _Traits>
inline typename basic_string_view<_CharT, _Traits>::const_iterator basic_string_view<_CharT, _Traits>::end() const
{
return m_str + m_size;
}
template <typename _CharT, typename _Traits>
inline typename basic_string_view<_CharT, _Traits>::const_iterator basic_string_view<_CharT, _Traits>::cbegin() const
{
return m_str;
}
template <typename _CharT, typename _Traits>
inline typename basic_string_view<_CharT, _Traits>::const_iterator basic_string_view<_CharT, _Traits>::cend() const
{
return m_str + m_size;
}
//--------------------------------------------------------------------------
// Public Functions
//--------------------------------------------------------------------------
template <typename _CharT, typename _Traits>
std::basic_ostream<_CharT, _Traits>& operator<<(std::basic_ostream<_CharT, _Traits>& o, const basic_string_view<_CharT, _Traits>& str)
{
o.write(str.data(), str.size());
return o;
}
template <typename _CharT, typename _Traits>
inline void swap(basic_string_view<_CharT, _Traits>& lhs, basic_string_view<_CharT, _Traits>& rhs)
{
lhs.swap(rhs);
}
//--------------------------------------------------------------------------
// Comparison Functions
//--------------------------------------------------------------------------
template <typename _CharT, typename _Traits>
inline bool operator==(const basic_string_view<_CharT, _Traits>& lhs, const basic_string_view<_CharT, _Traits>& rhs)
{
return lhs.compare(rhs) == 0;
}
template <typename _CharT, typename _Traits>
inline bool operator==(basic_string_view<_CharT, _Traits> lhs, const _CharT* rhs)
{
return lhs == basic_string_view<_CharT, _Traits>(rhs);
}
template <typename _CharT, typename _Traits>
inline bool operator==(const _CharT* lhs, const basic_string_view<_CharT, _Traits>& rhs)
{
return basic_string_view<_CharT, _Traits>(lhs) == rhs;
}
template <typename _CharT, typename _Traits, typename Allocator>
inline bool operator==(const std::basic_string<_CharT, _Traits, Allocator>& lhs, const basic_string_view<_CharT, _Traits>& rhs)
{
return basic_string_view<_CharT, _Traits>(lhs) == rhs;
}
template <typename _CharT, typename _Traits, typename Allocator>
inline bool operator==(const basic_string_view<_CharT, _Traits>& lhs, const std::basic_string<_CharT, _Traits, Allocator>& rhs)
{
return lhs == basic_string_view<_CharT, _Traits>(rhs);
}
//--------------------------------------------------------------------------
template <typename _CharT, typename _Traits>
inline bool operator!=(const basic_string_view<_CharT, _Traits>& lhs, const basic_string_view<_CharT, _Traits>& rhs)
{
return lhs.compare(rhs) != 0;
}
template <typename _CharT, typename _Traits>
inline bool operator!=(const basic_string_view<_CharT, _Traits>& lhs, const _CharT* rhs)
{
return lhs != basic_string_view<_CharT, _Traits>(rhs);
}
template <typename _CharT, typename _Traits>
inline bool operator!=(const _CharT* lhs, const basic_string_view<_CharT, _Traits>& rhs)
{
return basic_string_view<_CharT, _Traits>(lhs) != rhs;
}
template <typename _CharT, typename _Traits, typename Allocator>
inline bool operator!=(const std::basic_string<_CharT, _Traits, Allocator>& lhs, const basic_string_view<_CharT, _Traits>& rhs)
{
return basic_string_view<_CharT, _Traits>(lhs) != rhs;
}
template <typename _CharT, typename _Traits, typename Allocator>
inline bool operator!=(const basic_string_view<_CharT, _Traits>& lhs, const std::basic_string<_CharT, _Traits, Allocator>& rhs)
{
return lhs != basic_string_view<_CharT, _Traits>(rhs);
}
//--------------------------------------------------------------------------
template <typename _CharT, typename _Traits>
inline bool operator<(const basic_string_view<_CharT, _Traits>& lhs, const basic_string_view<_CharT, _Traits>& rhs)
{
return lhs.compare(rhs) < 0;
}
template <typename _CharT, typename _Traits>
inline bool operator<(const basic_string_view<_CharT, _Traits>& lhs, const _CharT* rhs)
{
return lhs < basic_string_view<_CharT, _Traits>(rhs);
}
template <typename _CharT, typename _Traits>
inline bool operator<(const _CharT* lhs, const basic_string_view<_CharT, _Traits>& rhs)
{
return basic_string_view<_CharT, _Traits>(lhs) < rhs;
}
template <typename _CharT, typename _Traits, typename Allocator>
inline bool operator<(const std::basic_string<_CharT, _Traits, Allocator>& lhs, const basic_string_view<_CharT, _Traits>& rhs)
{
return basic_string_view<_CharT, _Traits>(lhs) < rhs;
}
template <typename _CharT, typename _Traits, typename Allocator>
inline bool operator<(const basic_string_view<_CharT, _Traits>& lhs, const std::basic_string<_CharT, _Traits, Allocator>& rhs)
{
return lhs < basic_string_view<_CharT, _Traits>(rhs);
}
//--------------------------------------------------------------------------
template <typename _CharT, typename _Traits>
inline bool operator>(const basic_string_view<_CharT, _Traits>& lhs, const basic_string_view<_CharT, _Traits>& rhs)
{
return lhs.compare(rhs) > 0;
}
template <typename _CharT, typename _Traits>
inline bool operator>(const basic_string_view<_CharT, _Traits>& lhs, const _CharT* rhs)
{
return lhs > basic_string_view<_CharT, _Traits>(rhs);
}
template <typename _CharT, typename _Traits>
inline bool operator>(const _CharT* lhs, const basic_string_view<_CharT, _Traits>& rhs)
{
return basic_string_view<_CharT, _Traits>(lhs) > rhs;
}
template <typename _CharT, typename _Traits, typename Allocator>
inline bool operator>(const std::basic_string<_CharT, _Traits, Allocator>& lhs, const basic_string_view<_CharT, _Traits>& rhs)
{
return basic_string_view<_CharT, _Traits>(lhs) > rhs;
}
template <typename _CharT, typename _Traits, typename Allocator>
inline bool operator>(const basic_string_view<_CharT, _Traits>& lhs, const std::basic_string<_CharT, _Traits, Allocator>& rhs)
{
return lhs > basic_string_view<_CharT, _Traits>(rhs);
}
//--------------------------------------------------------------------------
template <typename _CharT, typename _Traits>
inline bool operator<=(const basic_string_view<_CharT, _Traits>& lhs, const basic_string_view<_CharT, _Traits>& rhs)
{
return lhs.compare(rhs) <= 0;
}
template <typename _CharT, typename _Traits>
inline bool operator<=(const basic_string_view<_CharT, _Traits>& lhs, const _CharT* rhs)
{
return lhs <= basic_string_view<_CharT, _Traits>(rhs);
}
template <typename _CharT, typename _Traits>
inline bool operator<=(const _CharT* lhs, const basic_string_view<_CharT, _Traits>& rhs)
{
return basic_string_view<_CharT, _Traits>(lhs) <= rhs;
}
template <typename _CharT, typename _Traits, typename Allocator>
inline bool operator<=(const std::basic_string<_CharT, _Traits, Allocator>& lhs, const basic_string_view<_CharT, _Traits>& rhs)
{
return basic_string_view<_CharT, _Traits>(lhs) <= rhs;
}
template <typename _CharT, typename _Traits, typename Allocator>
inline bool operator<=(const basic_string_view<_CharT, _Traits>& lhs, const std::basic_string<_CharT, _Traits, Allocator>& rhs)
{
return lhs <= basic_string_view<_CharT, _Traits>(rhs);
}
//--------------------------------------------------------------------------
template <typename _CharT, typename _Traits>
inline bool operator>=(const basic_string_view<_CharT, _Traits>& lhs, const basic_string_view<_CharT, _Traits>& rhs)