Repository navigation
Expand file tree
/
Copy pathstring_view.hpp
More file actions
2232 lines (1923 loc) · 66.2 KB
/
Copy pathstring_view.hpp
File metadata and controls
2232 lines (1923 loc) · 66.2 KB
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
/* /////////////////////////////////////////////////////////////////////////
* File: stlsoft/string/string_view.hpp
*
* Purpose: basic_string_view class.
*
* Created: 16th October 2004
* Updated: 4th May 2025
*
* Thanks: Bjorn Karlsson and Scott Patterson for discussions on various
* naming and design issues. Thanks also to Pablo Aguilar for
* his eagle eyed reviews of beta code. :-)
*
* Home: http://stlsoft.org/
*
* Copyright (c) 2019-2025, Matthew Wilson and Synesis Information Systems
* Copyright (c) 2004-2019, Matthew Wilson and Synesis Software
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name(s) of Matthew Wilson and Synesis Information Systems
* nor the names of any contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* ////////////////////////////////////////////////////////////////////// */
/** \file stlsoft/string/string_view.hpp
*
* \brief [C++] Definition of the stlsoft::basic_string_view class
* template
* (\ref group__library__String "String" Library).
*/
#ifndef STLSOFT_INCL_STLSOFT_STRING_HPP_STRING_VIEW
#define STLSOFT_INCL_STLSOFT_STRING_HPP_STRING_VIEW
#ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
# define STLSOFT_VER_STLSOFT_STRING_HPP_STRING_VIEW_MAJOR 4
# define STLSOFT_VER_STLSOFT_STRING_HPP_STRING_VIEW_MINOR 0
# define STLSOFT_VER_STLSOFT_STRING_HPP_STRING_VIEW_REVISION 3
# define STLSOFT_VER_STLSOFT_STRING_HPP_STRING_VIEW_EDIT 124
#endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
/* /////////////////////////////////////////////////////////////////////////
* compatibility
*/
#if 0
#elif defined(STLSOFT_OBSOLETE)
# ifndef STLSOFT_STRING_VIEW_PROVIDE_c_str
# define STLSOFT_STRING_VIEW_PROVIDE_c_str
# endif
#endif
#ifdef STLSOFT_STRING_VIEW_NO_PROVIDE_c_str
# ifdef STLSOFT_STRING_VIEW_PROVIDE_c_str
# undef STLSOFT_STRING_VIEW_PROVIDE_c_str
# endif
#endif
/* /////////////////////////////////////////////////////////////////////////
* includes
*/
#ifndef STLSOFT_INCL_STLSOFT_H_STLSOFT
# include <stlsoft/stlsoft.h>
#endif /* !STLSOFT_INCL_STLSOFT_H_STLSOFT */
#ifdef STLSOFT_TRACE_INCLUDE
# pragma message(__FILE__)
#endif /* STLSOFT_TRACE_INCLUDE */
#if defined(STLSOFT_COMPILER_IS_MWERKS) && \
((__MWERKS__ & 0xff00) < 0x3000)
# error stlsoft/string/string_view.hpp not compatible with Metrowerks 7.x (v2.4)
#endif /* compiler */
#ifndef STLSOFT_INCL_STLSOFT_COLLECTIONS_UTIL_HPP_COLLECTIONS
# include <stlsoft/collections/util/collections.hpp>
#endif /* !STLSOFT_INCL_STLSOFT_COLLECTIONS_UTIL_HPP_COLLECTIONS */
#ifndef STLSOFT_INCL_STLSOFT_MEMORY_UTIL_HPP_ALLOCATOR_SELECTOR
# include <stlsoft/memory/util/allocator_selector.hpp>
#endif /* !STLSOFT_INCL_STLSOFT_MEMORY_UTIL_HPP_ALLOCATOR_SELECTOR */
#ifndef STLSOFT_INCL_STLSOFT_STRING_HPP_CHAR_TRAITS
# include <stlsoft/string/char_traits.hpp>
#endif /* !STLSOFT_INCL_STLSOFT_STRING_HPP_CHAR_TRAITS */
#ifndef STLSOFT_INCL_STLSOFT_STRING_HPP_STRING_TRAITS_FWD
# include <stlsoft/string/string_traits_fwd.hpp>
#endif /* !STLSOFT_INCL_STLSOFT_STRING_HPP_STRING_TRAITS_FWD */
#ifndef STLSOFT_INCL_STLSOFT_UTIL_STD_HPP_ITERATOR_HELPER
# include <stlsoft/util/std/iterator_helper.hpp>
#endif /* !STLSOFT_INCL_STLSOFT_UTIL_STD_HPP_ITERATOR_HELPER */
#ifndef STLSOFT_INCL_STLSOFT_UTIL_HPP_STD_SWAP
# include <stlsoft/util/std_swap.hpp>
#endif /* !STLSOFT_INCL_STLSOFT_UTIL_HPP_STD_SWAP */
#ifndef STLSOFT_INCL_STLSOFT_UTIL_STREAMS_HPP_STRING_INSERTION
# include <stlsoft/util/streams/string_insertion.hpp>
#endif /* !STLSOFT_INCL_STLSOFT_UTIL_STREAMS_HPP_STRING_INSERTION */
#ifdef STLSOFT_CF_EXCEPTION_SUPPORT
# ifndef STLSOFT_INCL_STDEXCEPT
# define STLSOFT_INCL_STDEXCEPT
# include <stdexcept> // for std::out_of_range
# endif /* !STLSOFT_INCL_STDEXCEPT */
#endif /* !STLSOFT_CF_EXCEPTION_SUPPORT */
/* /////////////////////////////////////////////////////////////////////////
* namespace
*/
#ifndef STLSOFT_NO_NAMESPACE
namespace stlsoft
{
#endif /* STLSOFT_NO_NAMESPACE */
/* /////////////////////////////////////////////////////////////////////////
* classes
*/
// class basic_string_view
/** A string class that holds no internal storage, and merely represents a
* window into other string storage
*
* \ingroup group__library__String
*
* \param C The character type
* \param T The traits type. On translators that support default template
* arguments this is defaulted to char_traits<C>
* \param A The allocator type. On translators that support default template
* arguments this is defaulted to allocator_selector<C>::allocator_type.
* This is only used by the proxy generated by c_str()
* \ingroup concepts_view
*/
template<
ss_typename_param_k C
#ifdef STLSOFT_CF_TEMPLATE_CLASS_DEFAULT_CLASS_ARGUMENT_SUPPORT
, ss_typename_param_k T = char_traits<C>
, ss_typename_param_k A = ss_typename_type_def_k allocator_selector<C>::allocator_type
#else /* ? STLSOFT_CF_TEMPLATE_CLASS_DEFAULT_CLASS_ARGUMENT_SUPPORT */
, ss_typename_param_k T /* = char_traits<C> */
, ss_typename_param_k A /* = allocator_selector<C>::allocator_type */
#endif /* STLSOFT_CF_TEMPLATE_CLASS_DEFAULT_CLASS_ARGUMENT_SUPPORT */
>
class basic_string_view
#if defined(STLSOFT_COMPILER_IS_DMC)
: protected A
#else /* ? compiler */
: private A
#endif /* compiler */
, public stl_collection_tag
{
public:
/// The value type
typedef C value_type;
/// The traits type
typedef T traits_type;
/// The allocator type
typedef A allocator_type;
/// The current specialisation of the type
typedef basic_string_view<
value_type
, traits_type
, allocator_type
> class_type;
/// The character type
typedef value_type char_type;
#if 0
/// The pointer type
///
/// \note This type is not used by any functions, but is here to
/// facilitate type detection
typedef value_type const* pointer;
#endif /* 0 */
/// The non-mutable (const) pointer type
typedef value_type const* const_pointer;
#if 0
/// The reference type
typedef value_type& reference;
#endif /* 0 */
/// The non-mutable (const) reference type
typedef value_type const& const_reference;
/// The size type
typedef ss_size_t size_type;
/// The difference type
typedef ss_ptrdiff_t difference_type;
#if 0
/// The iterator type
typedef
#if !defined(STLSOFT_COMPILER_IS_BORLAND)
ss_typename_type_k
#endif /* compiler */
pointer_iterator<
value_type
, pointer
, reference
>::type iterator;
#endif /* 0 */
/// The non-mutating (const) iterator type
typedef
#if !defined(STLSOFT_COMPILER_IS_BORLAND)
ss_typename_type_k
#endif /* compiler */
pointer_iterator<
value_type const
, const_pointer
, const_reference
>::type const_iterator;
#if defined(STLSOFT_LF_BIDIRECTIONAL_ITERATOR_SUPPORT)
#if 0
/// The reverse iterator type
typedef reverse_iterator_base<
iterator
, value_type
, reference
, pointer
, difference_type
> reverse_iterator;
#endif /* 0 */
/// The non-mutating (const) reverse iterator type
typedef const_reverse_iterator_base<
const_iterator
, value_type const
, const_reference
, const_pointer
, difference_type
> const_reverse_iterator;
#endif /* STLSOFT_LF_BIDIRECTIONAL_ITERATOR_SUPPORT */
/// \name Construction
/// @{
public:
/// Default constructor
basic_string_view();
/// Copy constructor
basic_string_view(class_type const& rhs);
/// Construct from the given string at the specified position
basic_string_view(class_type const& s, size_type pos);
/// Construct with \c cch characters from the given string at the
/// specified position
basic_string_view(class_type const& s, size_type pos, size_type cch);
/// Construct from a null-terminated character string
basic_string_view(char_type const* s); // No, not explicit! Sigh
/// Construct with \c cch characters from the given character string
basic_string_view(char_type const* s, size_type cch);
/// Construct from the range [first:last)
basic_string_view(char_type const* first, char_type const* last);
/// Destructor
~basic_string_view() STLSOFT_NOEXCEPT;
/// Copy assignment operator
class_type& operator =(class_type const& rhs);
/// @}
/// \name Operations
/// @{
public:
/// Swaps the contents between \c this and \c other
void swap(class_type& other) STLSOFT_NOEXCEPT;
/// Empties the string
void clear() STLSOFT_NOEXCEPT;
/// Clear c_str() representation
///
/// Causes the c_str() representation, if currently allocated (see
/// c_str() for details), to be destroyed, in order that the next call
/// to c_str() will result in a fresh nul-terminated copy of the
/// 'current' contents of the view.
void refresh() STLSOFT_NOEXCEPT;
/// @}
/// \name Attributes
/// @{
public:
/// The number of elements in the string
size_type size() const STLSOFT_NOEXCEPT;
/// The maximum number of elements that can be stored in the string
static size_type max_size() STLSOFT_NOEXCEPT;
/// The number of elements in the string
size_type length() const STLSOFT_NOEXCEPT;
/// The storage currently allocated by the string
size_type capacity() const STLSOFT_NOEXCEPT;
/// Indicates whether the string is empty
ss_bool_t empty() const STLSOFT_NOEXCEPT;
/// Returns an instance of the allocator type
allocator_type get_allocator() const;
/// @}
/// \name Comparison
/// @{
public:
/// Evaluates whether two strings are equal
ss_bool_t equal(class_type const& rhs) const STLSOFT_NOEXCEPT;
/// Evaluates whether two strings are equal
ss_bool_t equal(value_type const* rhs, size_type cchRhs) const STLSOFT_NOEXCEPT;
/// Compares \c this with the given string
ss_sint_t compare(size_type pos, size_type cch, value_type const* s, size_type cchRhs) const STLSOFT_NOEXCEPT;
/// Compares \c this with the given string
ss_sint_t compare(size_type pos, size_type cch, value_type const* s) const STLSOFT_NOEXCEPT;
/// Compares \c this with the given string
ss_sint_t compare(value_type const* s) const STLSOFT_NOEXCEPT;
/// Compares \c this with the given string
ss_sint_t compare(size_type pos, size_type cch, class_type const& rhs, size_type posRhs, size_type cchRhs) const STLSOFT_NOEXCEPT;
/// Compares \c this with the given string
ss_sint_t compare(size_type pos, size_type cch, class_type const& rhs) const STLSOFT_NOEXCEPT;
/// Compares \c this with the given string
ss_sint_t compare(class_type const& rhs) const STLSOFT_NOEXCEPT;
/// @}
/// \name Accessors
/// @{
public:
#if 0
/// Returns mutable reference at the given index
reference operator [](size_type index);
#endif /* 0 */
/// Returns non-mutable (const) reference at the given index
///
/// \note Follows the convention of std::basic_string in returning a
/// reference to char_type() if index == size(). This reference will
/// <b>not</b> be part of the block constituting the string's viewed
/// area.
const_reference operator [](size_type index) const;
#ifdef STLSOFT_CF_EXCEPTION_SUPPORT
/// Returns non-mutable (const) reference at the given index
///
/// \note Throws std::out_of_range if index >= size()
const_reference at(size_type index) const;
/// Returns a string of maximum length cch, from the position pos
class_type substr(size_type pos, size_type cch) const;
class_type substr(size_type pos) const;
class_type substr() const;
#endif /* !STLSOFT_CF_EXCEPTION_SUPPORT */
/// Returns null-terminated non-mutable (const) pointer to string data
///
/// \note This returns a nul-terminated copy of the string. If the
/// view's underlying string changes after this point, this will not
/// be reflected in the value returned by c_str(), until such time as
/// refresh() is called.
///
/// \note If the view's specialisation is with a no-throw allocator,
/// behaviour is undefined in con
#ifdef STLSOFT_STRING_VIEW_PROVIDE_c_str
value_type const* c_str() const;
#endif /* STLSOFT_STRING_VIEW_PROVIDE_c_str */
#if 0
/// Facility for calling refresh() followed by c_str()
///
/// \param bRefresh call refresh() before c_str()
///
/// \note If bRefresh is \c false has identical semantics to c_str()
value_type const* c_str(ss_bool_t bRefresh) const;
#endif /* 0 */
/// Returns non-mutable (const) pointer to string data
value_type const* data() const STLSOFT_NOEXCEPT;
/// Returns value of base pointer
value_type const* base() const STLSOFT_NOEXCEPT;
#if 0
/// Returns the first character in the string
///
/// \note It is up to the user to ensure that the string is not empty
reference front();
/// Returns the last character in the string
///
/// \note It is up to the user to ensure that the string is not empty
reference back();
#endif /* 0 */
/// Returns the first character in the string
///
/// \note It is up to the user to ensure that the string is not empty
const_reference front() const;
/// Returns the last character in the string
///
/// \note It is up to the user to ensure that the string is not empty
const_reference back() const;
/// Copies elements into the given destination
size_type copy(value_type *dest, size_type cch, size_type pos = 0) const;
/// @}
/// \name Iteration
/// @{
public:
/// Begins the iteration
///
/// \return A non-mutable (const) iterator representing the start of the
/// sequence
const_iterator begin() const;
/// Ends the iteration
///
/// \return A non-mutable (const) iterator representing the end of the
/// sequence
const_iterator end() const;
#if 0
/// Begins the iteration
///
/// \return An iterator representing the start of the sequence
iterator begin();
/// Ends the iteration
///
/// \return An iterator representing the end of the sequence
iterator end();
#endif /* 0 */
#if defined(STLSOFT_LF_BIDIRECTIONAL_ITERATOR_SUPPORT)
/// Begins the reverse iteration
///
/// \return A non-mutable (const) iterator representing the start of the
/// reverse sequence
const_reverse_iterator rbegin() const;
/// Ends the reverse iteration
///
/// \return A non-mutable (const) iterator representing the end of the
/// reverse sequence
const_reverse_iterator rend() const;
#if 0
/// Begins the reverse iteration
///
/// \return An iterator representing the start of the reverse sequence
reverse_iterator rbegin();
/// Ends the reverse iteration
///
/// \return An iterator representing the end of the reverse sequence
reverse_iterator rend();
#endif /* 0 */
#endif /* STLSOFT_LF_BIDIRECTIONAL_ITERATOR_SUPPORT */
/// @}
/// \name Invariant
/// @{
ss_bool_t is_valid() const;
/// \name Implementation
/// @{
private:
// Empty string
static
char_type const*
empty_string_() STLSOFT_NOEXCEPT;
// Comparison
static
ss_sint_t
compare_(
char_type const* lhs
, size_type lhs_len
, char_type const* rhs
, size_type rhs_len
) STLSOFT_NOEXCEPT;
// Closes the m_cstr member
#ifdef STLSOFT_STRING_VIEW_PROVIDE_c_str
void close_() STLSOFT_NOEXCEPT;
#endif /* STLSOFT_STRING_VIEW_PROVIDE_c_str */
// Closes the m_cstr member and sets to \c nullptr
#ifdef STLSOFT_STRING_VIEW_PROVIDE_c_str
void close_set_null_() STLSOFT_NOEXCEPT;
#endif /* STLSOFT_STRING_VIEW_PROVIDE_c_str */
const_iterator begin_() const STLSOFT_NOEXCEPT;
const_iterator end_() const STLSOFT_NOEXCEPT;
#if 0
iterator begin_() STLSOFT_NOEXCEPT;
iterator end_() STLSOFT_NOEXCEPT;
#endif /* 0 */
/// @}
/// \name Members
/// @{
private:
size_type m_length; // The number of elements in the view
char_type const* m_base; // Pointer to the first element in the view, or NULL for a null view
#ifdef STLSOFT_STRING_VIEW_PROVIDE_c_str
char_type* m_cstr; // Pointer to a nul-terminated copy of the view, at the time of the c_str() call. Will be \c nullptr before c_str() is called
#endif /* STLSOFT_STRING_VIEW_PROVIDE_c_str */
/// @}
};
/* /////////////////////////////////////////////////////////////////////////
* typedefs
*/
#ifdef STLSOFT_CF_TEMPLATE_CLASS_DEFAULT_CLASS_ARGUMENT_SUPPORT
typedef basic_string_view<ss_char_a_t> string_view;
typedef basic_string_view<ss_char_w_t> wstring_view;
#else /* ? STLSOFT_CF_TEMPLATE_CLASS_DEFAULT_CLASS_ARGUMENT_SUPPORT */
typedef basic_string_view<
ss_char_a_t
, stlsoft_char_traits<ss_char_a_t>
, allocator_selector<ss_char_a_t>::allocator_type
> string_view;
typedef basic_string_view<
ss_char_w_t
, stlsoft_char_traits<ss_char_w_t>
, allocator_selector<ss_char_w_t>::allocator_type
> wstring_view;
#endif /* STLSOFT_CF_TEMPLATE_CLASS_DEFAULT_CLASS_ARGUMENT_SUPPORT */
/* /////////////////////////////////////////////////////////////////////////
* traits
*/
/** Specialisation of stlsoft::string_traits<> for
* stlsoft::basic_string_view<>
*/
# ifdef STLSOFT_CF_TEMPLATE_PARTIAL_SPECIALISATION_SUPPORT
template<
ss_typename_param_k C
, ss_typename_param_k T
, ss_typename_param_k A
>
struct string_traits<basic_string_view<C, T, A> >
{
// NOTE: Originally, what is string_type_ was defined as value_type, but
// Borland objects to value_type::value_type.
typedef basic_string_view<C, T, A> string_type_;
typedef ss_typename_type_k string_type_::value_type char_type;
typedef ss_typename_type_k string_type_::size_type size_type;
typedef char_type const const_char_type;
typedef string_type_ string_type;
typedef string_type_ value_type;
// typedef ss_typename_type_k string_type::pointer pointer;
typedef ss_typename_type_k string_type::const_pointer const_pointer;
// typedef ss_typename_type_k string_type::iterator iterator;
typedef ss_typename_type_k string_type::const_iterator const_iterator;
#if defined(STLSOFT_LF_BIDIRECTIONAL_ITERATOR_SUPPORT)
// typedef ss_typename_type_k string_type::reverse_iterator reverse_iterator;
typedef ss_typename_type_k string_type::const_reverse_iterator const_reverse_iterator;
#endif /* STLSOFT_LF_BIDIRECTIONAL_ITERATOR_SUPPORT */
enum
{
is_pointer = false
, is_pointer_to_const = false
, char_type_size = sizeof(char_type)
};
static string_type empty_string()
{
return string_type();
}
static string_type construct(string_type const& src, size_type pos, size_type len)
{
return string_type(src, pos, len);
}
# ifdef STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT
template <ss_typename_param_k I>
static string_type& assign_inplace(string_type& str, I first, I last)
# else /* ? STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT */
static string_type& assign_inplace(string_type& str, const_iterator first, const_iterator last)
# endif /* STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT */
{
// string view cannot assign in-place
return (str = string_type(first, last), str);
}
};
# else /* ? STLSOFT_CF_TEMPLATE_PARTIAL_SPECIALISATION_SUPPORT */
STLSOFT_TEMPLATE_SPECIALISATION
struct string_traits<string_view>
{
typedef string_view value_type;
typedef value_type::value_type char_type;
typedef value_type::size_type size_type;
typedef char_type const const_char_type;
typedef value_type string_type;
// typedef string_type::pointer pointer;
typedef string_type::const_pointer const_pointer;
// typedef string_type::iterator iterator;
typedef string_type::const_iterator const_iterator;
#if defined(STLSOFT_LF_BIDIRECTIONAL_ITERATOR_SUPPORT)
// typedef string_type::reverse_iterator reverse_iterator;
typedef string_type::const_reverse_iterator const_reverse_iterator;
#endif /* STLSOFT_LF_BIDIRECTIONAL_ITERATOR_SUPPORT */
enum
{
is_pointer = false
, is_pointer_to_const = false
, char_type_size = sizeof(char_type)
};
static string_type empty_string()
{
return string_type();
}
static string_type construct(string_type const& src, size_type pos, size_type len)
{
return string_type(src, pos, len);
}
# ifdef STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT
template <ss_typename_param_k I>
static string_type& assign_inplace(string_type& str, I first, I last)
# else /* ? STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT */
static string_type& assign_inplace(string_type& str, const_iterator first, const_iterator last)
# endif /* STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT */
{
// string view cannot assign in-place
return (str = string_type(first, last), str);
}
};
STLSOFT_TEMPLATE_SPECIALISATION
struct string_traits<wstring_view>
{
typedef wstring_view value_type;
typedef value_type::value_type char_type;
typedef value_type::size_type size_type;
typedef char_type const const_char_type;
typedef value_type string_type;
// typedef string_type::pointer pointer;
typedef string_type::const_pointer const_pointer;
// typedef string_type::iterator iterator;
typedef string_type::const_iterator const_iterator;
#if defined(STLSOFT_LF_BIDIRECTIONAL_ITERATOR_SUPPORT)
// typedef string_type::reverse_iterator reverse_iterator;
typedef string_type::const_reverse_iterator const_reverse_iterator;
#endif /* STLSOFT_LF_BIDIRECTIONAL_ITERATOR_SUPPORT */
enum
{
is_pointer = false
, is_pointer_to_const = false
, char_type_size = sizeof(char_type)
};
static string_type empty_string()
{
return string_type();
}
static string_type construct(string_type const& src, size_type pos, size_type len)
{
return string_type(src, pos, len);
}
# ifdef STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT
template <ss_typename_param_k I>
static string_type& assign_inplace(string_type& str, I first, I last)
# else /* ? STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT */
static string_type& assign_inplace(string_type& str, const_iterator first, const_iterator last)
# endif /* STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT */
{
// string view cannot assign in-place
return (str = string_type(first, last), str);
}
};
# endif /* STLSOFT_CF_TEMPLATE_PARTIAL_SPECIALISATION_SUPPORT */
/* /////////////////////////////////////////////////////////////////////////
* operators
*/
#ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
// operator ==
template<
ss_typename_param_k C
, ss_typename_param_k T
, ss_typename_param_k A
>
inline ss_bool_t operator ==(basic_string_view<C, T, A> const& lhs, basic_string_view<C, T, A> const& rhs)
{
return lhs.equal(rhs);
}
template<
ss_typename_param_k C
, ss_typename_param_k T
, ss_typename_param_k A
>
#ifdef STLSOFT_CF_TEMPLATE_OUTOFCLASSFN_QUALIFIED_TYPE_SUPPORT
inline ss_bool_t operator ==(basic_string_view<C, T, A> const& lhs, ss_typename_type_k basic_string_view<C, T, A>::char_type const* rhs)
#else /* ? STLSOFT_CF_TEMPLATE_OUTOFCLASSFN_QUALIFIED_TYPE_SUPPORT */
inline ss_bool_t operator ==(basic_string_view<C, T, A> const& lhs, C const* rhs)
#endif /* STLSOFT_CF_TEMPLATE_OUTOFCLASSFN_QUALIFIED_TYPE_SUPPORT */
{
typedef ss_typename_type_k basic_string_view<C, T, A>::size_type size_type;
typedef ss_typename_type_k basic_string_view<C, T, A>::traits_type traits_type;
size_type rhs_len = (NULL == rhs) ? 0 : traits_type::length(rhs);
return lhs.equal(rhs, rhs_len);
}
template<
ss_typename_param_k C
, ss_typename_param_k T
, ss_typename_param_k A
>
#ifdef STLSOFT_CF_TEMPLATE_OUTOFCLASSFN_QUALIFIED_TYPE_SUPPORT
inline ss_bool_t operator ==(ss_typename_type_k basic_string_view<C, T, A>::char_type const* lhs, basic_string_view<C, T, A> const& rhs)
#else /* ? STLSOFT_CF_TEMPLATE_OUTOFCLASSFN_QUALIFIED_TYPE_SUPPORT */
inline ss_bool_t operator ==(C *lhs, basic_string_view<C, T, A> const& rhs)
#endif /* STLSOFT_CF_TEMPLATE_OUTOFCLASSFN_QUALIFIED_TYPE_SUPPORT */
{
typedef ss_typename_type_k basic_string_view<C, T, A>::size_type size_type;
typedef ss_typename_type_k basic_string_view<C, T, A>::traits_type traits_type;
size_type lhs_len = (NULL == lhs) ? 0 : traits_type::length(lhs);
return rhs.equal(lhs, lhs_len);
}
// operator !=
template<
ss_typename_param_k C
, ss_typename_param_k T
, ss_typename_param_k A
>
inline ss_bool_t operator !=(basic_string_view<C, T, A> const& lhs, basic_string_view<C, T, A> const& rhs)
{
return !lhs.equal(rhs);
}
template<
ss_typename_param_k C
, ss_typename_param_k T
, ss_typename_param_k A
>
#ifdef STLSOFT_CF_TEMPLATE_OUTOFCLASSFN_QUALIFIED_TYPE_SUPPORT
inline ss_bool_t operator !=(basic_string_view<C, T, A> const& lhs, ss_typename_type_k basic_string_view<C, T, A>::char_type const* rhs)
#else /* ? STLSOFT_CF_TEMPLATE_OUTOFCLASSFN_QUALIFIED_TYPE_SUPPORT */
inline ss_bool_t operator !=(basic_string_view<C, T, A> const& lhs, C const* rhs)
#endif /* STLSOFT_CF_TEMPLATE_OUTOFCLASSFN_QUALIFIED_TYPE_SUPPORT */
{
typedef ss_typename_type_k basic_string_view<C, T, A>::size_type size_type;
typedef ss_typename_type_k basic_string_view<C, T, A>::traits_type traits_type;
size_type rhs_len = (NULL == rhs) ? 0 : traits_type::length(rhs);
return !lhs.equal(rhs, rhs_len);
}
template<
ss_typename_param_k C
, ss_typename_param_k T
, ss_typename_param_k A
>
#ifdef STLSOFT_CF_TEMPLATE_OUTOFCLASSFN_QUALIFIED_TYPE_SUPPORT
inline ss_bool_t operator !=(ss_typename_type_k basic_string_view<C, T, A>::char_type const* lhs, basic_string_view<C, T, A> const& rhs)
#else /* ? STLSOFT_CF_TEMPLATE_OUTOFCLASSFN_QUALIFIED_TYPE_SUPPORT */
inline ss_bool_t operator !=(C const* lhs, basic_string_view<C, T, A> const& rhs)
#endif /* STLSOFT_CF_TEMPLATE_OUTOFCLASSFN_QUALIFIED_TYPE_SUPPORT */
{
typedef ss_typename_type_k basic_string_view<C, T, A>::size_type size_type;
typedef ss_typename_type_k basic_string_view<C, T, A>::traits_type traits_type;
size_type lhs_len = (NULL == lhs) ? 0 : traits_type::length(lhs);
return !rhs.equal(lhs, lhs_len);
}
// operator <
template<
ss_typename_param_k C
, ss_typename_param_k T
, ss_typename_param_k A
>
inline ss_bool_t operator <(basic_string_view<C, T, A> const& lhs, basic_string_view<C, T, A> const& rhs)
{
return lhs.compare(rhs) < 0;
}
template<
ss_typename_param_k C
, ss_typename_param_k T
, ss_typename_param_k A
>
#ifdef STLSOFT_CF_TEMPLATE_OUTOFCLASSFN_QUALIFIED_TYPE_SUPPORT
inline ss_bool_t operator <(basic_string_view<C, T, A> const& lhs, ss_typename_type_k basic_string_view<C, T, A>::char_type const* rhs)
#else /* ? STLSOFT_CF_TEMPLATE_OUTOFCLASSFN_QUALIFIED_TYPE_SUPPORT */
inline ss_bool_t operator <(basic_string_view<C, T, A> const& lhs, C const* rhs)
#endif /* STLSOFT_CF_TEMPLATE_OUTOFCLASSFN_QUALIFIED_TYPE_SUPPORT */
{
return lhs.compare(rhs) < 0;
}
template<
ss_typename_param_k C
, ss_typename_param_k T
, ss_typename_param_k A
>
#ifdef STLSOFT_CF_TEMPLATE_OUTOFCLASSFN_QUALIFIED_TYPE_SUPPORT
inline ss_bool_t operator <(ss_typename_type_k basic_string_view<C, T, A>::char_type const* lhs, basic_string_view<C, T, A> const& rhs)
#else /* ? STLSOFT_CF_TEMPLATE_OUTOFCLASSFN_QUALIFIED_TYPE_SUPPORT */
inline ss_bool_t operator <(C const* lhs, basic_string_view<C, T, A> const& rhs)
#endif /* STLSOFT_CF_TEMPLATE_OUTOFCLASSFN_QUALIFIED_TYPE_SUPPORT */
{
return rhs.compare(lhs) > 0;
}
// operator <=
template<
ss_typename_param_k C
, ss_typename_param_k T
, ss_typename_param_k A
>
inline ss_bool_t operator <=(basic_string_view<C, T, A> const& lhs, basic_string_view<C, T, A> const& rhs)
{
return lhs.compare(rhs) <= 0;
}
template<
ss_typename_param_k C
, ss_typename_param_k T
, ss_typename_param_k A
>
#ifdef STLSOFT_CF_TEMPLATE_OUTOFCLASSFN_QUALIFIED_TYPE_SUPPORT
inline ss_bool_t operator <=(basic_string_view<C, T, A> const& lhs, ss_typename_type_k basic_string_view<C, T, A>::char_type const* rhs)
#else /* ? STLSOFT_CF_TEMPLATE_OUTOFCLASSFN_QUALIFIED_TYPE_SUPPORT */
inline ss_bool_t operator <=(basic_string_view<C, T, A> const& lhs, C const* rhs)
#endif /* STLSOFT_CF_TEMPLATE_OUTOFCLASSFN_QUALIFIED_TYPE_SUPPORT */
{
return lhs.compare(rhs) <= 0;
}
template<
ss_typename_param_k C
, ss_typename_param_k T
, ss_typename_param_k A
>
#ifdef STLSOFT_CF_TEMPLATE_OUTOFCLASSFN_QUALIFIED_TYPE_SUPPORT
inline ss_bool_t operator <=(ss_typename_type_k basic_string_view<C, T, A>::char_type const* lhs, basic_string_view<C, T, A> const& rhs)
#else /* ? STLSOFT_CF_TEMPLATE_OUTOFCLASSFN_QUALIFIED_TYPE_SUPPORT */
inline ss_bool_t operator <=(C const* lhs, basic_string_view<C, T, A> const& rhs)
#endif /* STLSOFT_CF_TEMPLATE_OUTOFCLASSFN_QUALIFIED_TYPE_SUPPORT */
{
return rhs.compare(lhs) >= 0;
}
// operator >
template<
ss_typename_param_k C
, ss_typename_param_k T
, ss_typename_param_k A
>
inline ss_bool_t operator >(basic_string_view<C, T, A> const& lhs, basic_string_view<C, T, A> const& rhs)
{
return lhs.compare(rhs) > 0;
}
template<
ss_typename_param_k C
, ss_typename_param_k T
, ss_typename_param_k A
>
#ifdef STLSOFT_CF_TEMPLATE_OUTOFCLASSFN_QUALIFIED_TYPE_SUPPORT
inline ss_bool_t operator >(basic_string_view<C, T, A> const& lhs, ss_typename_type_k basic_string_view<C, T, A>::char_type const* rhs)
#else /* ? STLSOFT_CF_TEMPLATE_OUTOFCLASSFN_QUALIFIED_TYPE_SUPPORT */
inline ss_bool_t operator >(basic_string_view<C, T, A> const& lhs, C const* rhs)
#endif /* STLSOFT_CF_TEMPLATE_OUTOFCLASSFN_QUALIFIED_TYPE_SUPPORT */
{
return lhs.compare(rhs) > 0;
}
template<
ss_typename_param_k C
, ss_typename_param_k T
, ss_typename_param_k A
>
#ifdef STLSOFT_CF_TEMPLATE_OUTOFCLASSFN_QUALIFIED_TYPE_SUPPORT
inline ss_bool_t operator >(ss_typename_type_k basic_string_view<C, T, A>::char_type const* lhs, basic_string_view<C, T, A> const& rhs)
#else /* ? STLSOFT_CF_TEMPLATE_OUTOFCLASSFN_QUALIFIED_TYPE_SUPPORT */
inline ss_bool_t operator >(C const* lhs, basic_string_view<C, T, A> const& rhs)
#endif /* STLSOFT_CF_TEMPLATE_OUTOFCLASSFN_QUALIFIED_TYPE_SUPPORT */
{
return rhs.compare(lhs) < 0;
}
// operator >=
template<
ss_typename_param_k C
, ss_typename_param_k T
, ss_typename_param_k A
>
inline ss_bool_t operator >=(basic_string_view<C, T, A> const& lhs, basic_string_view<C, T, A> const& rhs)
{
return lhs.compare(rhs) >= 0;
}
template<
ss_typename_param_k C
, ss_typename_param_k T
, ss_typename_param_k A
>
#ifdef STLSOFT_CF_TEMPLATE_OUTOFCLASSFN_QUALIFIED_TYPE_SUPPORT
inline ss_bool_t operator >=(basic_string_view<C, T, A> const& lhs, ss_typename_type_k basic_string_view<C, T, A>::char_type const* rhs)
#else /* ? STLSOFT_CF_TEMPLATE_OUTOFCLASSFN_QUALIFIED_TYPE_SUPPORT */
inline ss_bool_t operator >=(basic_string_view<C, T, A> const& lhs, C const* rhs)
#endif /* STLSOFT_CF_TEMPLATE_OUTOFCLASSFN_QUALIFIED_TYPE_SUPPORT */
{
return lhs.compare(rhs) >= 0;
}
template<
ss_typename_param_k C
, ss_typename_param_k T
, ss_typename_param_k A
>
#ifdef STLSOFT_CF_TEMPLATE_OUTOFCLASSFN_QUALIFIED_TYPE_SUPPORT
inline ss_bool_t operator >=(ss_typename_type_k basic_string_view<C, T, A>::char_type const* lhs, basic_string_view<C, T, A> const& rhs)
#else /* ? STLSOFT_CF_TEMPLATE_OUTOFCLASSFN_QUALIFIED_TYPE_SUPPORT */
inline ss_bool_t operator >=(C const* lhs, basic_string_view<C, T, A> const& rhs)
#endif /* STLSOFT_CF_TEMPLATE_OUTOFCLASSFN_QUALIFIED_TYPE_SUPPORT */
{
return rhs.compare(lhs) <= 0;
}
#endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
/* /////////////////////////////////////////////////////////////////////////
* stream insertion
*/
template <
ss_typename_param_k T_stream
, ss_typename_param_k C
, ss_typename_param_k T
, ss_typename_param_k A
>
inline
T_stream&
operator <<(
T_stream& stm
, basic_string_view<C, T, A> const& s
)
{
STLSOFT_NS_USING(util::string_insert);
string_insert(stm, s.data(), s.size());
return stm;
}
/* /////////////////////////////////////////////////////////////////////////
* implementation
*/
#ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
// Implementation
template<
ss_typename_param_k C
, ss_typename_param_k T
, ss_typename_param_k A
>
inline
/* static */ ss_typename_type_ret_k basic_string_view<C, T, A>::char_type const*
basic_string_view<C, T, A>::empty_string_() STLSOFT_NOEXCEPT
{
// This character array is initialised to 0, which conveniently happens to
// be the empty string, by the module/application load, so it is
// guaranteed to be valid, and there are no threading/race conditions
static char_type s_empty[1];
STLSOFT_ASSERT(s_empty[0] == '\0'); // Paranoid check