00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00048 #ifndef STLSOFT_INCL_STLSOFT_STRING_HPP_SIMPLE_STRING
00049 #define STLSOFT_INCL_STLSOFT_STRING_HPP_SIMPLE_STRING
00050
00051 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
00052 # define STLSOFT_VER_STLSOFT_STRING_HPP_SIMPLE_STRING_MAJOR 4
00053 # define STLSOFT_VER_STLSOFT_STRING_HPP_SIMPLE_STRING_MINOR 1
00054 # define STLSOFT_VER_STLSOFT_STRING_HPP_SIMPLE_STRING_REVISION 4
00055 # define STLSOFT_VER_STLSOFT_STRING_HPP_SIMPLE_STRING_EDIT 246
00056 #endif
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072 #ifndef STLSOFT_INCL_STLSOFT_H_STLSOFT
00073 # include <stlsoft/stlsoft.h>
00074 #endif
00075 #ifndef STLSOFT_INCL_STLSOFT_STRING_HPP_CHAR_TRAITS
00076 # include <stlsoft/string/char_traits.hpp>
00077 #endif
00078 #ifndef STLSOFT_INCL_STLSOFT_STRING_HPP_STRING_TRAITS_FWD
00079 # include <stlsoft/string/string_traits_fwd.hpp>
00080 #endif
00081 #ifndef STLSOFT_INCL_STLSOFT_COLLECTIONS_UTIL_HPP_COLLECTIONS
00082 # include <stlsoft/collections/util/collections.hpp>
00083 #endif
00084 #ifndef STLSOFT_INCL_STLSOFT_MEMORY_HPP_ALLOCATOR_BASE
00085 # include <stlsoft/memory/allocator_base.hpp>
00086 #endif
00087 #ifndef STLSOFT_INCL_STLSOFT_MEMORY_HPP_ALLOCATOR_SELECTOR
00088 # include <stlsoft/memory/allocator_selector.hpp>
00089 #endif
00090 #ifndef STLSOFT_INCL_STLSOFT_HPP_MEMORY_AUTO_BUFFER
00091 # include <stlsoft/memory/auto_buffer.hpp>
00092 #endif
00093 #ifndef STLSOFT_INCL_STLSOFT_UTIL_HPP_STD_SWAP
00094 # include <stlsoft/util/std_swap.hpp>
00095 #endif
00096 #ifndef STLSOFT_INCL_STLSOFT_UTIL_STD_HPP_ITERATOR_GENERATORS
00097 # include <stlsoft/util/std/iterator_generators.hpp>
00098 #endif
00099 #ifndef STLSOFT_INCL_STLSOFT_ALGORITHMS_HPP_BOUNDED
00100 # include <stlsoft/algorithms/bounded.hpp>
00101 #endif
00102 #ifndef STLSOFT_INCL_STLSOFT_UTIL_HPP_MINMAX
00103 # include <stlsoft/util/minmax.hpp>
00104 #endif
00105 #ifndef STLSOFT_INCL_STLSOFT_CONVERSION_HPP_SAP_CAST
00106 # include <stlsoft/conversion/sap_cast.hpp>
00107 #endif
00108 #ifndef STLSOFT_INCL_STLSOFT_UTIL_STD_HPP_ITERATOR_HELPER
00109 # include <stlsoft/util/std/iterator_helper.hpp>
00110 #endif
00111
00112 #if defined(__BORLANDC__) && \
00113 __BORLANDC__ > 0x0580 && \
00114 defined(_DEBUG)
00115 # include <stdio.h>
00116 #endif
00117
00118
00119 #ifdef STLSOFT_UNITTEST
00120 # include <stdio.h>
00121 # include <string>
00122 #endif
00123 #ifdef STLSOFT_CF_EXCEPTION_SUPPORT
00124 # include <stdexcept>
00125 #endif
00126
00127
00128
00129
00130
00131 #if defined(STLSOFT_COMPILER_IS_MSVC) && \
00132 _MSC_VER < 1200
00133 # define STLSOFT_SIMPLE_STRING_ITERATOR_METHODS_INLINE
00134 #endif
00135
00136
00137
00138
00139
00140 #ifndef _STLSOFT_NO_NAMESPACE
00141 namespace stlsoft
00142 {
00143 #endif
00144
00145
00146
00147
00148
00157 template< ss_typename_param_k C
00158 #ifdef STLSOFT_CF_TEMPLATE_CLASS_DEFAULT_CLASS_ARGUMENT_SUPPORT
00159 , ss_typename_param_k T = stlsoft_char_traits<C>
00160 , ss_typename_param_k A = ss_typename_type_def_k allocator_selector<C>::allocator_type
00161 #else
00162 , ss_typename_param_k T
00163 , ss_typename_param_k A
00164 #endif
00165 >
00166
00167 class basic_simple_string
00168 : public stl_collection_tag
00169 {
00172 public:
00174 typedef C value_type;
00176 typedef T traits_type;
00178 typedef A allocator_type;
00180 typedef basic_simple_string<C, T, A> class_type;
00182 typedef value_type char_type;
00184 typedef value_type* pointer;
00186 typedef value_type const* const_pointer;
00188 typedef value_type& reference;
00190 typedef value_type const& const_reference;
00192 typedef ss_size_t size_type;
00194 typedef ss_ptrdiff_t difference_type;
00195
00197 typedef
00198 #if !defined(STLSOFT_COMPILER_IS_BORLAND)
00199 ss_typename_type_k
00200 #endif
00201 pointer_iterator < value_type
00202 , pointer
00203 , reference
00204 >::type iterator;
00206 typedef
00207 #if !defined(STLSOFT_COMPILER_IS_BORLAND)
00208 ss_typename_type_k
00209 #endif
00210 pointer_iterator < value_type const
00211 , const_pointer
00212 , const_reference
00213 >::type const_iterator;
00214
00215 #if defined(STLSOFT_LF_BIDIRECTIONAL_ITERATOR_SUPPORT)
00217 typedef ss_typename_type_k reverse_iterator_generator < iterator
00218 , value_type
00219 , reference
00220 , pointer
00221 , difference_type
00222 >::type reverse_iterator;
00223
00225 typedef ss_typename_type_k const_reverse_iterator_generator < const_iterator
00226 , value_type
00227 , const_reference
00228 , const_pointer
00229 , difference_type
00230 >::type const_reverse_iterator;
00231 #endif
00232
00233 private:
00238 #ifdef STLSOFT_LF_ALLOCATOR_REBIND_SUPPORT
00239 typedef ss_typename_type_k A::ss_template_qual_k rebind<ss_byte_t>::other byte_ator_type;
00240 #else
00241 typedef ss_typename_type_k allocator_selector<ss_byte_t>::allocator_type byte_ator_type;
00242 #endif
00244
00247 public:
00249 basic_simple_string();
00251 basic_simple_string(class_type const& rhs);
00253 basic_simple_string(class_type const& s, size_type pos);
00255 basic_simple_string(class_type const& s, size_type pos, size_type cch);
00257 basic_simple_string(char_type const* s); // Not, not explicit. Sigh
00259 basic_simple_string(char_type const* s, size_type cch);
00261 basic_simple_string(size_type cch, char_type ch);
00263 #if !defined(STLSOFT_CF_MEMBER_TEMPLATE_RANGE_METHOD_SUPPORT)
00264 basic_simple_string(char_type const* first, char_type const* last);
00265 #else
00266 template <ss_typename_param_k II>
00267 basic_simple_string(II first, II last)
00268 : m_buffer(NULL)
00269 {
00270 assign(first, last);
00271 }
00272 #endif
00274 ~basic_simple_string() stlsoft_throw_0();
00276
00279 public:
00281 class_type& assign(char_type const* s);
00283 class_type& assign(char_type const* s, size_type cch);
00285 class_type& assign(class_type const& str, size_type pos, size_type cch);
00287 class_type& assign(class_type const& str);
00289 class_type& assign(size_type cch, char_type ch);
00291 #if !defined(STLSOFT_CF_MEMBER_TEMPLATE_RANGE_METHOD_SUPPORT)
00292 class_type& assign(const_iterator first, const_iterator last);
00293 #else
00294 template <ss_typename_param_k II>
00295 class_type& assign(II first, II last)
00296 {
00297 # if ( defined(STLSOFT_COMPILER_IS_GCC) && \
00298 __GNUC__ < 3) || \
00299 ( defined(STLSOFT_COMPILER_IS_BORLAND) && \
00300 defined(STLSOFT_CF_STD_LIBRARY_IS_DINKUMWARE_BORLAND))
00301 typedef ss_typename_type_k std::iterator_traits<II> traits_t;
00302
00303 return assign_(first, last, traits_t::iterator_category());
00304 # elif defined(STLSOFT_COMPILER_IS_MWERKS) || \
00305 defined(STLSOFT_COMPILER_IS_DMC)
00306 return assign_(first, last, stlsoft_iterator_query_category_ptr(II, first));
00307 # else
00308 return assign_(first, last, stlsoft_iterator_query_category(II, first));
00309 # endif
00310 }
00311 #endif
00312
00314 class_type const& operator =(class_type const& rhs);
00316 class_type const& operator =(char_type const* s);
00318 class_type const& operator =(char_type ch);
00320
00323 public:
00325 class_type& append(char_type const* s);
00327 class_type& append(char_type const* s, size_type cch);
00329 class_type& append(class_type const& str, size_type pos, size_type cch);
00331 class_type& append(class_type const& str);
00333 class_type& append(size_type cch, char_type ch);
00335 #if !defined(STLSOFT_CF_MEMBER_TEMPLATE_RANGE_METHOD_SUPPORT)
00336 class_type& append(const_iterator first, const_iterator last);
00337 #else
00338 template <ss_typename_param_k II>
00339 class_type& append(II first, II last)
00340 {
00341 # if ( defined(STLSOFT_COMPILER_IS_GCC) && \
00342 __GNUC__ < 3) || \
00343 ( defined(STLSOFT_COMPILER_IS_BORLAND) && \
00344 defined(STLSOFT_CF_STD_LIBRARY_IS_DINKUMWARE_BORLAND))
00345 typedef ss_typename_type_k std::iterator_traits<II> traits_t;
00346
00347 return append_(first, last, traits_t::iterator_category());
00348 # elif defined(STLSOFT_COMPILER_IS_MWERKS) || \
00349 defined(STLSOFT_COMPILER_IS_DMC)
00350 return append_(first, last, stlsoft_iterator_query_category_ptr(II, first));
00351 # else
00352 return append_(first, last, stlsoft_iterator_query_category(II, first));
00353 # endif
00354 }
00355 #endif
00356
00358 class_type& operator +=(char_type ch);
00360 class_type& operator +=(char_type const* s);
00362 class_type& operator +=(class_type const& rhs);
00363
00365 void push_back(char_type ch);
00367
00370 public:
00372 void reserve(size_type cch);
00374 void swap(class_type& other);
00375
00380 void resize(size_type cch, value_type ch = value_type());
00381
00383 void clear();
00385
00388 public:
00390 size_type size() const;
00392 size_type max_size() const;
00394 size_type length() const;
00396 size_type capacity() const;
00398 ss_bool_t empty() const;
00400
00403 public:
00404 #if 0
00406 ss_sint_t equal(size_type pos, size_type cch, value_type const* s, size_type cchRhs) const;
00408 ss_sint_t equal(size_type pos, size_type cch, value_type const* s) const;
00410 ss_sint_t equal(value_type const* s) const;
00412 ss_sint_t equal(size_type pos, size_type cch, class_type const& rhs, size_type posRhs, size_type cchRhs) const;
00414 ss_sint_t equal(size_type pos, size_type cch, class_type const& rhs) const;
00416 ss_sint_t equal(class_type const& rhs) const;
00417 #endif
00418
00420 ss_sint_t compare(size_type pos, size_type cch, value_type const* s, size_type cchRhs) const;
00422 ss_sint_t compare(size_type pos, size_type cch, value_type const* s) const;
00424 ss_sint_t compare(value_type const* s) const;
00426 ss_sint_t compare(size_type pos, size_type cch, class_type const& rhs, size_type posRhs, size_type cchRhs) const;
00428 ss_sint_t compare(size_type pos, size_type cch, class_type const& rhs) const;
00430 ss_sint_t compare(class_type const& rhs) const;
00432
00435 public:
00437 reference operator [](size_type index);
00439 const_reference operator [](size_type index) const;
00440
00441 #ifdef STLSOFT_CF_EXCEPTION_SUPPORT
00445 reference at(size_type index);
00449 const_reference at(size_type index) const;
00450
00452 class_type substr(size_type pos, size_type cch) const;
00453 class_type substr(size_type pos) const;
00454 class_type substr() const;
00455 #endif
00456
00458 value_type const* c_str() const;
00460 value_type const* data() const;
00461
00465 reference front();
00469 reference back();
00473 const_reference front() const;
00477 const_reference back() const;
00478
00480 size_type copy(value_type* dest, size_type cch, size_type pos = 0) const;
00482
00485 public:
00489 #ifdef STLSOFT_SIMPLE_STRING_ITERATOR_METHODS_INLINE
00490 const_iterator begin() const
00491 {
00492 return const_cast<class_type*>(this)->begin_();
00493 }
00494 #else
00495 const_iterator begin() const;
00496 #endif
00500 #ifdef STLSOFT_SIMPLE_STRING_ITERATOR_METHODS_INLINE
00501 const_iterator end() const
00502 {
00503 return const_cast<class_type*>(this)->end_();
00504 }
00505 #else
00506 const_iterator end() const;
00507 #endif
00511 iterator begin();
00515 iterator end();
00516
00517 #if defined(STLSOFT_LF_BIDIRECTIONAL_ITERATOR_SUPPORT)
00521 const_reverse_iterator rbegin() const;
00525 const_reverse_iterator rend() const;
00529 reverse_iterator rbegin();
00533 reverse_iterator rend();
00534 #endif
00536
00539 private:
00540 enum { alloc_quantum = 31 };
00541
00542 struct string_buffer
00543 {
00544 size_type capacity;
00545 size_type length;
00546 char_type contents[1];
00547 };
00548
00549 typedef auto_buffer_old<char_type
00550 , allocator_type
00551 > buffer_type_;
00552
00553 #ifdef STLSOFT_SIMPLE_STRING_NO_PTR_ADJUST
00554 typedef string_buffer* member_pointer;
00555 typedef string_buffer const* member_const_pointer;
00556 #else
00557 typedef char_type* member_pointer;
00558 typedef char_type const* member_const_pointer;
00559 #endif
00560
00561
00562 static char_type* char_pointer_from_member_pointer_(member_pointer );
00563
00564
00565 static string_buffer* string_buffer_from_member_pointer_(member_pointer );
00566 static string_buffer const* string_buffer_from_member_pointer_(member_const_pointer );
00567
00568
00569 static member_pointer member_pointer_from_string_buffer_(string_buffer*);
00570
00571
00572 static member_pointer alloc_buffer_(char_type const* s, size_type capacity, size_type length);
00573 static member_pointer alloc_buffer_(char_type const* s, size_type cch);
00574 static member_pointer alloc_buffer_(char_type const* s);
00575
00576
00577 static member_pointer copy_buffer_(member_pointer );
00578
00579
00580 static void destroy_buffer_(string_buffer*);
00581 static void destroy_buffer_(char_type*);
00582
00583
00584 pointer begin_();
00585 pointer end_();
00586
00587
00588 ss_bool_t is_valid() const;
00589
00590
00591 static char_type const* empty_string_();
00592
00593
00594 static ss_sint_t compare_(char_type const* lhs, size_type lhs_len, char_type const* rhs, size_type rhs_len);
00595
00596
00597 #if defined(STLSOFT_CF_MEMBER_TEMPLATE_RANGE_METHOD_SUPPORT)
00598 template <ss_typename_param_k II>
00599 # if defined(STLSOFT_COMPILER_IS_MWERKS) || \
00600 defined(STLSOFT_COMPILER_IS_DMC)
00601
00602 class_type& assign_(II first, II last, stlsoft_ns_qual_std(input_iterator_tag) const*)
00603 # else
00604 class_type& assign_(II first, II last, stlsoft_ns_qual_std(input_iterator_tag))
00605 # endif
00606 {
00607 stlsoft_ns_qual_std(copy)(first, last, stlsoft_ns_qual_std(back_inserter)(*this));
00608
00609 STLSOFT_ASSERT(is_valid());
00610 return *this;
00611 }
00612 template <ss_typename_param_k II>
00613 # if defined(STLSOFT_COMPILER_IS_MWERKS) || \
00614 defined(STLSOFT_COMPILER_IS_DMC)
00615
00616 class_type& assign_(II first, II last, stlsoft_ns_qual_std(forward_iterator_tag) const*)
00617 # else
00618 class_type& assign_(II first, II last, stlsoft_ns_qual_std(forward_iterator_tag))
00619 # endif
00620 {
00621 const ss_size_t n = static_cast<ss_size_t>(stlsoft_ns_qual_std(distance)(first, last));
00622 buffer_type_ buffer(n);
00623
00624 copy_n(first, buffer.size(), &buffer[0]);
00625 assign(buffer.data(), buffer.size());
00626
00627 STLSOFT_ASSERT(is_valid());
00628
00629 return *this;
00630 }
00631 #endif
00632
00633
00634 #if defined(STLSOFT_CF_MEMBER_TEMPLATE_RANGE_METHOD_SUPPORT)
00635 template <ss_typename_param_k II>
00636 # if defined(STLSOFT_COMPILER_IS_MWERKS) || \
00637 defined(STLSOFT_COMPILER_IS_DMC)
00638 class_type& append_(II first, II last, stlsoft_ns_qual_std(input_iterator_tag) const*)
00639 # else
00640 class_type& append_(II first, II last, stlsoft_ns_qual_std(input_iterator_tag))
00641 # endif
00642 {
00643 stlsoft_ns_qual_std(copy)(first, last, stlsoft_ns_qual_std(back_inserter)(*this));
00644
00645 STLSOFT_ASSERT(is_valid());
00646 return *this;
00647 }
00648 template <ss_typename_param_k II>
00649 # if defined(STLSOFT_COMPILER_IS_MWERKS) || \
00650 defined(STLSOFT_COMPILER_IS_DMC)
00651 class_type& append_(II first, II last, stlsoft_ns_qual_std(forward_iterator_tag) const*)
00652 # else
00653 class_type& append_(II first, II last, stlsoft_ns_qual_std(forward_iterator_tag))
00654 # endif
00655 {
00656 buffer_type_ buffer(static_cast<ss_size_t>(stlsoft_ns_qual_std(distance)(first, last)));
00657
00658 std_copy(first, last, &buffer[0]);
00659 append(buffer.data(), buffer.size());
00660
00661 STLSOFT_ASSERT(is_valid());
00662 return *this;
00663 }
00664 #endif
00666
00669 private:
00670 member_pointer m_buffer;
00672 };
00673
00674
00675
00676
00677
00678 #ifdef STLSOFT_CF_TEMPLATE_CLASS_DEFAULT_CLASS_ARGUMENT_SUPPORT
00679 typedef basic_simple_string<ss_char_a_t> simple_string;
00680 typedef basic_simple_string<ss_char_w_t> simple_wstring;
00681 #else
00682 typedef basic_simple_string<ss_char_a_t
00683 , stlsoft_char_traits<ss_char_a_t>
00684 , allocator_selector<ss_char_a_t>::allocator_type
00685 > simple_string;
00686 typedef basic_simple_string<ss_char_w_t
00687 , stlsoft_char_traits<ss_char_w_t>
00688 , allocator_selector<ss_char_w_t>::allocator_type
00689 > simple_wstring;
00690 #endif
00691
00692
00693
00694
00695
00698 # ifdef STLSOFT_CF_TEMPLATE_PARTIAL_SPECIALISATION_SUPPORT
00699 template <ss_typename_param_k C>
00700 struct string_traits<basic_simple_string<C> >
00701 {
00702
00703
00704 typedef basic_simple_string<C> string_type_;
00705 typedef ss_typename_type_k string_type_::value_type char_type;
00706 typedef ss_typename_type_k string_type_::size_type size_type;
00707 typedef char_type const const_char_type;
00708 typedef string_type_ string_type;
00709 typedef string_type_ value_type;
00710 typedef ss_typename_type_k string_type::pointer pointer;
00711 typedef ss_typename_type_k string_type::const_pointer const_pointer;
00712 typedef ss_typename_type_k string_type::iterator iterator;
00713 typedef ss_typename_type_k string_type::const_iterator const_iterator;
00714 #if defined(STLSOFT_LF_BIDIRECTIONAL_ITERATOR_SUPPORT)
00715 typedef ss_typename_type_k string_type::reverse_iterator reverse_iterator;
00716 typedef ss_typename_type_k string_type::const_reverse_iterator const_reverse_iterator;
00717 #endif
00718 enum
00719 {
00720 is_pointer = false
00721 , is_pointer_to_const = false
00722 , char_type_size = sizeof(char_type)
00723 };
00724
00725 static string_type empty_string()
00726 {
00727 return string_type();
00728 }
00729 static string_type construct(string_type const& src, size_type pos, size_type len)
00730 {
00731 return string_type(src, pos, len);
00732 }
00733 # ifdef STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT
00734 template <ss_typename_param_k I>
00735 static string_type &assign_inplace(string_type &str, I first, I last)
00736 # else
00737 static string_type &assign_inplace(string_type &str, const_iterator first, const_iterator last)
00738 # endif
00739 {
00740
00741 return str.assign(first, last);
00742 }
00743 };
00744 # else
00745 STLSOFT_TEMPLATE_SPECIALISATION
00746 struct string_traits<simple_string>
00747 {
00748 typedef basic_simple_string<ss_char_a_t> value_type;
00749 typedef value_type::value_type char_type;
00750 typedef value_type::size_type size_type;
00751 typedef char_type const const_char_type;
00752 typedef value_type string_type;
00753 typedef string_type::pointer pointer;
00754 typedef string_type::const_pointer const_pointer;
00755 typedef string_type::iterator iterator;
00756 typedef string_type::const_iterator const_iterator;
00757 #if defined(STLSOFT_LF_BIDIRECTIONAL_ITERATOR_SUPPORT)
00758 typedef string_type::reverse_iterator reverse_iterator;
00759 typedef string_type::const_reverse_iterator const_reverse_iterator;
00760 #endif
00761 enum
00762 {
00763 is_pointer = false
00764 , is_pointer_to_const = false
00765 , char_type_size = sizeof(char_type)
00766 };
00767
00768 static string_type empty_string()
00769 {
00770 return string_type();
00771 }
00772 static string_type construct(string_type const& src, size_type pos, size_type len)
00773 {
00774 return string_type(src, pos, len);
00775 }
00776 # ifdef STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT
00777 template <ss_typename_param_k I>
00778 static string_type &assign_inplace(string_type &str, I first, I last)
00779 # else
00780 static string_type &assign_inplace(string_type &str, const_iterator first, const_iterator last)
00781 # endif
00782 {
00783
00784 return str.assign(first, last);
00785 }
00786 };
00787
00788 STLSOFT_TEMPLATE_SPECIALISATION
00789 struct string_traits<simple_wstring>
00790 {
00791 typedef basic_simple_string<ss_char_w_t> value_type;
00792 typedef value_type::value_type char_type;
00793 typedef value_type::size_type size_type;
00794 typedef char_type const const_char_type;
00795 typedef value_type string_type;
00796 typedef string_type::pointer pointer;
00797 typedef string_type::const_pointer const_pointer;
00798 typedef string_type::iterator iterator;
00799 typedef string_type::const_iterator const_iterator;
00800 #if defined(STLSOFT_LF_BIDIRECTIONAL_ITERATOR_SUPPORT)
00801 typedef string_type::reverse_iterator reverse_iterator;
00802 typedef string_type::const_reverse_iterator const_reverse_iterator;
00803 #endif
00804 enum
00805 {
00806 is_pointer = false
00807 , is_pointer_to_const = false
00808 , char_type_size = sizeof(char_type)
00809 };
00810
00811 static string_type empty_string()
00812 {
00813 return string_type();
00814 }
00815 static string_type construct(string_type const& src, size_type pos, size_type len)
00816 {
00817 return string_type(src, pos, len);
00818 }
00819 # ifdef STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT
00820 template <ss_typename_param_k I>
00821 static string_type &assign_inplace(string_type &str, I first, I last)
00822 # else
00823 static string_type &assign_inplace(string_type &str, const_iterator first, const_iterator last)
00824 # endif
00825 {
00826
00827 return str.assign(first, last);
00828 }
00829 };
00830 # endif
00831
00832
00833
00834
00835
00836 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
00837
00838
00839
00840 template< ss_typename_param_k C
00841 , ss_typename_param_k T
00842 , ss_typename_param_k A
00843 >
00844 inline ss_bool_t operator ==(basic_simple_string<C, T, A> const& lhs, basic_simple_string<C, T, A> const& rhs)
00845 {
00846 return 0 == lhs.compare(rhs);
00847 }
00848
00849 template< ss_typename_param_k C
00850 , ss_typename_param_k T
00851 , ss_typename_param_k A
00852 >
00853 #ifdef STLSOFT_CF_TEMPLATE_OUTOFCLASSFN_QUALIFIED_TYPE_SUPPORT
00854 inline ss_bool_t operator ==(basic_simple_string<C, T, A> const& lhs, ss_typename_type_k basic_simple_string<C, T, A>::char_type const* rhs)
00855 #else
00856 inline ss_bool_t operator ==(basic_simple_string<C, T, A> const& lhs, C const* rhs)
00857 #endif
00858 {
00859 return 0 == lhs.compare(rhs);
00860 }
00861
00862 template< ss_typename_param_k C
00863 , ss_typename_param_k T
00864 , ss_typename_param_k A
00865 >
00866 #ifdef STLSOFT_CF_TEMPLATE_OUTOFCLASSFN_QUALIFIED_TYPE_SUPPORT
00867 inline ss_bool_t operator ==(ss_typename_type_k basic_simple_string<C, T, A>::char_type const* lhs, basic_simple_string<C, T, A> const& rhs)
00868 #else
00869 inline ss_bool_t operator ==(C *lhs, basic_simple_string<C, T, A> const& rhs)
00870 #endif
00871 {
00872 return 0 == rhs.compare(lhs);
00873 }
00874
00875
00876
00877 template< ss_typename_param_k C
00878 , ss_typename_param_k T
00879 , ss_typename_param_k A
00880 >
00881 inline ss_bool_t operator !=(basic_simple_string<C, T, A> const& lhs, basic_simple_string<C, T, A> const& rhs)
00882 {
00883 return 0 != lhs.compare(rhs);
00884 }
00885 template< ss_typename_param_k C
00886 , ss_typename_param_k T
00887 , ss_typename_param_k A
00888 >
00889 #ifdef STLSOFT_CF_TEMPLATE_OUTOFCLASSFN_QUALIFIED_TYPE_SUPPORT
00890 inline ss_bool_t operator !=(basic_simple_string<C, T, A> const& lhs, ss_typename_type_k basic_simple_string<C, T, A>::char_type const* rhs)
00891 #else
00892 inline ss_bool_t operator !=(basic_simple_string<C, T, A> const& lhs, C const* rhs)
00893 #endif
00894 {
00895 return 0 != lhs.compare(rhs);
00896 }
00897 template< ss_typename_param_k C
00898 , ss_typename_param_k T
00899 , ss_typename_param_k A
00900 >
00901 #ifdef STLSOFT_CF_TEMPLATE_OUTOFCLASSFN_QUALIFIED_TYPE_SUPPORT
00902 inline ss_bool_t operator !=(ss_typename_type_k basic_simple_string<C, T, A>::char_type const* lhs, basic_simple_string<C, T, A> const& rhs)
00903 #else
00904 inline ss_bool_t operator !=(C const* lhs, basic_simple_string<C, T, A> const& rhs)
00905 #endif
00906 {
00907 return 0 != rhs.compare(lhs);
00908 }
00909
00910
00911
00912 template< ss_typename_param_k C
00913 , ss_typename_param_k T
00914 , ss_typename_param_k A
00915 >
00916 inline ss_bool_t operator <(basic_simple_string<C, T, A> const& lhs, basic_simple_string<C, T, A> const& rhs)
00917 {
00918 return lhs.compare(rhs) < 0;
00919 }
00920
00921 template< ss_typename_param_k C
00922 , ss_typename_param_k T
00923 , ss_typename_param_k A
00924 >
00925 #ifdef STLSOFT_CF_TEMPLATE_OUTOFCLASSFN_QUALIFIED_TYPE_SUPPORT
00926 inline ss_bool_t operator <(basic_simple_string<C, T, A> const& lhs, ss_typename_type_k basic_simple_string<C, T, A>::char_type const* rhs)
00927 #else
00928 inline ss_bool_t operator <(basic_simple_string<C, T, A> const& lhs, C const* rhs)
00929 #endif
00930 {
00931 return lhs.compare(rhs) < 0;
00932 }
00933
00934 template< ss_typename_param_k C
00935 , ss_typename_param_k T
00936 , ss_typename_param_k A
00937 >
00938 #ifdef STLSOFT_CF_TEMPLATE_OUTOFCLASSFN_QUALIFIED_TYPE_SUPPORT
00939 inline ss_bool_t operator <(ss_typename_type_k basic_simple_string<C, T, A>::char_type const* lhs, basic_simple_string<C, T, A> const& rhs)
00940 #else
00941 inline ss_bool_t operator <(C const* lhs, basic_simple_string<C, T, A> const& rhs)
00942 #endif
00943 {
00944 return rhs.compare(lhs) > 0;
00945 }
00946
00947
00948
00949 template< ss_typename_param_k C
00950 , ss_typename_param_k T
00951 , ss_typename_param_k A
00952 >
00953 inline ss_bool_t operator <=(basic_simple_string<C, T, A> const& lhs, basic_simple_string<C, T, A> const& rhs)
00954 {
00955 return lhs.compare(rhs) <= 0;
00956 }
00957 template< ss_typename_param_k C
00958 , ss_typename_param_k T
00959 , ss_typename_param_k A
00960 >
00961 #ifdef STLSOFT_CF_TEMPLATE_OUTOFCLASSFN_QUALIFIED_TYPE_SUPPORT
00962 inline ss_bool_t operator <=(basic_simple_string<C, T, A> const& lhs, ss_typename_type_k basic_simple_string<C, T, A>::char_type const* rhs)
00963 #else
00964 inline ss_bool_t operator <=(basic_simple_string<C, T, A> const& lhs, C const* rhs)
00965 #endif
00966 {
00967 return lhs.compare(rhs) <= 0;
00968 }
00969 template< ss_typename_param_k C
00970 , ss_typename_param_k T
00971 , ss_typename_param_k A
00972 >
00973 #ifdef STLSOFT_CF_TEMPLATE_OUTOFCLASSFN_QUALIFIED_TYPE_SUPPORT
00974 inline ss_bool_t operator <=(ss_typename_type_k basic_simple_string<C, T, A>::char_type const* lhs, basic_simple_string<C, T, A> const& rhs)
00975 #else
00976 inline ss_bool_t operator <=(C const* lhs, basic_simple_string<C, T, A> const& rhs)
00977 #endif
00978 {
00979 return rhs.compare(lhs) >= 0;
00980 }
00981
00982
00983
00984 template< ss_typename_param_k C
00985 , ss_typename_param_k T
00986 , ss_typename_param_k A
00987 >
00988 inline ss_bool_t operator >(basic_simple_string<C, T, A> const& lhs, basic_simple_string<C, T, A> const& rhs)
00989 {
00990 return lhs.compare(rhs) > 0;
00991 }
00992 template< ss_typename_param_k C
00993 , ss_typename_param_k T
00994 , ss_typename_param_k A
00995 >
00996 #ifdef STLSOFT_CF_TEMPLATE_OUTOFCLASSFN_QUALIFIED_TYPE_SUPPORT
00997 inline ss_bool_t operator >(basic_simple_string<C, T, A> const& lhs, ss_typename_type_k basic_simple_string<C, T, A>::char_type const* rhs)
00998 #else
00999 inline ss_bool_t operator >(basic_simple_string<C, T, A> const& lhs, C const* rhs)
01000 #endif
01001 {
01002 return lhs.compare(rhs) > 0;
01003 }
01004 template< ss_typename_param_k C
01005 , ss_typename_param_k T
01006 , ss_typename_param_k A
01007 >
01008 #ifdef STLSOFT_CF_TEMPLATE_OUTOFCLASSFN_QUALIFIED_TYPE_SUPPORT
01009 inline ss_bool_t operator >(ss_typename_type_k basic_simple_string<C, T, A>::char_type const* lhs, basic_simple_string<C, T, A> const& rhs)
01010 #else
01011 inline ss_bool_t operator >(C const* lhs, basic_simple_string<C, T, A> const& rhs)
01012 #endif
01013 {
01014 return rhs.compare(lhs) < 0;
01015 }
01016
01017
01018
01019 template< ss_typename_param_k C
01020 , ss_typename_param_k T
01021 , ss_typename_param_k A
01022 >
01023 inline ss_bool_t operator >=(basic_simple_string<C, T, A> const& lhs, basic_simple_string<C, T, A> const& rhs)
01024 {
01025 return lhs.compare(rhs) >= 0;
01026 }
01027 template< ss_typename_param_k C
01028 , ss_typename_param_k T
01029 , ss_typename_param_k A
01030 >
01031 #ifdef STLSOFT_CF_TEMPLATE_OUTOFCLASSFN_QUALIFIED_TYPE_SUPPORT
01032 inline ss_bool_t operator >=(basic_simple_string<C, T, A> const& lhs, ss_typename_type_k basic_simple_string<C, T, A>::char_type const* rhs)
01033 #else
01034 inline ss_bool_t operator >=(basic_simple_string<C, T, A> const& lhs, C const* rhs)
01035 #endif
01036 {
01037 return lhs.compare(rhs) >= 0;
01038 }
01039 template< ss_typename_param_k C
01040 , ss_typename_param_k T
01041 , ss_typename_param_k A
01042 >
01043 #ifdef STLSOFT_CF_TEMPLATE_OUTOFCLASSFN_QUALIFIED_TYPE_SUPPORT
01044 inline ss_bool_t operator >=(ss_typename_type_k basic_simple_string<C, T, A>::char_type const* lhs, basic_simple_string<C, T, A> const& rhs)
01045 #else
01046 inline ss_bool_t operator >=(C const* lhs, basic_simple_string<C, T, A> const& rhs)
01047 #endif
01048 {
01049 return rhs.compare(lhs) <= 0;
01050 }
01051
01052
01053
01054 template< ss_typename_param_k C
01055 , ss_typename_param_k T
01056 , ss_typename_param_k A
01057 >
01058 inline basic_simple_string<C, T, A> operator +(basic_simple_string<C, T, A> const& lhs, basic_simple_string<C, T, A> const& rhs)
01059 {
01060 return basic_simple_string<C, T, A>(lhs) += rhs;
01061 }
01062 template< ss_typename_param_k C
01063 , ss_typename_param_k T
01064 , ss_typename_param_k A
01065 >
01066 #ifdef STLSOFT_CF_TEMPLATE_OUTOFCLASSFN_QUALIFIED_TYPE_SUPPORT
01067 inline basic_simple_string<C, T, A> operator +(basic_simple_string<C, T, A> const& lhs, ss_typename_type_k basic_simple_string<C, T, A>::char_type const* rhs)
01068 #else
01069 inline basic_simple_string<C, T, A> operator +(basic_simple_string<C, T, A> const& lhs, C const* rhs)
01070 #endif
01071 {
01072 return basic_simple_string<C, T, A>(lhs) += rhs;
01073 }
01074 template< ss_typename_param_k C
01075 , ss_typename_param_k T
01076 , ss_typename_param_k A
01077 >
01078 #ifdef STLSOFT_CF_TEMPLATE_OUTOFCLASSFN_QUALIFIED_TYPE_SUPPORT
01079 inline basic_simple_string<C, T, A> operator +(ss_typename_type_k basic_simple_string<C, T, A>::char_type const* lhs, basic_simple_string<C, T, A> const& rhs)
01080 #else
01081 inline basic_simple_string<C, T, A> operator +(C const* lhs, basic_simple_string<C, T, A> const& rhs)
01082 #endif
01083 {
01084 return basic_simple_string<C, T, A>(lhs) += rhs;
01085 }
01086 template< ss_typename_param_k C
01087 , ss_typename_param_k T
01088 , ss_typename_param_k A
01089 >
01090 #ifdef STLSOFT_CF_TEMPLATE_OUTOFCLASSFN_QUALIFIED_TYPE_SUPPORT
01091 inline basic_simple_string<C, T, A> operator +(basic_simple_string<C, T, A> const& lhs, ss_typename_type_k basic_simple_string<C, T, A>::char_type rhs)
01092 #else
01093 inline basic_simple_string<C, T, A> operator +(basic_simple_string<C, T, A> const& lhs, C rhs)
01094 #endif
01095 {
01096 return basic_simple_string<C, T, A>(lhs) += rhs;
01097 }
01098 template< ss_typename_param_k C
01099 , ss_typename_param_k T
01100 , ss_typename_param_k A
01101 >
01102 #ifdef STLSOFT_CF_TEMPLATE_OUTOFCLASSFN_QUALIFIED_TYPE_SUPPORT
01103 inline basic_simple_string<C, T, A> operator +(ss_typename_type_k basic_simple_string<C, T, A>::char_type lhs, basic_simple_string<C, T, A> const& rhs)
01104 #else
01105 inline basic_simple_string<C, T, A> operator +(C lhs, basic_simple_string<C, T, A> const& rhs)
01106 #endif
01107 {
01108 return basic_simple_string<C, T, A>(1, lhs) += rhs;
01109 }
01110
01111 #endif
01112
01113
01114
01115
01116
01117
01118
01123 template< ss_typename_param_k C
01124 , ss_typename_param_k T
01125 , ss_typename_param_k A
01126 >
01127 inline C const* c_str_ptr_null(basic_simple_string<C, T, A> const& s)
01128 {
01129 return (0 == s.length()) ? NULL : s.c_str();
01130 }
01135 template<ss_typename_param_k T, ss_typename_param_k A>
01136 inline ss_char_a_t const* c_str_ptr_null_a(basic_simple_string<ss_char_a_t, T, A> const& s)
01137 {
01138 return c_str_ptr_null(s);
01139 }
01144 template<ss_typename_param_k T, ss_typename_param_k A>
01145 inline ss_char_w_t const* c_str_ptr_null_w(basic_simple_string<ss_char_w_t, T, A> const& s)
01146 {
01147 return c_str_ptr_null(s);
01148 }
01149
01150
01151
01156 template< ss_typename_param_k C
01157 , ss_typename_param_k T
01158 , ss_typename_param_k A
01159 >
01160 inline C const* c_str_ptr(basic_simple_string<C, T, A> const& s)
01161 {
01162 return s.c_str();
01163 }
01168 template<ss_typename_param_k T, ss_typename_param_k A>
01169 inline ss_char_a_t const* c_str_ptr_a(basic_simple_string<ss_char_a_t, T, A> const& s)
01170 {
01171 return c_str_ptr(s);
01172 }
01177 template<ss_typename_param_k T, ss_typename_param_k A>
01178 inline ss_char_w_t const* c_str_ptr_w(basic_simple_string<ss_char_w_t, T, A> const& s)
01179 {
01180 return c_str_ptr(s);
01181 }
01182
01183
01184
01189 template< ss_typename_param_k C
01190 , ss_typename_param_k T
01191 , ss_typename_param_k A
01192 >
01193 inline C const* c_str_data(basic_simple_string<C, T, A> const& s)
01194 {
01195 return s.data();
01196 }
01201 template<ss_typename_param_k T, ss_typename_param_k A>
01202 inline ss_char_a_t const* c_str_data_a(basic_simple_string<ss_char_a_t, T, A> const& s)
01203 {
01204 return c_str_data(s);
01205 }
01210 template<ss_typename_param_k T, ss_typename_param_k A>
01211 inline ss_char_w_t const* c_str_data_w(basic_simple_string<ss_char_w_t, T, A> const& s)
01212 {
01213 return c_str_data(s);
01214 }
01215
01216
01217
01222 template< ss_typename_param_k C
01223 , ss_typename_param_k T
01224 , ss_typename_param_k A
01225 >
01226 inline ss_size_t c_str_len(basic_simple_string<C, T, A> const& s)
01227 {
01228 return s.length();
01229 }
01234 template<ss_typename_param_k T, ss_typename_param_k A>
01235 inline ss_size_t c_str_len_a(basic_simple_string<ss_char_a_t, T, A> const& s)
01236 {
01237 return c_str_len(s);
01238 }
01243 template<ss_typename_param_k T, ss_typename_param_k A>
01244 inline ss_size_t c_str_len_w(basic_simple_string<ss_char_w_t, T, A> const& s)
01245 {
01246 return c_str_len(s);
01247 }
01248
01249
01250
01251
01252 template< ss_typename_param_k S
01253 , ss_typename_param_k C
01254 , ss_typename_param_k T
01255 , ss_typename_param_k A
01256 >
01257 inline S& operator <<(S& s, basic_simple_string<C, T, A> const& str)
01258 {
01259
01260
01261
01262 s << static_cast<C const*>(str.c_str());
01263
01264 return s;
01265 }
01266
01267
01268
01269
01270
01271 template< ss_typename_param_k C
01272 , ss_typename_param_k T
01273 , ss_typename_param_k A
01274 >
01275 inline void swap(basic_simple_string<C, T, A>& lhs, basic_simple_string<C, T, A>& rhs)
01276 {
01277 lhs.swap(rhs);
01278 }
01279
01280
01281
01282
01283
01284 #ifdef STLSOFT_UNITTEST
01285 # include "./unittest/simple_string_unittest_.h"
01286 #endif
01287
01288
01289
01290
01291
01292 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
01293
01294
01295
01296 template< ss_typename_param_k C
01297 , ss_typename_param_k T
01298 , ss_typename_param_k A
01299 >
01300 inline ss_typename_type_ret_k basic_simple_string<C, T, A>::char_type* basic_simple_string<C, T, A>::char_pointer_from_member_pointer_(ss_typename_type_k basic_simple_string<C, T, A>::member_pointer m)
01301 {
01302 #ifdef STLSOFT_SIMPLE_STRING_NO_PTR_ADJUST
01303 return (NULL == m) ? NULL : m->contents;
01304 #else
01305 return m;
01306 #endif
01307 }
01308
01309
01310 template< ss_typename_param_k C
01311 , ss_typename_param_k T
01312 , ss_typename_param_k A
01313 >
01314 inline ss_typename_type_ret_k basic_simple_string<C, T, A>::string_buffer* basic_simple_string<C, T, A>::string_buffer_from_member_pointer_(ss_typename_type_k basic_simple_string<C, T, A>::member_pointer m)
01315 {
01316 STLSOFT_MESSAGE_ASSERT("Attempt to convert a null string_buffer in basic_simple_string", NULL != m);
01317
01318 #ifdef STLSOFT_SIMPLE_STRING_NO_PTR_ADJUST
01319 return m;
01320 #else
01321 return reinterpret_cast<string_buffer*>(const_cast<void*>(ptr_byte_offset(m, -static_cast<ss_ptrdiff_t>(STLSOFT_RAW_OFFSETOF(string_buffer, contents)))));
01322 #endif
01323 }
01324
01325 template< ss_typename_param_k C
01326 , ss_typename_param_k T
01327 , ss_typename_param_k A
01328 >
01329 inline ss_typename_type_ret_k basic_simple_string<C, T, A>::string_buffer const* basic_simple_string<C, T, A>::string_buffer_from_member_pointer_(ss_typename_type_k basic_simple_string<C, T, A>::member_const_pointer m)
01330 {
01331 STLSOFT_MESSAGE_ASSERT("Attempt to convert a null string_buffer in basic_simple_string", NULL != m);
01332
01333 #ifdef STLSOFT_SIMPLE_STRING_NO_PTR_ADJUST
01334 return m;
01335 #else
01336 return reinterpret_cast<string_buffer const*>(ptr_byte_offset(m, -static_cast<ss_ptrdiff_t>(STLSOFT_RAW_OFFSETOF(string_buffer, contents))));
01337 #endif
01338 }
01339
01340 template< ss_typename_param_k C
01341 , ss_typename_param_k T
01342 , ss_typename_param_k A
01343 >
01344 inline ss_typename_type_ret_k basic_simple_string<C, T, A>::member_pointer basic_simple_string<C, T, A>::member_pointer_from_string_buffer_(ss_typename_type_k basic_simple_string<C, T, A>::string_buffer* b)
01345 {
01346 #ifdef STLSOFT_SIMPLE_STRING_NO_PTR_ADJUST
01347 return b;
01348 #else
01349 return b->contents;
01350 #endif
01351 }
01352
01353 template< ss_typename_param_k C
01354 , ss_typename_param_k T
01355 , ss_typename_param_k A
01356 >
01357 inline ss_typename_type_ret_k basic_simple_string<C, T, A>::member_pointer basic_simple_string<C, T, A>::alloc_buffer_(ss_typename_type_k basic_simple_string<C, T, A>::char_type const* s
01358 , ss_typename_type_k basic_simple_string<C, T, A>::size_type capacity
01359 , ss_typename_type_k basic_simple_string<C, T, A>::size_type length)
01360 {
01361
01362 STLSOFT_ASSERT(length <= capacity);
01363 STLSOFT_ASSERT(length >= traits_type::length_max_null(s, length));
01364
01365 const ss_size_t members = (STLSOFT_RAW_OFFSETOF(string_buffer, contents) + (sizeof(char_type) - 1)) / sizeof(char_type);
01366
01367 capacity += 1;
01368 capacity += members;
01369 capacity = (alloc_quantum + capacity) & ~alloc_quantum;
01370
01371 byte_ator_type byte_ator;
01372 void* raw_buffer = byte_ator.allocate(capacity * sizeof(char_type), NULL);
01373 string_buffer* buffer = sap_cast<string_buffer*>(raw_buffer);
01374
01375 if(NULL != buffer)
01376 {
01377 if(NULL == s)
01378 {
01379 STLSOFT_ASSERT(0 == length);
01380
01381 buffer->contents[0] = traits_type::to_char_type(0);
01382 }
01383 else
01384 {
01385 traits_type::copy(buffer->contents, s, length);
01386 buffer->contents[length] = traits_type::to_char_type(0);
01387 }
01388
01389 buffer->length = length;
01390 buffer->capacity = capacity - members;
01391
01392 return member_pointer_from_string_buffer_(buffer);
01393 }
01394
01395 return NULL;
01396 }
01397
01398 template< ss_typename_param_k C
01399 , ss_typename_param_k T
01400 , ss_typename_param_k A
01401 >
01402 inline ss_typename_type_ret_k basic_simple_string<C, T, A>::member_pointer basic_simple_string<C, T, A>::alloc_buffer_(ss_typename_type_k basic_simple_string<C, T, A>::char_type const* s
01403 , ss_typename_type_k basic_simple_string<C, T, A>::size_type cch)
01404 {
01405 size_type length = traits_type::length_max_null(s, cch);
01406 size_type capacity = cch;
01407
01408 if(cch < length)
01409 {
01410 length = cch;
01411 }
01412
01413 return alloc_buffer_(s, capacity, length);
01414 }
01415
01416 template< ss_typename_param_k C
01417 , ss_typename_param_k T
01418 , ss_typename_param_k A
01419 >
01420 inline ss_typename_type_ret_k basic_simple_string<C, T, A>::member_pointer basic_simple_string<C, T, A>::alloc_buffer_(ss_typename_type_k basic_simple_string<C, T, A>::char_type const* s)
01421 {
01422 member_pointer res;
01423
01424 if(NULL == s)
01425 {
01426 res = NULL;
01427 }
01428 else
01429 {
01430 size_type len = traits_type::length(s);
01431
01432 res = alloc_buffer_(s, len, len);
01433 }
01434
01435 return res;
01436 }
01437
01438 template< ss_typename_param_k C
01439 , ss_typename_param_k T
01440 , ss_typename_param_k A
01441 >
01442 inline ss_typename_type_ret_k basic_simple_string<C, T, A>::member_pointer basic_simple_string<C, T, A>::copy_buffer_(ss_typename_type_k basic_simple_string<C, T, A>::member_pointer m)
01443 {
01444 if(NULL != m)
01445 {
01446 byte_ator_type byte_ator;
01447 string_buffer* buffer = string_buffer_from_member_pointer_(m);
01448 ss_size_t cb = buffer->capacity * sizeof(char_type) + STLSOFT_RAW_OFFSETOF(string_buffer, contents);
01449 void* raw_buffer = byte_ator.allocate(cb, NULL);
01450 string_buffer* new_buffer = sap_cast<string_buffer*>(raw_buffer);
01451
01452 if(NULL != new_buffer)
01453 {
01454 memcpy(new_buffer, buffer, cb);
01455
01456 return member_pointer_from_string_buffer_(new_buffer);
01457 }
01458 }
01459
01460 return NULL;
01461 }
01462
01463 template< ss_typename_param_k C
01464 , ss_typename_param_k T
01465 , ss_typename_param_k A
01466 >
01467 inline void basic_simple_string<C, T, A>::destroy_buffer_(ss_typename_type_k basic_simple_string<C, T, A>::string_buffer* buffer)
01468 {
01469 byte_ator_type byte_ator;
01470
01471 byte_ator.deallocate(sap_cast<ss_byte_t*>(buffer), 0);
01472 }
01473
01474 template< ss_typename_param_k C
01475 , ss_typename_param_k T
01476 , ss_typename_param_k A
01477 >
01478 inline void basic_simple_string<C, T, A>::destroy_buffer_(ss_typename_type_k basic_simple_string<C, T, A>::char_type* s)
01479 {
01480 destroy_buffer_(string_buffer_from_member_pointer_(s));
01481 }
01482
01483 template< ss_typename_param_k C
01484 , ss_typename_param_k T
01485 , ss_typename_param_k A
01486 >
01487 inline ss_typename_type_ret_k basic_simple_string<C, T, A>::pointer basic_simple_string<C, T, A>::begin_()
01488 {
01489 return char_pointer_from_member_pointer_(m_buffer);
01490 }
01491
01492 template< ss_typename_param_k C
01493 , ss_typename_param_k T
01494 , ss_typename_param_k A
01495 >
01496 inline ss_typename_type_ret_k basic_simple_string<C, T, A>::pointer basic_simple_string<C, T, A>::end_()
01497 {
01498 return begin_() + length();
01499 }
01500
01501 template< ss_typename_param_k C
01502 , ss_typename_param_k T
01503 , ss_typename_param_k A
01504 >
01505 inline ss_bool_t basic_simple_string<C, T, A>::is_valid() const
01506 {
01507 if(NULL != m_buffer)
01508 {
01509 string_buffer const* buffer = string_buffer_from_member_pointer_(m_buffer);
01510
01511 if(buffer->capacity < 1)
01512 {
01513 #if defined(STLSOFT_UNITTEST) || \
01514 defined(STLSOFT_PRINT_CONTRACT_VIOLATION_DETAILS)
01515 fprintf(stderr, "%08x: capacity (%u) < 1\n", static_cast<unsigned>(reinterpret_cast<ss_size_t>(this)), static_cast<unsigned>(buffer->capacity));
01516 #endif
01517
01518 return false;
01519 }
01520 else if(buffer->capacity < buffer->length)
01521 {
01522 #if defined(STLSOFT_UNITTEST) || \
01523 defined(STLSOFT_PRINT_CONTRACT_VIOLATION_DETAILS)
01524 fprintf(stderr, "%08x: capacity (%u) < length (%u, %08x)\n", static_cast<unsigned>(reinterpret_cast<ss_size_t>(this)), static_cast<unsigned>(buffer->capacity), static_cast<unsigned>(buffer->length), static_cast<unsigned>(buffer->length));
01525 #endif
01526
01527 return false;
01528 }
01529 else
01530 {
01531 size_type len = traits_type::length(buffer->contents);
01532
01533 if(buffer->length < len)
01534 {
01535 #if defined(STLSOFT_UNITTEST) || \
01536 defined(STLSOFT_PRINT_CONTRACT_VIOLATION_DETAILS)
01537 fprintf(stderr, "%08x: length (%u) < length() (%u, %08x)\n", static_cast<unsigned>(reinterpret_cast<ss_size_t>(this)), static_cast<unsigned>(buffer->length), static_cast<unsigned>(len), static_cast<unsigned>(len));
01538 #endif
01539
01540 return false;
01541 }
01542 }
01543 }
01544
01545 return true;
01546 }
01547
01548 template< ss_typename_param_k C
01549 , ss_typename_param_k T
01550 , ss_typename_param_k A
01551 >
01552 inline ss_typename_type_ret_k basic_simple_string<C, T, A>::char_type const* basic_simple_string<C, T, A>::empty_string_()
01553 {
01554
01555
01556
01557 static char_type s_empty[1];
01558
01559 STLSOFT_ASSERT(s_empty[0] == '\0');
01560
01561 return s_empty;
01562 }
01563
01564
01565
01566 template< ss_typename_param_k C
01567 , ss_typename_param_k T
01568 , ss_typename_param_k A
01569 >
01570 inline basic_simple_string<C, T, A>::basic_simple_string()
01571 : m_buffer(NULL)
01572 {
01573 STLSOFT_ASSERT(is_valid());
01574 }
01575
01576 template< ss_typename_param_k C
01577 , ss_typename_param_k T
01578 , ss_typename_param_k A
01579 >
01580 inline basic_simple_string<C, T, A>::basic_simple_string(class_type const& rhs)
01581 : m_buffer(copy_buffer_(rhs.m_buffer))
01582 {
01583 STLSOFT_ASSERT(rhs.is_valid());
01584 STLSOFT_ASSERT(is_valid());
01585 }
01586
01587 template< ss_typename_param_k C
01588 , ss_typename_param_k T
01589 , ss_typename_param_k A
01590 >
01591 inline basic_simple_string<C, T, A>::basic_simple_string( ss_typename_type_k basic_simple_string<C, T, A>::class_type const& rhs
01592 , ss_typename_type_k basic_simple_string<C, T, A>::size_type pos)
01593 : m_buffer(alloc_buffer_(&rhs[pos]))
01594 {
01595 STLSOFT_ASSERT(is_valid());
01596 }
01597
01598 template< ss_typename_param_k C
01599 , ss_typename_param_k T
01600 , ss_typename_param_k A
01601 >
01602 inline basic_simple_string<C, T, A>::basic_simple_string( ss_typename_type_k basic_simple_string<C, T, A>::class_type const& rhs
01603 , ss_typename_type_k basic_simple_string<C, T, A>::size_type pos
01604 , ss_typename_type_k basic_simple_string<C, T, A>::size_type cch)
01605 : m_buffer(alloc_buffer_(&rhs[pos], cch, minimum(cch, rhs.length() - pos)))
01606 {
01607 STLSOFT_ASSERT(is_valid());
01608 }
01609
01610 template< ss_typename_param_k C
01611 , ss_typename_param_k T
01612 , ss_typename_param_k A
01613 >
01614 inline basic_simple_string<C, T, A>::basic_simple_string(ss_typename_type_k basic_simple_string<C, T, A>::char_type const* s)
01615 : m_buffer(alloc_buffer_(s))
01616 {
01617 STLSOFT_ASSERT(is_valid());
01618 }
01619
01620 template< ss_typename_param_k C
01621 , ss_typename_param_k T
01622 , ss_typename_param_k A
01623 >
01624 inline basic_simple_string<C, T, A>::basic_simple_string( ss_typename_type_k basic_simple_string<C, T, A>::char_type const* s
01625 , ss_typename_type_k basic_simple_string<C, T, A>::size_type cch)
01626 : m_buffer(alloc_buffer_(s, cch))
01627 {
01628 STLSOFT_ASSERT(is_valid());
01629 }
01630
01631 template< ss_typename_param_k C
01632 , ss_typename_param_k T
01633 , ss_typename_param_k A
01634 >
01635 inline basic_simple_string<C, T, A>::basic_simple_string( ss_typename_type_k basic_simple_string<C, T, A>::size_type cch
01636 , ss_typename_type_k basic_simple_string<C, T, A>::char_type ch)
01637 : m_buffer(NULL)
01638 {
01639 STLSOFT_ASSERT(is_valid());
01640
01641 assign(cch, ch);
01642 }
01643
01644 #if !defined(STLSOFT_CF_MEMBER_TEMPLATE_RANGE_METHOD_SUPPORT)
01645 template< ss_typename_param_k C
01646 , ss_typename_param_k T
01647 , ss_typename_param_k A
01648 >
01649 inline basic_simple_string<C, T, A>::basic_simple_string( ss_typename_type_k basic_simple_string<C, T, A>::char_type const* first
01650 , ss_typename_type_k basic_simple_string<C, T, A>::char_type const* last)
01651 : m_buffer(alloc_buffer_(first, last - first))
01652 {
01653 STLSOFT_ASSERT(is_valid());
01654 }
01655 #endif
01656
01657 template< ss_typename_param_k C
01658 , ss_typename_param_k T
01659 , ss_typename_param_k A
01660 >
01661 inline basic_simple_string<C, T, A>::~basic_simple_string() stlsoft_throw_0()
01662 {
01663 #if defined(__BORLANDC__) && \
01664 __BORLANDC__ > 0x0580 && \
01665 defined(_DEBUG)
01666
01667
01668
01669
01670
01671
01672 if(!is_valid())
01673 {
01674 this->size();
01675 }
01676 else
01677 {
01678 this->size();
01679 fprintf(stdin, "%.*s", int(this->size()), this->data());
01680 }
01681 #endif
01682
01683 STLSOFT_ASSERT(is_valid());
01684
01685 if(NULL != m_buffer)
01686 {
01687 destroy_buffer_(m_buffer);
01688 }
01689 }
01690
01691
01692
01693 template< ss_typename_param_k C
01694 , ss_typename_param_k T
01695 , ss_typename_param_k A
01696 >
01697 inline ss_sint_t basic_simple_string<C, T, A>::compare_( ss_typename_type_k basic_simple_string<C, T, A>::value_type const* lhs
01698 , ss_typename_type_k basic_simple_string<C, T, A>::size_type lhs_len
01699 , ss_typename_type_k basic_simple_string<C, T, A>::value_type const* rhs
01700 , ss_typename_type_k basic_simple_string<C, T, A>::size_type rhs_len)
01701 {
01702 size_type cmp_len = (lhs_len < rhs_len) ? lhs_len : rhs_len;
01703 ss_int_t result = traits_type::compare(lhs, rhs, cmp_len);
01704
01705 if(0 == result)
01706 {
01707 result = static_cast<ss_int_t>(lhs_len) - static_cast<ss_int_t>(rhs_len);
01708 }
01709
01710 return result;
01711 }
01712
01713 template< ss_typename_param_k C
01714 , ss_typename_param_k T
01715 , ss_typename_param_k A
01716 >
01717 inline ss_sint_t basic_simple_string<C, T, A>::compare( ss_typename_type_k basic_simple_string<C, T, A>::size_type pos
01718 , ss_typename_type_k basic_simple_string<C, T, A>::size_type cch
01719 , ss_typename_type_k basic_simple_string<C, T, A>::value_type const* rhs
01720 , ss_typename_type_k basic_simple_string<C, T, A>::size_type cchRhs) const
01721 {
01722 size_type lhs_len = length();
01723
01724 if(!(pos < lhs_len))
01725 {
01726 pos = lhs_len;
01727 }
01728 else
01729 {
01730 lhs_len -= pos;
01731 }
01732
01733 if(cch < lhs_len)
01734 {
01735 lhs_len = cch;
01736 }
01737
01738 size_type rhs_len = (NULL == rhs) ? 0 : traits_type::length(rhs);
01739
01740 if(cchRhs < rhs_len)
01741 {
01742 rhs_len = cchRhs;
01743 }
01744
01745 return compare_(char_pointer_from_member_pointer_(m_buffer) + pos, lhs_len, rhs, rhs_len);
01746 }
01747
01748 template< ss_typename_param_k C
01749 , ss_typename_param_k T
01750 , ss_typename_param_k A
01751 >
01752 inline ss_sint_t basic_simple_string<C, T, A>::compare( ss_typename_type_k basic_simple_string<C, T, A>::size_type pos
01753 , ss_typename_type_k basic_simple_string<C, T, A>::size_type cch
01754 , ss_typename_type_k basic_simple_string<C, T, A>::value_type const* rhs) const
01755 {
01756 size_type lhs_len = length();
01757
01758 if(!(pos < lhs_len))
01759 {
01760 pos = lhs_len;
01761 }
01762 else
01763 {
01764 lhs_len -= pos;
01765 }
01766
01767 if(cch < lhs_len)
01768 {
01769 lhs_len = cch;
01770 }
01771
01772 size_type rhs_len = (NULL == rhs) ? 0 : traits_type::length(rhs);
01773
01774 return compare_(char_pointer_from_member_pointer_(m_buffer) + pos, lhs_len, rhs, rhs_len);
01775 }
01776
01777 template< ss_typename_param_k C
01778 , ss_typename_param_k T
01779 , ss_typename_param_k A
01780 >
01781 inline ss_sint_t basic_simple_string<C, T, A>::compare(ss_typename_type_k basic_simple_string<C, T, A>::value_type const* rhs) const
01782 {
01783 size_type lhs_len = length();
01784 size_type rhs_len = (NULL == rhs) ? 0 : traits_type::length(rhs);
01785
01786 return compare_(char_pointer_from_member_pointer_(m_buffer), lhs_len, rhs, rhs_len);
01787 }
01788
01789 template< ss_typename_param_k C
01790 , ss_typename_param_k T
01791 , ss_typename_param_k A
01792 >
01793 inline ss_sint_t basic_simple_string<C, T, A>::compare( ss_typename_type_k basic_simple_string<C, T, A>::size_type pos
01794 , ss_typename_type_k basic_simple_string<C, T, A>::size_type cch
01795 , ss_typename_type_k basic_simple_string<C, T, A>::class_type const& rhs
01796 , ss_typename_type_k basic_simple_string<C, T, A>::size_type posRhs
01797 , ss_typename_type_k basic_simple_string<C, T, A>::size_type cchRhs) const
01798 {
01799 size_type lhs_len = length();
01800
01801 if(pos == lhs_len)
01802 {
01803 lhs_len = 0u;
01804 }
01805 else if(pos + cch > lhs_len)
01806 {
01807 lhs_len -= pos;
01808 }
01809
01810 if(cch < lhs_len)
01811 {
01812 lhs_len = cch;
01813 }
01814
01815 size_type rhs_len = rhs.length();
01816
01817 if(posRhs == rhs_len)
01818 {
01819 rhs_len = 0u;
01820 }
01821 else if(posRhs + cchRhs > rhs_len)
01822 {
01823 rhs_len -= posRhs;
01824 }
01825
01826 if(cchRhs < rhs_len)
01827 {
01828 rhs_len = cchRhs;
01829 }
01830
01831 return compare_(char_pointer_from_member_pointer_(m_buffer) + pos, lhs_len, char_pointer_from_member_pointer_(rhs.m_buffer) + posRhs, rhs_len);
01832 }
01833
01834 template< ss_typename_param_k C
01835 , ss_typename_param_k T
01836 , ss_typename_param_k A
01837 >
01838 inline ss_sint_t basic_simple_string<C, T, A>::compare( ss_typename_type_k basic_simple_string<C, T, A>::size_type pos
01839 , ss_typename_type_k basic_simple_string<C, T, A>::size_type cch
01840 , ss_typename_type_k basic_simple_string<C, T, A>::class_type const& rhs) const
01841 {
01842 size_type lhs_len = length();
01843
01844 if(!(pos < lhs_len))
01845 {
01846 pos = lhs_len;
01847 }
01848 else
01849 {
01850 lhs_len -= pos;
01851 }
01852
01853 if(cch < lhs_len)
01854 {
01855 lhs_len = cch;
01856 }
01857
01858 size_type rhs_len = rhs.length();
01859
01860 return compare_(char_pointer_from_member_pointer_(m_buffer) + pos, lhs_len, char_pointer_from_member_pointer_(rhs.m_buffer), rhs_len);
01861 }
01862
01863 template< ss_typename_param_k C
01864 , ss_typename_param_k T
01865 , ss_typename_param_k A
01866 >
01867 inline ss_sint_t basic_simple_string<C, T, A>::compare(ss_typename_type_k basic_simple_string<C, T, A>::class_type const& rhs) const
01868 {
01869 size_type lhs_len = length();
01870 size_type rhs_len = rhs.length();
01871
01872 return compare_(char_pointer_from_member_pointer_(m_buffer), lhs_len, char_pointer_from_member_pointer_(rhs.m_buffer), rhs_len);
01873 }
01874
01875
01876 template< ss_typename_param_k C
01877 , ss_typename_param_k T
01878 , ss_typename_param_k A
01879 >
01880 inline ss_typename_type_ret_k basic_simple_string<C, T, A>::reference basic_simple_string<C, T, A>::operator [](ss_typename_type_k basic_simple_string<C, T, A>::size_type index)
01881 {
01882 STLSOFT_MESSAGE_ASSERT("index access out of range in simple_string", index < length());
01883
01884 STLSOFT_ASSERT(is_valid());
01885
01886 return char_pointer_from_member_pointer_(m_buffer)[index];
01887 }
01888
01889 template< ss_typename_param_k C
01890 , ss_typename_param_k T
01891 , ss_typename_param_k A
01892 >
01893 inline ss_typename_type_ret_k basic_simple_string<C, T, A>::const_reference basic_simple_string<C, T, A>::operator [](ss_typename_type_k basic_simple_string<C, T, A>::size_type index) const
01894 {
01895 STLSOFT_MESSAGE_ASSERT("index access out of range in simple_string", index < length() + 1);
01896
01897 STLSOFT_ASSERT(is_valid());
01898
01899 return char_pointer_from_member_pointer_(m_buffer)[index];
01900 }
01901
01902 #ifdef STLSOFT_CF_EXCEPTION_SUPPORT
01903 template< ss_typename_param_k C
01904 , ss_typename_param_k T
01905 , ss_typename_param_k A
01906 >
01907 inline ss_typename_type_ret_k basic_simple_string<C, T, A>::reference basic_simple_string<C, T, A>::at(ss_typename_type_k basic_simple_string<C, T, A>::size_type index)
01908 {
01909 STLSOFT_ASSERT(is_valid());
01910
01911 if(index >= size())
01912 {
01913 STLSOFT_THROW_X(stlsoft_ns_qual_std(out_of_range)("index out of range"));
01914 }
01915
01916 STLSOFT_ASSERT(is_valid());
01917
01918 return char_pointer_from_member_pointer_(m_buffer)[index];
01919 }
01920
01921 template< ss_typename_param_k C
01922 , ss_typename_param_k T
01923 , ss_typename_param_k A
01924 >
01925 inline ss_typename_type_ret_k basic_simple_string<C, T, A>::const_reference basic_simple_string<C, T, A>::at(ss_typename_type_k basic_simple_string<C, T, A>::size_type index) const
01926 {
01927 STLSOFT_ASSERT(is_valid());
01928
01929 if(index >= size())
01930 {
01931 STLSOFT_THROW_X(stlsoft_ns_qual_std(out_of_range)("index out of range"));
01932 }
01933
01934 STLSOFT_ASSERT(is_valid());
01935
01936 return char_pointer_from_member_pointer_(m_buffer)[index];
01937 }
01938
01939 template< ss_typename_param_k C
01940 , ss_typename_param_k T
01941 , ss_typename_param_k A
01942 >
01943 inline ss_typename_type_ret_k basic_simple_string<C, T, A>::class_type basic_simple_string<C, T, A>::substr(ss_typename_type_k basic_simple_string<C, T, A>::size_type pos, ss_typename_type_k basic_simple_string<C, T, A>::size_type cch) const
01944 {
01945 STLSOFT_ASSERT(is_valid());
01946
01947 if(pos > size())
01948 {
01949 STLSOFT_THROW_X(stlsoft_ns_qual_std(out_of_range)("index out of range"));
01950 }
01951
01952 STLSOFT_ASSERT(is_valid());
01953
01954 if(cch > (this->length() - pos))
01955 {
01956 cch = this->length() - pos;
01957 }
01958
01959 return class_type(this->data() + pos, cch);
01960 }
01961
01962 template< ss_typename_param_k C
01963 , ss_typename_param_k T
01964 , ss_typename_param_k A
01965 >
01966 inline ss_typename_type_ret_k basic_simple_string<C, T, A>::class_type basic_simple_string<C, T, A>::substr(ss_typename_type_k basic_simple_string<C, T, A>::size_type pos) const
01967 {
01968 STLSOFT_ASSERT(is_valid());
01969
01970 if(pos > size())
01971 {
01972 STLSOFT_THROW_X(stlsoft_ns_qual_std(out_of_range)("index out of range"));
01973 }
01974
01975 STLSOFT_ASSERT(is_valid());
01976
01977 return class_type(this->data() + pos, this->length() - pos);
01978 }
01979
01980 template< ss_typename_param_k C
01981 , ss_typename_param_k T
01982 , ss_typename_param_k A
01983 >
01984 inline ss_typename_type_ret_k basic_simple_string<C, T, A>::class_type basic_simple_string<C, T, A>::substr() const
01985 {
01986 return *this;
01987 }
01988 #endif
01989
01990 template< ss_typename_param_k C
01991 , ss_typename_param_k T
01992 , ss_typename_param_k A
01993 >
01994 inline ss_typename_type_ret_k basic_simple_string<C, T, A>::value_type const* basic_simple_string<C, T, A>::c_str() const
01995 {
01996 return (NULL == m_buffer) ? empty_string_() : char_pointer_from_member_pointer_(m_buffer);
01997 }
01998
01999 template< ss_typename_param_k C
02000 , ss_typename_param_k T
02001 , ss_typename_param_k A
02002 >
02003 inline ss_typename_type_ret_k basic_simple_string<C, T, A>::value_type const* basic_simple_string<C, T, A>::data() const
02004 {
02005 return (NULL == m_buffer) ? empty_string_() : char_pointer_from_member_pointer_(m_buffer);
02006 }
02007
02008 template< ss_typename_param_k C
02009 , ss_typename_param_k T
02010 , ss_typename_param_k A
02011 >
02012 inline ss_typename_type_ret_k basic_simple_string<C, T, A>::reference basic_simple_string<C, T, A>::front()
02013 {
02014 return (*this)[0];
02015 }
02016
02017 template< ss_typename_param_k C
02018 , ss_typename_param_k T
02019 , ss_typename_param_k A
02020 >
02021 inline ss_typename_type_ret_k basic_simple_string<C, T, A>::reference basic_simple_string<C, T, A>::back()
02022 {
02023 return (*this)[length() - 1];
02024 }
02025
02026 template< ss_typename_param_k C
02027 , ss_typename_param_k T
02028 , ss_typename_param_k A
02029 >
02030 inline ss_typename_type_ret_k basic_simple_string<C, T, A>::const_reference basic_simple_string<C, T, A>::front() const
02031 {
02032 return (*this)[0];
02033 }
02034
02035 template< ss_typename_param_k C
02036 , ss_typename_param_k T
02037 , ss_typename_param_k A
02038 >
02039 inline ss_typename_type_ret_k basic_simple_string<C, T, A>::const_reference basic_simple_string<C, T, A>::back() const
02040 {
02041 return (*this)[length() - 1];
02042 }
02043
02044 template< ss_typename_param_k C
02045 , ss_typename_param_k T
02046 , ss_typename_param_k A
02047 >
02048 inline ss_typename_type_ret_k basic_simple_string<C, T, A>::size_type basic_simple_string<C, T, A>::copy( ss_typename_type_k basic_simple_string<C, T, A>::value_type* dest
02049 , ss_typename_type_k basic_simple_string<C, T, A>::size_type cch
02050 , ss_typename_type_k basic_simple_string<C, T, A>::size_type pos ) const
02051 {
02052 size_type len = length();
02053
02054 if(pos < len)
02055 {
02056 if(len < pos + cch)
02057 {
02058 cch = len - pos;
02059 }
02060
02061 traits_type::copy(dest, data() + pos, cch);
02062 }
02063 else
02064 {
02065 cch = 0;
02066 }
02067
02068 return cch;
02069 }
02070
02071
02072
02073 #ifndef STLSOFT_SIMPLE_STRING_ITERATOR_METHODS_INLINE
02074 template< ss_typename_param_k C
02075 , ss_typename_param_k T
02076 , ss_typename_param_k A
02077 >
02078 inline ss_typename_type_ret_k basic_simple_string<C, T, A>::const_iterator basic_simple_string<C, T, A>::begin() const
02079 {
02080 return const_cast<class_type*>(this)->begin_();
02081 }
02082
02083 template< ss_typename_param_k C
02084 , ss_typename_param_k T
02085 , ss_typename_param_k A
02086 >
02087 inline ss_typename_type_ret_k basic_simple_string<C, T, A>::const_iterator basic_simple_string<C, T, A>::end() const
02088 {
02089 return const_cast<class_type*>(this)->end_();
02090 }
02091 #endif
02092
02093 template< ss_typename_param_k C
02094 , ss_typename_param_k T
02095 , ss_typename_param_k A
02096 >
02097 inline ss_typename_type_ret_k basic_simple_string<C, T, A>::iterator basic_simple_string<C, T, A>::begin()
02098 {
02099 return begin_();
02100 }
02101
02102 template< ss_typename_param_k C
02103 , ss_typename_param_k T
02104 , ss_typename_param_k A
02105 >
02106 inline ss_typename_type_ret_k basic_simple_string<C, T, A>::iterator basic_simple_string<C, T, A>::end()
02107 {
02108 return end_();
02109 }
02110
02111 #if defined(STLSOFT_LF_BIDIRECTIONAL_ITERATOR_SUPPORT)
02112 template< ss_typename_param_k C
02113 , ss_typename_param_k T
02114 , ss_typename_param_k A
02115 >
02116 inline ss_typename_type_ret_k basic_simple_string<C, T, A>::const_reverse_iterator basic_simple_string<C, T, A>::rbegin() const
02117 {
02118 return const_reverse_iterator(end());
02119 }
02120
02121 template< ss_typename_param_k C
02122 , ss_typename_param_k T
02123 , ss_typename_param_k A
02124 >
02125 inline ss_typename_type_ret_k basic_simple_string<C, T, A>::const_reverse_iterator basic_simple_string<C, T, A>::rend() const
02126 {
02127 return const_reverse_iterator(begin());
02128 }
02129
02130 template< ss_typename_param_k C
02131 , ss_typename_param_k T
02132 , ss_typename_param_k A
02133 >
02134 inline ss_typename_type_ret_k basic_simple_string<C, T, A>::reverse_iterator basic_simple_string<C, T, A>::rbegin()
02135 {
02136 return reverse_iterator(end());
02137 }
02138
02139 template< ss_typename_param_k C
02140 , ss_typename_param_k T
02141 , ss_typename_param_k A
02142 >
02143 inline ss_typename_type_ret_k basic_simple_string<C, T, A>::reverse_iterator basic_simple_string<C, T, A>::rend()
02144 {
02145 return reverse_iterator(begin());
02146 }
02147 #endif
02148
02149
02150 template< ss_typename_param_k C
02151 , ss_typename_param_k T
02152 , ss_typename_param_k A
02153 >
02154 inline ss_typename_type_ret_k basic_simple_string<C, T, A>::class_type& basic_simple_string<C, T, A>::assign( ss_typename_type_k basic_simple_string<C, T, A>::char_type const* s
02155 , ss_typename_type_k basic_simple_string<C, T, A>::size_type cch)
02156 {
02157 STLSOFT_ASSERT(is_valid());
02158
02159 if(NULL == m_buffer)
02160 {
02161 if(cch == 0)
02162 {
02163
02164 }
02165 else
02166 {
02167 m_buffer = alloc_buffer_(s, cch);
02168 }
02169 }
02170 else
02171 {
02172 if(NULL == s)
02173 {
02174 destroy_buffer_(m_buffer);
02175 m_buffer = NULL;
02176 }
02177 else
02178 {
02179
02180
02181
02182
02183 string_buffer* buffer = string_buffer_from_member_pointer_(m_buffer);
02184 size_type len = traits_type::length(s);
02185
02186 #if 0
02187 if(len < cch)
02188 {
02189 cch = len;
02190 }
02191 #endif
02192
02193 if( cch < buffer->capacity &&
02194 ( s < &buffer->contents[0] ||
02195 s > &buffer->contents[len]))
02196 {
02197 traits_type::copy(buffer->contents, s, cch);
02198 buffer->contents[cch] = 0;
02199 buffer->length = cch;
02200 }
02201 else
02202 {
02203 member_pointer new_buffer = alloc_buffer_(s, cch, cch);
02204
02205 destroy_buffer_(m_buffer);
02206 m_buffer = new_buffer;
02207 }
02208 }
02209 }
02210
02211 STLSOFT_ASSERT(is_valid());
02212 return *this;
02213 }
02214
02215 template< ss_typename_param_k C
02216 , ss_typename_param_k T
02217 , ss_typename_param_k A
02218 >
02219 inline ss_typename_type_ret_k basic_simple_string<C, T, A>::class_type& basic_simple_string<C, T, A>::assign(ss_typename_type_k basic_simple_string<C, T, A>::char_type const* s)
02220 {
02221 return assign(s, (NULL == s) ? 0 : traits_type::length(s));
02222 }
02223
02224 template< ss_typename_param_k C
02225 , ss_typename_param_k T
02226 , ss_typename_param_k A
02227 >
02228 inline ss_typename_type_ret_k basic_simple_string<C, T, A>::class_type& basic_simple_string<C, T, A>::assign( ss_typename_type_k basic_simple_string<C, T, A>::class_type const& rhs
02229 , ss_typename_type_k basic_simple_string<C, T, A>::size_type pos
02230 , ss_typename_type_k basic_simple_string<C, T, A>::size_type cch)
02231 {
02232 char_type* s = char_pointer_from_member_pointer_(rhs.m_buffer);
02233 size_type len = rhs.length();
02234
02235 if(len < pos)
02236 {
02237 pos = len;
02238 }
02239
02240 if(len - pos < cch)
02241 {
02242 cch = len - pos;
02243 }
02244
02245 if(NULL != s)
02246 {
02247 s += pos;
02248 }
02249 else
02250 {
02251 cch = 0;
02252 }
02253
02254 return assign(s, cch);
02255 }
02256
02257 template< ss_typename_param_k C
02258 , ss_typename_param_k T
02259 , ss_typename_param_k A
02260 >
02261 inline ss_typename_type_ret_k basic_simple_string<C, T, A>::class_type& basic_simple_string<C, T, A>::assign(ss_typename_type_k basic_simple_string<C, T, A>::class_type const& rhs)
02262 {
02263 return assign(char_pointer_from_member_pointer_(rhs.m_buffer), rhs.length());
02264 }
02265
02266 template< ss_typename_param_k C
02267 , ss_typename_param_k T
02268 , ss_typename_param_k A
02269 >
02270 inline ss_typename_type_ret_k basic_simple_string<C, T, A>::class_type& basic_simple_string<C, T, A>::assign( ss_typename_type_k basic_simple_string<C, T, A>::size_type cch
02271 , ss_typename_type_k basic_simple_string<C, T, A>::char_type ch)
02272 {
02273 buffer_type_ buffer(cch);
02274
02275 static_cast<void>(stlsoft_ns_qual_std(fill)(buffer.begin(), buffer.end(), ch));
02276
02277 return assign(buffer.data(), buffer.size());
02278 }
02279
02280 #if !defined(STLSOFT_CF_MEMBER_TEMPLATE_RANGE_METHOD_SUPPORT)
02281 template< ss_typename_param_k C
02282 , ss_typename_param_k T
02283 , ss_typename_param_k A
02284 >
02285 inline ss_typename_type_ret_k basic_simple_string<C, T, A>::class_type& basic_simple_string<C, T, A>::assign( ss_typename_type_k basic_simple_string<C, T, A>::const_iterator first
02286 , ss_typename_type_k basic_simple_string<C, T, A>::const_iterator last)
02287 {
02288
02289
02290 return assign(&(*first), last - first);
02291 }
02292 #endif
02293
02294 template< ss_typename_param_k C
02295 , ss_typename_param_k T
02296 , ss_typename_param_k A
02297 >
02298 inline ss_typename_type_ret_k basic_simple_string<C, T, A>::class_type const& basic_simple_string<C, T, A>::operator =(ss_typename_type_k basic_simple_string<C, T, A>::class_type const& rhs)
02299 {
02300 return assign(rhs);
02301 }
02302
02303 template< ss_typename_param_k C
02304 , ss_typename_param_k T
02305 , ss_typename_param_k A
02306 >
02307 inline ss_typename_type_ret_k basic_simple_string<C, T, A>::class_type const& basic_simple_string<C, T, A>::operator =(ss_typename_type_k basic_simple_string<C, T, A>::char_type const* s)
02308 {
02309 return assign(s);
02310 }
02311
02312 template< ss_typename_param_k C
02313 , ss_typename_param_k T
02314 , ss_typename_param_k A
02315 >
02316 inline ss_typename_type_ret_k basic_simple_string<C, T, A>::class_type const& basic_simple_string<C, T, A>::operator =(ss_typename_type_k basic_simple_string<C, T, A>::char_type ch)
02317 {
02318 char_type sz[2] = { ch, traits_type::to_char_type(0) };
02319
02320 return assign(sz);
02321 }
02322
02323
02324
02325 template< ss_typename_param_k C
02326 , ss_typename_param_k T
02327 , ss_typename_param_k A
02328 >
02329 inline ss_typename_type_ret_k basic_simple_string<C, T, A>::class_type& basic_simple_string<C, T, A>::append( ss_typename_type_k basic_simple_string<C, T, A>::char_type const* s
02330 , ss_typename_type_k basic_simple_string<C, T, A>::size_type cch)
02331 {
02332 STLSOFT_ASSERT(is_valid());
02333
02334 if(NULL == m_buffer)
02335 {
02336 assign(s, cch);
02337 }
02338 else
02339 {
02340 if( NULL == s ||
02341 0 == cch)
02342 {
02343
02344 }
02345 else
02346 {
02347 #if 1
02348
02349
02350 size_type len = traits_type::length_max(s, cch);
02351
02352 if(len < cch)
02353 {
02354 cch = len;
02355 }
02356 #endif
02357
02358 string_buffer* old_buffer = NULL;
02359 string_buffer* buffer = string_buffer_from_member_pointer_(m_buffer);
02360 size_type buf_len = buffer->length;
02361
02362 if(buffer->capacity - buf_len < 1 + cch)
02363 {
02364
02365 member_pointer new_buffer = alloc_buffer_(buffer->contents, buf_len + cch);
02366
02367 if(NULL == new_buffer)
02368 {
02369 cch = 0;
02370 }
02371 else
02372 {
02373 old_buffer = buffer;
02374 m_buffer = new_buffer;
02375 buffer = string_buffer_from_member_pointer_(new_buffer);
02376 }
02377 }
02378
02379 traits_type::copy(buffer->contents + buf_len, s, cch);
02380 buffer->length += cch;
02381 buffer->contents[buffer->length] = traits_type::to_char_type(0);
02382
02383 if(NULL != old_buffer)
02384 {
02385 destroy_buffer_(old_buffer);
02386 }
02387 }
02388 }
02389
02390 STLSOFT_ASSERT(is_valid());
02391 return *this;
02392 }
02393
02394 template< ss_typename_param_k C
02395 , ss_typename_param_k T
02396 , ss_typename_param_k A
02397 >
02398 inline ss_typename_type_ret_k basic_simple_string<C, T, A>::class_type& basic_simple_string<C, T, A>::append(ss_typename_type_k basic_simple_string<C, T, A>::char_type const* s)
02399 {
02400 return append(s, (NULL == s) ? 0 : traits_type::length(s));
02401 }
02402
02403 template< ss_typename_param_k C
02404 , ss_typename_param_k T
02405 , ss_typename_param_k A
02406 >
02407 inline ss_typename_type_ret_k basic_simple_string<C, T, A>::class_type& basic_simple_string<C, T, A>::append( ss_typename_type_k basic_simple_string<C, T, A>::class_type const& rhs
02408 , ss_typename_type_k basic_simple_string<C, T, A>::size_type pos
02409 , ss_typename_type_k basic_simple_string<C, T, A>::size_type cch)
02410 {
02411 char_type* s = char_pointer_from_member_pointer_(rhs.m_buffer);
02412 size_type len = rhs.length();
02413
02414 if(len < pos)
02415 {
02416 #ifdef STLSOFT_CF_EXCEPTION_SUPPORT
02417 STLSOFT_THROW_X(stlsoft_ns_qual_std(out_of_range)("index out of range"));
02418 #else
02419 pos = len;
02420 #endif
02421 }
02422
02423 if(len - pos < cch)
02424 {
02425 cch = len - pos;
02426 }
02427
02428 if(NULL != s)
02429 {
02430 s += pos;
02431 }
02432 else
02433 {
02434 cch = 0;
02435 }
02436
02437 return append(s, cch);
02438 }
02439
02440 template< ss_typename_param_k C
02441 , ss_typename_param_k T
02442 , ss_typename_param_k A
02443 >
02444 inline ss_typename_type_ret_k basic_simple_string<C, T, A>::class_type& basic_simple_string<C, T, A>::append(ss_typename_type_k basic_simple_string<C, T, A>::class_type const& s)
02445 {
02446 return append(char_pointer_from_member_pointer_(s.m_buffer), s.length());
02447 }
02448
02449 template< ss_typename_param_k C
02450 , ss_typename_param_k T
02451 , ss_typename_param_k A
02452 >
02453 inline ss_typename_type_ret_k basic_simple_string<C, T, A>::class_type& basic_simple_string<C, T, A>::append( ss_typename_type_k basic_simple_string<C, T, A>::size_type cch
02454 , ss_typename_type_k basic_simple_string<C, T, A>::char_type ch)
02455 {
02456 if(NULL == m_buffer)
02457 {
02458 assign(cch, ch);
02459 }
02460 else
02461 {
02462 buffer_type_ buffer(cch);
02463
02464 static_cast<void>(stlsoft_ns_qual_std(fill)(buffer.begin(), buffer.end(), ch));
02465
02466 append(buffer.data(), buffer.size());
02467 }
02468
02469 return *this;
02470 }
02471
02472 #if !defined(STLSOFT_CF_MEMBER_TEMPLATE_RANGE_METHOD_SUPPORT)
02473 template< ss_typename_param_k C
02474 , ss_typename_param_k T
02475 , ss_typename_param_k A
02476 >
02477 inline ss_typename_type_ret_k basic_simple_string<C, T, A>::class_type& basic_simple_string<C, T, A>::append( ss_typename_type_k basic_simple_string<C, T, A>::const_iterator first
02478 , ss_typename_type_k basic_simple_string<C, T, A>::const_iterator last)
02479 {
02480
02481
02482 return append(&(*first), last - first);
02483 }
02484 #endif
02485
02486 template< ss_typename_param_k C
02487 , ss_typename_param_k T
02488 , ss_typename_param_k A
02489 >
02490 inline ss_typename_type_ret_k basic_simple_string<C, T, A>::class_type& basic_simple_string<C, T, A>::operator +=(ss_typename_type_k basic_simple_string<C, T, A>::char_type ch)
02491 {
02492 return append(1, ch);
02493 }
02494
02495 template< ss_typename_param_k C
02496 , ss_typename_param_k T
02497 , ss_typename_param_k A
02498 >
02499 inline ss_typename_type_ret_k basic_simple_string<C, T, A>::class_type& basic_simple_string<C, T, A>::operator +=(const ss_typename_type_k basic_simple_string<C, T, A>::char_type* s)
02500 {
02501 return append(s);
02502 }
02503
02504 template< ss_typename_param_k C
02505 , ss_typename_param_k T
02506 , ss_typename_param_k A
02507 >
02508 inline ss_typename_type_ret_k basic_simple_string<C, T, A>::class_type& basic_simple_string<C, T, A>::operator +=(const ss_typename_type_k basic_simple_string<C, T, A>::class_type& rhs)
02509 {
02510 return append(rhs);
02511 }
02512
02513 template< ss_typename_param_k C
02514 , ss_typename_param_k T
02515 , ss_typename_param_k A
02516 >
02517 inline void basic_simple_string<C, T, A>::push_back(ss_typename_type_k basic_simple_string<C, T, A>::char_type ch)
02518 {
02519 append(1, ch);
02520 }
02521
02522
02523 template< ss_typename_param_k C
02524 , ss_typename_param_k T
02525 , ss_typename_param_k A
02526 >
02527 inline void basic_simple_string<C, T, A>::reserve(ss_typename_type_k basic_simple_string<C, T, A>::size_type cch)
02528 {
02529 if(length() < cch)
02530 {
02531 if(NULL == m_buffer)
02532 {
02533 m_buffer = alloc_buffer_(NULL, cch, 0);
02534 }
02535 else
02536 {
02537 if(cch <= string_buffer_from_member_pointer_(m_buffer)->capacity)
02538 {
02539 ;
02540 }
02541 else
02542 {
02543
02544 member_pointer new_buffer = alloc_buffer_(c_str(), cch, length());
02545
02546 if(NULL != new_buffer)
02547 {
02548 destroy_buffer_(m_buffer);
02549 m_buffer = new_buffer;
02550 }
02551 }
02552 }
02553 }
02554 }
02555
02556 template< ss_typename_param_k C
02557 , ss_typename_param_k T
02558 , ss_typename_param_k A
02559 >
02560 inline void basic_simple_string<C, T, A>::swap(ss_typename_type_k basic_simple_string<C, T, A>::class_type& other)
02561 {
02562 STLSOFT_ASSERT(is_valid());
02563 STLSOFT_ASSERT(other.is_valid());
02564
02565 std_swap(m_buffer, other.m_buffer);
02566 }
02567
02568 template< ss_typename_param_k C
02569 , ss_typename_param_k T
02570 , ss_typename_param_k A
02571 >
02572 inline void basic_simple_string<C, T, A>::resize( ss_typename_type_k basic_simple_string<C, T, A>::size_type cch
02573 , ss_typename_type_k basic_simple_string<C, T, A>::value_type ch)
02574 {
02575 STLSOFT_ASSERT(is_valid());
02576
02577 size_type const len = length();
02578
02579 if(len != cch)
02580 {
02581 if(len < cch)
02582 {
02583
02584 assign(c_str(), cch);
02585
02586 traits_type::assign(char_pointer_from_member_pointer_(m_buffer) + len, cch - len, ch);
02587 }
02588
02589 string_buffer* buffer = string_buffer_from_member_pointer_(m_buffer);
02590
02591 buffer->length = cch;
02592 buffer->contents[buffer->length] = traits_type::to_char_type(0);
02593 }
02594
02595 STLSOFT_ASSERT(is_valid());
02596 }
02597
02598 template< ss_typename_param_k C
02599 , ss_typename_param_k T
02600 , ss_typename_param_k A
02601 >
02602 inline void basic_simple_string<C, T, A>::clear()
02603 {
02604 if(NULL != m_buffer)
02605 {
02606 string_buffer* buffer = string_buffer_from_member_pointer_(m_buffer);
02607
02608 buffer->length = 0;
02609 buffer->contents[0] = traits_type::to_char_type(0);
02610 }
02611 }
02612
02613
02614 template< ss_typename_param_k C
02615 , ss_typename_param_k T
02616 , ss_typename_param_k A
02617 >
02618 inline ss_typename_type_ret_k basic_simple_string<C, T, A>::size_type basic_simple_string<C, T, A>::size() const
02619 {
02620 STLSOFT_ASSERT(is_valid());
02621
02622 return (NULL == m_buffer) ? 0 : string_buffer_from_member_pointer_(m_buffer)->length;
02623 }
02624
02625 template< ss_typename_param_k C
02626 , ss_typename_param_k T
02627 , ss_typename_param_k A
02628 >
02629 inline ss_typename_type_ret_k basic_simple_string<C, T, A>::size_type basic_simple_string<C, T, A>::max_size() const
02630 {
02631 STLSOFT_ASSERT(is_valid());
02632
02633 return static_cast<size_type>(-1) / sizeof(char_type);
02634 }
02635
02636 template< ss_typename_param_k C
02637 , ss_typename_param_k T
02638 , ss_typename_param_k A
02639 >
02640 inline ss_typename_type_ret_k basic_simple_string<C, T, A>::size_type basic_simple_string<C, T, A>::length() const
02641 {
02642 STLSOFT_ASSERT(is_valid());
02643
02644 return size();
02645 }
02646
02647 template< ss_typename_param_k C
02648 , ss_typename_param_k T
02649 , ss_typename_param_k A
02650 >
02651 inline ss_typename_type_ret_k basic_simple_string<C, T, A>::size_type basic_simple_string<C, T, A>::capacity() const
02652 {
02653 STLSOFT_ASSERT(is_valid());
02654
02655 return (NULL == m_buffer) ? 0 : string_buffer_from_member_pointer_(m_buffer)->capacity;
02656 }
02657
02658 template< ss_typename_param_k C
02659 , ss_typename_param_k T
02660 , ss_typename_param_k A
02661 >
02662 inline ss_bool_t basic_simple_string<C, T, A>::empty() const
02663 {
02664 STLSOFT_ASSERT(is_valid());
02665
02666 return 0 == length();
02667 }
02668
02669 #endif
02670
02671
02672
02673 #ifndef _STLSOFT_NO_NAMESPACE
02674 }
02675 #endif
02676
02677
02678
02679
02680 #if defined(STLSOFT_CF_std_NAMESPACE)
02681 # if ( ( defined(STLSOFT_COMPILER_IS_INTEL) && \
02682 defined(_MSC_VER))) && \
02683 _MSC_VER < 1310
02684 namespace std
02685 {
02686 template< ss_typename_param_k C
02687 , ss_typename_param_k T
02688 , ss_typename_param_k A
02689 >
02690 inline void swap(stlsoft_ns_qual(basic_simple_string)<C, T, A>& lhs, stlsoft_ns_qual(basic_simple_string)<C, T, A>& rhs)
02691 {
02692 lhs.swap(rhs);
02693 }
02694 }
02695 # endif
02696 #endif
02697
02698
02699
02700 #endif
02701
02702