Repository navigation
Expand file tree
/
Copy pathsimple_string.hpp
More file actions
4070 lines (3627 loc) · 113 KB
/
Copy pathsimple_string.hpp
File metadata and controls
4070 lines (3627 loc) · 113 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/simple_string.hpp (originally MSString.h, ::SynesisDev)
*
* Purpose: basic_simple_string class template.
*
* Created: 19th March 1993
* Updated: 15th October 2026
*
* Home: http://stlsoft.org/
*
* Copyright (c) 2019-2026, Matthew Wilson and Synesis Information Systems
* Copyright (c) 1993-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/simple_string.hpp
*
* \brief [C++] Definition of the stlsoft::basic_simple_string class
* template
* (\ref group__library__String "String" Library).
*/
#ifndef STLSOFT_INCL_STLSOFT_STRING_HPP_SIMPLE_STRING
#define STLSOFT_INCL_STLSOFT_STRING_HPP_SIMPLE_STRING
#ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
# define STLSOFT_VER_STLSOFT_STRING_HPP_SIMPLE_STRING_MAJOR 5
# define STLSOFT_VER_STLSOFT_STRING_HPP_SIMPLE_STRING_MINOR 0
# define STLSOFT_VER_STLSOFT_STRING_HPP_SIMPLE_STRING_REVISION 1
# define STLSOFT_VER_STLSOFT_STRING_HPP_SIMPLE_STRING_EDIT 288
#endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
/* /////////////////////////////////////////////////////////////////////////
* 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 */
#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_COLLECTIONS_UTIL_HPP_COLLECTIONS
# include <stlsoft/collections/util/collections.hpp>
#endif /* !STLSOFT_INCL_STLSOFT_COLLECTIONS_UTIL_HPP_COLLECTIONS */
#ifndef STLSOFT_INCL_STLSOFT_MEMORY_HPP_ALLOCATOR_BASE
# include <stlsoft/memory/allocator_base.hpp> // for STLSOFT_LF_ALLOCATOR_REBIND_SUPPORT
#endif /* !STLSOFT_INCL_STLSOFT_MEMORY_HPP_ALLOCATOR_BASE */
#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_MEMORY_HPP_AUTO_BUFFER
# include <stlsoft/memory/auto_buffer.hpp>
#endif /* !STLSOFT_INCL_STLSOFT_MEMORY_HPP_AUTO_BUFFER */
#ifndef STLSOFT_INCL_STLSOFT_UTIL_HPP_STD_SWAP
# include <stlsoft/util/std_swap.hpp> // for stlsoft::std_swap()
#endif /* !STLSOFT_INCL_STLSOFT_UTIL_HPP_STD_SWAP */
#ifndef STLSOFT_INCL_STLSOFT_UTIL_STD_HPP_ITERATOR_GENERATORS
# include <stlsoft/util/std/iterator_generators.hpp>
#endif /* !STLSOFT_INCL_STLSOFT_UTIL_STD_HPP_ITERATOR_GENERATORS */
#ifndef STLSOFT_INCL_STLSOFT_ALGORITHMS_HPP_BOUNDED
# include <stlsoft/algorithms/bounded.hpp> // for stlsoft::copy_n()
#endif /* !STLSOFT_INCL_STLSOFT_ALGORITHMS_HPP_BOUNDED */
#ifndef STLSOFT_INCL_STLSOFT_UTIL_HPP_MINMAX
# include <stlsoft/util/minmax.hpp>
#endif /* !STLSOFT_INCL_STLSOFT_UTIL_HPP_MINMAX */
#ifndef STLSOFT_INCL_STLSOFT_CONVERSION_HPP_SAP_CAST
# include <stlsoft/conversion/sap_cast.hpp>
#endif /* !STLSOFT_INCL_STLSOFT_CONVERSION_HPP_SAP_CAST */
#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_STREAMS_HPP_STRING_INSERTION
# include <stlsoft/util/streams/string_insertion.hpp>
#endif /* !STLSOFT_INCL_STLSOFT_UTIL_STREAMS_HPP_STRING_INSERTION */
#if defined(__BORLANDC__) && \
__BORLANDC__ > 0x0580 && \
defined(STLSOFT_DEBUG)
# include <stdio.h>
#endif /* compiler */
#ifdef STLSOFT_CF_EXCEPTION_SUPPORT
# include <stdexcept> // for std::out_of_range
#endif /* !STLSOFT_CF_EXCEPTION_SUPPORT */
#ifndef STLSOFT_INCL_STLSOFT_API_external_h_memfns
# include <stlsoft/api/external/memfns.h>
#endif /* !STLSOFT_INCL_STLSOFT_API_external_h_memfns */
/* /////////////////////////////////////////////////////////////////////////
* compatibility
*/
#if defined(STLSOFT_COMPILER_IS_MSVC) && \
_MSC_VER < 1200
# define STLSOFT_SIMPLE_STRING_ITERATOR_METHODS_INLINE
#endif /* compiler */
/* /////////////////////////////////////////////////////////////////////////
* namespace
*/
#ifndef STLSOFT_NO_NAMESPACE
namespace stlsoft
{
#endif /* STLSOFT_NO_NAMESPACE */
/* /////////////////////////////////////////////////////////////////////////
* classes
*/
/** Simple string class
*
* \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
*
* \ingroup group__library__String
*/
template<
ss_typename_param_k C
#ifdef STLSOFT_CF_TEMPLATE_CLASS_DEFAULT_CLASS_ARGUMENT_SUPPORT
, ss_typename_param_k T = stlsoft_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 /* = stlsoft_char_traits<C> */
, ss_typename_param_k A /* = allocator_selector<C>::allocator_type */
#endif /* STLSOFT_CF_TEMPLATE_CLASS_DEFAULT_CLASS_ARGUMENT_SUPPORT */
>
// class basic_simple_string
class basic_simple_string
: public stl_collection_tag
{
/// \name Member Types
/// @{
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_simple_string<
C
, T
, A
> class_type;
/// The character type
typedef value_type char_type;
/// The pointer type
typedef value_type* pointer;
/// The non-mutable (const) pointer type
typedef value_type const* const_pointer;
/// The reference type
typedef value_type& reference;
/// 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;
/// The iterator type
typedef
#if !defined(STLSOFT_COMPILER_IS_BORLAND)
ss_typename_type_k
#endif /* compiler */
pointer_iterator<
value_type
, pointer
, reference
>::type iterator;
/// 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)
/// The mutating (non-const) reverse iterator type
typedef ss_typename_type_k reverse_iterator_generator<
iterator
, value_type
, reference
, pointer
, difference_type
>::type reverse_iterator;
/// The non-mutating (const) reverse iterator type
typedef ss_typename_type_k const_reverse_iterator_generator<
const_iterator
, value_type
, const_reference
, const_pointer
, difference_type
>::type const_reverse_iterator;
#endif /* STLSOFT_LF_BIDIRECTIONAL_ITERATOR_SUPPORT */
private:
/// The allocator type for allocating bytes
///
/// \note This has to be defined here, rather than on a use-by-use basis, because
/// Borland gets very upset.
#ifdef STLSOFT_LF_ALLOCATOR_REBIND_SUPPORT
typedef ss_typename_type_k A::ss_template_qual_k rebind<
ss_byte_t
>::other byte_ator_type;
#else /* ? STLSOFT_LF_ALLOCATOR_REBIND_SUPPORT */
typedef ss_typename_type_k allocator_selector<
ss_byte_t
>::allocator_type byte_ator_type;
#endif /* STLSOFT_LF_ALLOCATOR_REBIND_SUPPORT */
/// @}
/// \name Construction
/// @{
public:
/// Default constructor
ss_constexpr_2014_k
basic_simple_string() STLSOFT_NOEXCEPT;
/// Copy constructor
basic_simple_string(class_type const& rhs);
/// Construct from the given string at the specified position
basic_simple_string(class_type const& s, size_type pos);
/// Construct with \c cch characters from the given string at the specified position
basic_simple_string(class_type const& s, size_type pos, size_type cch);
/// Construct from the given character string
basic_simple_string(char_type const* s); // Not, not explicit. Sigh
/// Construct with \c cch characters from the given character string
basic_simple_string(char_type const* s, size_type cch);
/// Construct with \c cch characters each set to \c ch
basic_simple_string(size_type cch, char_type ch);
/// Construct from the range [first:last)
#if !defined(STLSOFT_CF_MEMBER_TEMPLATE_RANGE_METHOD_SUPPORT)
basic_simple_string(char_type const* first, char_type const* last);
#else /* ? STLSOFT_CF_MEMBER_TEMPLATE_RANGE_METHOD_SUPPORT */
template <ss_typename_param_k II>
basic_simple_string(II first, II last)
: m_buffer(ss_nullptr_k)
{
assign(first, last);
}
#endif /* STLSOFT_CF_MEMBER_TEMPLATE_RANGE_METHOD_SUPPORT */
#ifdef STLSOFT_CF_RVALUE_REFERENCES_SUPPORT
/// Transfers the contents of the instance \c rhs
basic_simple_string(class_type&& rhs) STLSOFT_NOEXCEPT;
#endif /* STLSOFT_CF_RVALUE_REFERENCES_SUPPORT */
/// Destructor
ss_constexpr_2020_k
~basic_simple_string() STLSOFT_NOEXCEPT;
/// @}
/// \name Assignment
/// @{
public:
/// Assigns from the given character string
class_type& assign(char_type const* s);
/// Assigns with \c cch characters from the given character string
class_type& assign(char_type const* s, size_type cch);
/// Assigns with \c cch characters from the given character string at the specified position
class_type& assign(class_type const& str, size_type pos, size_type cch);
/// Assigns from the given string
class_type& assign(class_type const& str);
/// Assigns \c cch characters with the value \c ch
class_type& assign(size_type cch, char_type ch);
/// Assigns from the range [first:last)
#if !defined(STLSOFT_CF_MEMBER_TEMPLATE_RANGE_METHOD_SUPPORT)
class_type& assign(const_iterator first, const_iterator last);
#else /* ? STLSOFT_CF_MEMBER_TEMPLATE_RANGE_METHOD_SUPPORT */
template <ss_typename_param_k II>
class_type& assign(II first, II last)
{
# if ( defined(STLSOFT_COMPILER_IS_GCC) && \
__GNUC__ < 3) || \
( defined(STLSOFT_COMPILER_IS_BORLAND) && \
defined(STLSOFT_CF_STD_LIBRARY_IS_DINKUMWARE_BORLAND))
typedef ss_typename_type_k std::iterator_traits<II> traits_t;
return assign_(first, last, traits_t::iterator_category());
# elif defined(STLSOFT_COMPILER_IS_MWERKS) || \
defined(STLSOFT_COMPILER_IS_DMC)
return assign_(first, last, stlsoft_iterator_query_category_ptr(II, first));
# else /* ? compiler */
return assign_(first, last, stlsoft_iterator_query_category(II, first));
# endif /* compiler */
}
#endif /* STLSOFT_CF_MEMBER_TEMPLATE_RANGE_METHOD_SUPPORT */
/// Copy assignment operator
class_type const& operator =(class_type const& rhs);
/// Assignment operator
class_type const& operator =(char_type const* s);
/// Assignment operator
class_type const& operator =(char_type ch);
/// @}
/// \name Appending
/// @{
public:
/// Appends the given character string
class_type& append(char_type const* s);
/// Appends \c cch characters from the given character string
class_type& append(char_type const* s, size_type cch);
/// Assigns \c cch characters from the given character string at the specified position
class_type& append(class_type const& str, size_type pos, size_type cch);
/// Appends the given string
class_type& append(class_type const& str);
/// Appends \c cch characters with the value \c ch
class_type& append(size_type cch, char_type ch);
/// Appends the range [first:last)
#if !defined(STLSOFT_CF_MEMBER_TEMPLATE_RANGE_METHOD_SUPPORT)
class_type& append(const_iterator first, const_iterator last);
#else /* ? STLSOFT_CF_MEMBER_TEMPLATE_RANGE_METHOD_SUPPORT */
template <ss_typename_param_k II>
class_type& append(II first, II last)
{
# if ( defined(STLSOFT_COMPILER_IS_GCC) && \
__GNUC__ < 3) || \
( defined(STLSOFT_COMPILER_IS_BORLAND) && \
defined(STLSOFT_CF_STD_LIBRARY_IS_DINKUMWARE_BORLAND))
typedef ss_typename_type_k std::iterator_traits<II> traits_t;
return append_(first, last, traits_t::iterator_category());
# elif defined(STLSOFT_COMPILER_IS_MWERKS) || \
defined(STLSOFT_COMPILER_IS_DMC)
return append_(first, last, stlsoft_iterator_query_category_ptr(II, first));
# else /* ? compiler */
return append_(first, last, stlsoft_iterator_query_category(II, first));
# endif /* compiler */
}
#endif /* STLSOFT_CF_MEMBER_TEMPLATE_RANGE_METHOD_SUPPORT */
/// Concatenation operator
class_type& operator +=(char_type ch);
/// Concatenation operator
class_type& operator +=(char_type const* s);
/// Concatenation operator
class_type& operator +=(class_type const& rhs);
/// Appends a single character
void push_back(char_type ch);
/// Removes the last character
void pop_back() STLSOFT_NOEXCEPT;
/// @}
/// \name Modifiers
/// @{
public:
/// Reserves at least cch characters
void reserve(size_type cch);
/// Swaps the contents between \c this and \c other
void swap(class_type& other) STLSOFT_NOEXCEPT;
/// Resizes the string
///
/// \param cch The new size of the string
/// \param ch The value with which to initialise additional items if the string is expanded
void resize(size_type cch, value_type ch = value_type());
/// Empties the string
void clear() 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
size_type max_size() const 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;
/// @}
/// \name Comparison
/// @{
public:
/// Equates the substring [pos, pos+cch) of \c this with the substring [0, cchRhs) of the given C-style string \c s
ss_bool_t equal(size_type pos, size_type cch, value_type const* s, size_type cchRhs) const STLSOFT_NOEXCEPT;
/// Equates the substring [pos, pos+cch) of \c this with the given C-style string \c s
ss_bool_t equal(size_type pos, size_type cch, value_type const* s) const STLSOFT_NOEXCEPT;
/// Equates \c this with the given C-style string \c s
ss_bool_t equal(value_type const* s) const STLSOFT_NOEXCEPT;
/// Equates the substring [pos, pos+cch) of \c this with the substring [posRhs, posRhs+cchRhs) of the given string \c rhs
ss_bool_t equal(size_type pos, size_type cch, class_type const& rhs, size_type posRhs, size_type cchRhs) const STLSOFT_NOEXCEPT;
/// Equates the substring [pos, pos+cch) of \c this with the given string
ss_bool_t equal(size_type pos, size_type cch, class_type const& rhs) const STLSOFT_NOEXCEPT;
/// Equates \c this with the given string \c rhs
ss_bool_t equal(class_type const& rhs) const STLSOFT_NOEXCEPT;
/// Compares the substring [pos, pos+cch) of \c this with the substring [0, cchRhs) of the given C-style string \c s
ss_sint_t compare(size_type pos, size_type cch, value_type const* s, size_type cchRhs) const STLSOFT_NOEXCEPT;
/// Compares the substring [pos, pos+cch) of \c this with the given C-style string \c s
ss_sint_t compare(size_type pos, size_type cch, value_type const* s) const STLSOFT_NOEXCEPT;
/// Compares \c this with the given C-style string \c s
ss_sint_t compare(value_type const* s) const STLSOFT_NOEXCEPT;
/// Compares the substring [pos, pos+cch) of \c this with the substring [posRhs, posRhs+cchRhs) of the given string \c rhs
ss_sint_t compare(size_type pos, size_type cch, class_type const& rhs, size_type posRhs, size_type cchRhs) const STLSOFT_NOEXCEPT;
/// Compares the substring [pos, pos+cch) of \c this with the given string \c rhs
ss_sint_t compare(size_type pos, size_type cch, class_type const& rhs) const STLSOFT_NOEXCEPT;
/// Compares \c this with the given string \c rhs
ss_sint_t compare(class_type const& rhs) const STLSOFT_NOEXCEPT;
/// Indicates whether the string contains the string \c s
bool contains(class_type const& s) const STLSOFT_NOEXCEPT;
/// Indicates whether the string contains the C-style string \c s
bool contains(char_type const* s) const STLSOFT_NOEXCEPT;
/// Indicates whether the string contains the character \c ch
bool contains(char_type ch) const STLSOFT_NOEXCEPT;
/// Indicates whether the string starts with the string \c s
bool starts_with(class_type const& s) const STLSOFT_NOEXCEPT;
/// Indicates whether the string starts with the C-style string \c s
bool starts_with(char_type const* s) const STLSOFT_NOEXCEPT;
/// Indicates whether the string starts with the character \c ch
bool starts_with(char_type ch) const STLSOFT_NOEXCEPT;
/// Indicates whether the string ends with the string \c s
bool ends_with(class_type const& s) const STLSOFT_NOEXCEPT;
/// Indicates whether the string ends with the C-style string \c s
bool ends_with(char_type const* s) const STLSOFT_NOEXCEPT;
/// Indicates whether the string ends with the character \c ch
bool ends_with(char_type ch) const STLSOFT_NOEXCEPT;
/// @}
/// \name Accessors
/// @{
public:
/// Returns mutable reference at the given index
reference operator [](size_type index) STLSOFT_NOEXCEPT;
/// Returns non-mutable (const) reference at the given index
const_reference operator [](size_type index) const STLSOFT_NOEXCEPT;
#ifdef STLSOFT_CF_EXCEPTION_SUPPORT
/// Returns mutable (non-const) reference at the given index
///
/// \note Throws std::out_of_range if index >= size()
reference at(size_type index);
/// 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
value_type const* c_str() const STLSOFT_NOEXCEPT;
/// Returns non-mutable (const) pointer to string data
value_type const* data() const STLSOFT_NOEXCEPT;
/// Returns the first character in the string
///
/// \note It is us to the user to ensure that the string is not empty
reference front() STLSOFT_NOEXCEPT;
/// Returns the last character in the string
///
/// \note It is us to the user to ensure that the string is not empty
reference back() STLSOFT_NOEXCEPT;
/// Returns the first character in the string
///
/// \note It is us to the user to ensure that the string is not empty
const_reference front() const STLSOFT_NOEXCEPT;
/// Returns the last character in the string
///
/// \note It is us to the user to ensure that the string is not empty
const_reference back() const STLSOFT_NOEXCEPT;
/// Copies elements into the given destination
size_type copy(
value_type* dest
, size_type cch
, size_type pos = 0
) const STLSOFT_NOEXCEPT;
/// @}
/// \name Iteration
/// @{
public:
/// Begins the iteration
///
/// \return A non-mutable (const) iterator representing the start of the sequence
#ifdef STLSOFT_SIMPLE_STRING_ITERATOR_METHODS_INLINE
const_iterator begin() const STLSOFT_NOEXCEPT
{
return const_cast<class_type*>(this)->begin_();
}
#else /* ? STLSOFT_SIMPLE_STRING_ITERATOR_METHODS_INLINE */
const_iterator begin() const STLSOFT_NOEXCEPT;
#endif /* STLSOFT_SIMPLE_STRING_ITERATOR_METHODS_INLINE */
/// Ends the iteration
///
/// \return A non-mutable (const) iterator representing the end of the sequence
#ifdef STLSOFT_SIMPLE_STRING_ITERATOR_METHODS_INLINE
const_iterator end() const STLSOFT_NOEXCEPT
{
return const_cast<class_type*>(this)->end_();
}
#else /* ? STLSOFT_SIMPLE_STRING_ITERATOR_METHODS_INLINE */
const_iterator end() const STLSOFT_NOEXCEPT;
#endif /* STLSOFT_SIMPLE_STRING_ITERATOR_METHODS_INLINE */
/// Begins the iteration
///
/// \return An iterator representing the start of the sequence
iterator begin() STLSOFT_NOEXCEPT;
/// Ends the iteration
///
/// \return An iterator representing the end of the sequence
iterator end() STLSOFT_NOEXCEPT;
#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 STLSOFT_NOEXCEPT;
/// Ends the reverse iteration
///
/// \return A non-mutable (const) iterator representing the end of the reverse sequence
const_reverse_iterator rend() const STLSOFT_NOEXCEPT;
/// Begins the reverse iteration
///
/// \return An iterator representing the start of the reverse sequence
reverse_iterator rbegin() STLSOFT_NOEXCEPT;
/// Ends the reverse iteration
///
/// \return An iterator representing the end of the reverse sequence
reverse_iterator rend() STLSOFT_NOEXCEPT;
#endif /* STLSOFT_LF_BIDIRECTIONAL_ITERATOR_SUPPORT */
/// @}
/// \name Implementation
/// @{
private:
enum { alloc_quantum = 31 }; // Must be (2^n - 1)
struct string_buffer
{
size_type capacity; // The number of char places in the buffer
size_type length; // The number of chars in the string (<= capacity)
char_type contents[1]; // The first element in the array
};
typedef auto_buffer<
char_type
, auto_buffer_internal_size_calculator<char_type>::value
, allocator_type
> buffer_type_;
#ifdef STLSOFT_SIMPLE_STRING_NO_PTR_ADJUST
typedef string_buffer* member_pointer;
typedef string_buffer const* member_const_pointer;
#else /* ? STLSOFT_SIMPLE_STRING_NO_PTR_ADJUST */
typedef char_type* member_pointer;
typedef char_type const* member_const_pointer;
#endif /* STLSOFT_SIMPLE_STRING_NO_PTR_ADJUST */
// Conversion between member pointer and character pointer
static char_type* char_pointer_from_member_pointer_(member_pointer ) STLSOFT_NOEXCEPT;
// Conversion between pointer and buffer
static ss_constexpr_2014_k string_buffer* string_buffer_from_member_pointer_(member_pointer ) STLSOFT_NOEXCEPT;
static ss_constexpr_2014_k string_buffer const* string_buffer_from_member_pointer_(member_const_pointer ) STLSOFT_NOEXCEPT;
// Conversion between buffer and pointer
static member_pointer member_pointer_from_string_buffer_(string_buffer*) STLSOFT_NOEXCEPT;
// Creating buffer
static member_pointer alloc_buffer_(char_type const* s, size_type capacity, size_type length);
static member_pointer alloc_buffer_(char_type const* s, size_type cch);
static member_pointer alloc_buffer_(char_type const* s);
// Copying a buffer
static member_pointer copy_buffer_(member_pointer );
// Destroying buffer
static void destroy_buffer_(string_buffer*) STLSOFT_NOEXCEPT;
static void destroy_buffer_(char_type*) STLSOFT_NOEXCEPT;
// Iteration
pointer begin_() STLSOFT_NOEXCEPT;
pointer end_() STLSOFT_NOEXCEPT;
// Invariance
ss_constexpr_2014_k
ss_bool_t is_valid() const STLSOFT_NOEXCEPT;
// 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;
// testing known-length lhs against css rhs
static ss_bool_t equal_(
char_type const* lhs
, size_type lhs_len
, char_type const* rhs
) STLSOFT_NOEXCEPT;
// testing same-known-length lhs and rhs
static ss_bool_t equal_(
char_type const* lhs
, char_type const* rhs
, size_type len
) STLSOFT_NOEXCEPT;
bool contains_(
char_type const* s
, size_type n
) const STLSOFT_NOEXCEPT;
bool starts_with_(
char_type const* s
, size_type n
) const STLSOFT_NOEXCEPT;
bool ends_with_(
char_type const* s
, size_type n
) const STLSOFT_NOEXCEPT;
// Assignment
#if defined(STLSOFT_CF_MEMBER_TEMPLATE_RANGE_METHOD_SUPPORT)
template <ss_typename_param_k II>
# if defined(STLSOFT_COMPILER_IS_MWERKS) || \
defined(STLSOFT_COMPILER_IS_DMC)
// There seems to be a bug in CodeWarrior that makes it have a cow with iterator tags by value, so we just use a ptr
class_type& assign_(II first, II last, STLSOFT_NS_QUAL_STD(input_iterator_tag) const*)
# else /* ? compiler */
class_type& assign_(II first, II last, STLSOFT_NS_QUAL_STD(input_iterator_tag))
# endif /* compiler */
{
STLSOFT_NS_QUAL_STD(copy)(first, last, STLSOFT_NS_QUAL_STD(back_inserter)(*this));
STLSOFT_ASSERT(is_valid());
return *this;
}
template <ss_typename_param_k II>
# if defined(STLSOFT_COMPILER_IS_MWERKS) || \
defined(STLSOFT_COMPILER_IS_DMC)
// There seems to be a bug in CodeWarrior that makes it have a cow with iterator tags by value, so we just use a ptr
class_type& assign_(II first, II last, STLSOFT_NS_QUAL_STD(forward_iterator_tag) const*)
# else /* ? compiler */
class_type& assign_(II first, II last, STLSOFT_NS_QUAL_STD(forward_iterator_tag))
# endif /* compiler */
{
ss_size_t const n = static_cast<ss_size_t>(STLSOFT_NS_QUAL_STD(distance)(first, last));
buffer_type_ buffer(n);
copy_n(first, buffer.size(), &buffer[0]);
assign(buffer.data(), buffer.size());
STLSOFT_ASSERT(is_valid());
return *this;
}
#endif /* STLSOFT_CF_MEMBER_TEMPLATE_RANGE_METHOD_SUPPORT */
// Appending
#if defined(STLSOFT_CF_MEMBER_TEMPLATE_RANGE_METHOD_SUPPORT)
template <ss_typename_param_k II>
# if defined(STLSOFT_COMPILER_IS_MWERKS) || \
defined(STLSOFT_COMPILER_IS_DMC)
class_type& append_(II first, II last, STLSOFT_NS_QUAL_STD(input_iterator_tag) const*)
# else /* ? compiler */
class_type& append_(II first, II last, STLSOFT_NS_QUAL_STD(input_iterator_tag))
# endif /* compiler */
{
STLSOFT_NS_QUAL_STD(copy)(first, last, STLSOFT_NS_QUAL_STD(back_inserter)(*this));
STLSOFT_ASSERT(is_valid());
return *this;
}
template <ss_typename_param_k II>
# if defined(STLSOFT_COMPILER_IS_MWERKS) || \
defined(STLSOFT_COMPILER_IS_DMC)
class_type& append_(II first, II last, STLSOFT_NS_QUAL_STD(forward_iterator_tag) const*)
# else /* ? compiler */
class_type& append_(II first, II last, STLSOFT_NS_QUAL_STD(forward_iterator_tag))
# endif /* compiler */
{
buffer_type_ buffer(static_cast<ss_size_t>(STLSOFT_NS_QUAL_STD(distance)(first, last)));
std_copy(first, last, &buffer[0]);
append(buffer.data(), buffer.size());
STLSOFT_ASSERT(is_valid());
return *this;
}
#endif /* STLSOFT_CF_MEMBER_TEMPLATE_RANGE_METHOD_SUPPORT */
/// @}
/// \name Members
/// @{
private:
member_pointer m_buffer;
/// @}
};
/* /////////////////////////////////////////////////////////////////////////
* typedefs
*/
#ifdef STLSOFT_CF_TEMPLATE_CLASS_DEFAULT_CLASS_ARGUMENT_SUPPORT
typedef basic_simple_string<ss_char_a_t> simple_string;
typedef basic_simple_string<ss_char_w_t> simple_wstring;
#else /* ? STLSOFT_CF_TEMPLATE_CLASS_DEFAULT_CLASS_ARGUMENT_SUPPORT */
typedef basic_simple_string<
ss_char_a_t
, stlsoft_char_traits<ss_char_a_t>
, allocator_selector<ss_char_a_t>::allocator_type
> simple_string;
typedef basic_simple_string<
ss_char_w_t
, stlsoft_char_traits<ss_char_w_t>
, allocator_selector<ss_char_w_t>::allocator_type
> simple_wstring;
#endif /* STLSOFT_CF_TEMPLATE_CLASS_DEFAULT_CLASS_ARGUMENT_SUPPORT */
/* /////////////////////////////////////////////////////////////////////////
* traits
*/
/** Specialisation for stlsoft::basic_simple_string<>
*/
# 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_simple_string<C, T, A>
>
{
// NOTE: Originally, what is string_type_ was defined as value_type, but
// Borland objects to value_type::value_type.
typedef basic_simple_string<C> 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() STLSOFT_NOEXCEPT
{
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 */
{
// simple_string can assign in-place
return str.assign(first, last);
}
};
# else /* ? STLSOFT_CF_TEMPLATE_PARTIAL_SPECIALISATION_SUPPORT */
STLSOFT_TEMPLATE_SPECIALISATION
struct string_traits<simple_string>
{
typedef basic_simple_string<ss_char_a_t> 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 */
{
// simple_string can assign in-place
return str.assign(first, last);
}
};
STLSOFT_TEMPLATE_SPECIALISATION
struct string_traits<simple_wstring>
{
typedef basic_simple_string<ss_char_w_t> 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 */
{
// simple_string can assign in-place
return str.assign(first, last);
}
};
# 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_simple_string<C, T, A> const& lhs
, basic_simple_string<C, T, A> const& rhs
)
{
return 0 == lhs.compare(rhs);
}
template <
ss_typename_param_k C
, ss_typename_param_k T
, ss_typename_param_k A
>
inline
ss_bool_t
#ifdef STLSOFT_CF_TEMPLATE_OUTOFCLASSFN_QUALIFIED_TYPE_SUPPORT
operator ==(
basic_simple_string<C, T, A> const& lhs
, ss_typename_type_k basic_simple_string<C, T, A>::char_type const* rhs
)
#else /* ? STLSOFT_CF_TEMPLATE_OUTOFCLASSFN_QUALIFIED_TYPE_SUPPORT */
operator ==(
basic_simple_string<C, T, A> const& lhs
, C const* rhs
)
#endif /* STLSOFT_CF_TEMPLATE_OUTOFCLASSFN_QUALIFIED_TYPE_SUPPORT */
{
return 0 == lhs.compare(rhs);
}
template <
ss_typename_param_k C
, ss_typename_param_k T
, ss_typename_param_k A
>
inline
ss_bool_t
#ifdef STLSOFT_CF_TEMPLATE_OUTOFCLASSFN_QUALIFIED_TYPE_SUPPORT
operator ==(
ss_typename_type_k basic_simple_string<C, T, A>::char_type const* lhs
, basic_simple_string<C, T, A> const& rhs
)
#else /* ? STLSOFT_CF_TEMPLATE_OUTOFCLASSFN_QUALIFIED_TYPE_SUPPORT */
operator ==(
C const* lhs
, basic_simple_string<C, T, A> const& rhs
)
#endif /* STLSOFT_CF_TEMPLATE_OUTOFCLASSFN_QUALIFIED_TYPE_SUPPORT */
{
return 0 == rhs.compare(lhs);
}
// operator !=
template <
ss_typename_param_k C
, ss_typename_param_k T
, ss_typename_param_k A
>