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
00041
00042
00050 #ifndef STLSOFT_INCL_STLSOFT_STRING_HPP_STATIC_STRING
00051 #define STLSOFT_INCL_STLSOFT_STRING_HPP_STATIC_STRING
00052
00053 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
00054 # define STLSOFT_VER_STLSOFT_STRING_HPP_STATIC_STRING_MAJOR 4
00055 # define STLSOFT_VER_STLSOFT_STRING_HPP_STATIC_STRING_MINOR 3
00056 # define STLSOFT_VER_STLSOFT_STRING_HPP_STATIC_STRING_REVISION 2
00057 # define STLSOFT_VER_STLSOFT_STRING_HPP_STATIC_STRING_EDIT 198
00058 #endif
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076 #ifndef STLSOFT_INCL_STLSOFT_H_STLSOFT
00077 # include <stlsoft/stlsoft.h>
00078 #endif
00079
00080 #if defined(STLSOFT_COMPILER_IS_DMC) && \
00081 __DMC__ < 0x0839
00082 # error stlsoft/string/static_string.hpp is not compatible with Digital Mars C/C++ 3.38 or earlier
00083 #endif
00084 #if defined(STLSOFT_COMPILER_IS_MSVC) && \
00085 _MSC_VER < 1200
00086 # error stlsoft/string/static_string.hpp is not compatible with Visual C++ 5.0 or earlier
00087 #endif
00088
00089 #ifndef STLSOFT_INCL_STLSOFT_STRING_HPP_CHAR_TRAITS
00090 # include <stlsoft/string/char_traits.hpp>
00091 #endif
00092 #ifndef STLSOFT_INCL_STLSOFT_COLLECTIONS_UTIL_HPP_COLLECTIONS
00093 # include <stlsoft/collections/util/collections.hpp>
00094 #endif
00095 #ifndef STLSOFT_INCL_STLSOFT_MEMORY_HPP_AUTO_BUFFER
00096 # include <stlsoft/memory/auto_buffer.hpp>
00097 #endif
00098 #ifndef STLSOFT_INCL_STLSOFT_MEMORY_HPP_ALLOCATOR_SELECTOR
00099 # include <stlsoft/memory/allocator_selector.hpp>
00100 #endif
00101 #ifndef STLSOFT_INCL_STLSOFT_UTIL_HPP_STD_SWAP
00102 # include <stlsoft/util/std_swap.hpp>
00103 #endif
00104 #ifndef STLSOFT_INCL_STLSOFT_UTIL_STD_HPP_ITERATOR_GENERATORS
00105 # include <stlsoft/util/std/iterator_generators.hpp>
00106 #endif
00107 #ifndef STLSOFT_INCL_STLSOFT_UTIL_STD_HPP_ITERATOR_HELPER
00108 # include <stlsoft/util/std/iterator_helper.hpp>
00109 #endif
00110 #ifdef STLSOFT_CF_EXCEPTION_SUPPORT
00111 # include <stdexcept>
00112 #endif
00113
00114 #ifdef STLSOFT_UNITTEST
00115 # include <string>
00116 # include <stdio.h>
00117 #endif
00118
00119
00120
00121
00122
00123 #ifndef _STLSOFT_NO_NAMESPACE
00124 namespace stlsoft
00125 {
00126 #endif
00127
00128
00129
00130
00131
00140 template< ss_typename_param_k C
00141 , ss_size_t CCH
00142 #ifdef STLSOFT_CF_TEMPLATE_CLASS_DEFAULT_CLASS_ARGUMENT_SUPPORT
00143 , ss_typename_param_k T = char_traits<C>
00144 #else
00145 , ss_typename_param_k T =
00146 #endif
00147 >
00148
00149 class basic_static_string
00150 : public stl_collection_tag
00151 {
00152 private:
00153 enum { internalSize = CCH };
00154
00157 public:
00159 typedef C value_type;
00161 typedef T traits_type;
00163 typedef ss_typename_type_k allocator_selector<C>::allocator_type allocator_type;
00165 typedef basic_static_string<C, CCH, T> class_type;
00167 typedef value_type char_type;
00169 typedef value_type* pointer;
00171 typedef value_type const* const_pointer;
00173 typedef value_type& reference;
00175 typedef value_type const& const_reference;
00177 typedef ss_size_t size_type;
00179 typedef ss_ptrdiff_t difference_type;
00180
00182 typedef
00183 #if !defined(STLSOFT_COMPILER_IS_BORLAND)
00184 ss_typename_type_k
00185 #endif
00186 pointer_iterator < value_type
00187 , pointer
00188 , reference
00189 >::type iterator;
00191 typedef
00192 #if !defined(STLSOFT_COMPILER_IS_BORLAND)
00193 ss_typename_type_k
00194 #endif
00195 pointer_iterator < value_type const
00196 , const_pointer
00197 , const_reference
00198 >::type const_iterator;
00199
00200 #if defined(STLSOFT_LF_BIDIRECTIONAL_ITERATOR_SUPPORT)
00202 typedef ss_typename_type_k reverse_iterator_generator < iterator
00203 , value_type
00204 , reference
00205 , pointer
00206 , difference_type
00207 >::type reverse_iterator;
00208
00210 typedef ss_typename_type_k const_reverse_iterator_generator < const_iterator
00211 , value_type
00212 , const_reference
00213 , const_pointer
00214 , difference_type
00215 >::type const_reverse_iterator;
00216 #endif
00217
00218 private:
00219 typedef auto_buffer_old<char_type
00220 , allocator_type
00221 > buffer_type_;
00223
00226 public:
00228 basic_static_string();
00230 basic_static_string(class_type const& rhs);
00232 basic_static_string(class_type const& s, size_type pos);
00234 basic_static_string(class_type const& s, size_type pos, size_type n);
00236 basic_static_string(char_type const* s);
00238 basic_static_string(char_type const* s, size_type n);
00240 basic_static_string(size_type n, char_type ch);
00242 #if !defined(STLSOFT_CF_MEMBER_TEMPLATE_RANGE_METHOD_SUPPORT)
00243 basic_static_string(char_type const* f, char_type const* t);
00244 #else
00245 template <ss_typename_param_k II>
00246 basic_static_string(II first, II last)
00247 : m_length(static_cast<ss_size_t>(stlsoft_ns_qual_std(distance)(first, last)))
00248 {
00249 STLSOFT_MESSAGE_ASSERT("incident string too large for static_string construction", !(max_size() < m_length));
00250
00251 buffer_type_ buffer(m_length);
00252
00253 stlsoft_ns_qual_std(copy)(first, last, buffer.begin());
00254
00255 traits_type::copy(&m_buffer[0], buffer.data(), buffer.size());
00256
00257 m_buffer[m_length] = '\0';
00258 m_buffer[max_size()] = '\0';
00259 }
00260 #endif
00262 ~basic_static_string() stlsoft_throw_0();
00264
00267 public:
00269 class_type& assign(char_type const* s);
00271 class_type& assign(char_type const* s, size_type n);
00273 class_type& assign(class_type const& str, size_type pos, size_type n);
00275 class_type& assign(class_type const& str);
00277 class_type& assign(size_type n, char_type c);
00279 #if !defined(STLSOFT_CF_MEMBER_TEMPLATE_RANGE_METHOD_SUPPORT)
00280 class_type& assign(const_iterator first, const_iterator last);
00281 #else
00282 template <ss_typename_param_k II>
00283 class_type& assign(II first, II last)
00284 {
00285 # if defined(STLSOFT_COMPILER_IS_GCC) && \
00286 __GNUC__ < 3
00287 typedef ss_typename_type_k std::iterator_traits<II> traits_t;
00288
00289 return assign_(first, last, traits_t::iterator_category());
00290 # elif defined(STLSOFT_COMPILER_IS_MWERKS) || \
00291 defined(STLSOFT_COMPILER_IS_DMC)
00292 return assign_(first, last, stlsoft_iterator_query_category_ptr(II, first));
00293 # else
00294 return assign_(first, last, stlsoft_iterator_query_category(II, first));
00295 # endif
00296 }
00297 #endif
00298
00300 class_type const& operator =(class_type const& rhs);
00302 class_type const& operator =(char_type const* s);
00304 class_type const& operator =(char_type ch);
00306
00309 public:
00311 class_type& append(char_type const* s);
00313 class_type& append(char_type const* s, size_type cch);
00315 class_type& append(class_type const& str, size_type pos, size_type cch);
00317 class_type& append(class_type const& str);
00319 class_type& append(size_type cch, char_type ch);
00321 #if !defined(STLSOFT_CF_MEMBER_TEMPLATE_RANGE_METHOD_SUPPORT)
00322 class_type& append(const_iterator first, const_iterator last);
00323 #else
00324 template <ss_typename_param_k II>
00325 class_type& append(II first, II last)
00326 {
00327 # if defined(STLSOFT_COMPILER_IS_GCC) && \
00328 __GNUC__ < 3
00329 typedef ss_typename_type_k std::iterator_traits<II> traits_t;
00330
00331 return append_(first, last, traits_t::iterator_category());
00332 # elif defined(STLSOFT_COMPILER_IS_MWERKS) || \
00333 defined(STLSOFT_COMPILER_IS_DMC)
00334 return append_(first, last, stlsoft_iterator_query_category_ptr(II, first));
00335 # else
00336 return append_(first, last, stlsoft_iterator_query_category(II, first));
00337 # endif
00338 }
00339 #endif
00340
00342 class_type& operator +=(char_type ch);
00344 class_type& operator +=(char_type const* s);
00346 class_type& operator +=(class_type const& rhs);
00347
00349 void push_back(char_type ch);
00351 void pop_back();
00353
00356 public:
00358 void reserve(size_type n);
00360 void swap(class_type& other);
00361
00366 void resize(size_type n, value_type ch = value_type());
00367
00369 void clear();
00371
00374 public:
00376 size_type size() const;
00378 static size_type max_size();
00380 size_type length() const;
00382 size_type capacity() const;
00384 ss_bool_t empty() const;
00386
00389 public:
00391 ss_sint_t compare(size_type pos, size_type n, value_type const* s, size_type cchRhs) const;
00393 ss_sint_t compare(size_type pos, size_type n, value_type const* s) const;
00395 ss_sint_t compare(value_type const* s) const;
00397 ss_sint_t compare(size_type pos, size_type n, class_type const& rhs, size_type posRhs, size_type cchRhs) const;
00399 ss_sint_t compare(size_type pos, size_type n, class_type const& rhs) const;
00401 ss_sint_t compare(class_type const& rhs) const;
00403
00406 public:
00408 reference operator [](size_type index);
00410 const_reference operator [](size_type index) const;
00411
00412 #ifdef STLSOFT_CF_EXCEPTION_SUPPORT
00416 reference at(size_type index);
00420 const_reference at(size_type index) const;
00421 #endif
00422
00424 value_type const *c_str() const;
00426 value_type const *data() const;
00427
00429 size_type copy(value_type *dest, size_type cch_, size_type pos = 0) const;
00431
00434 public:
00438 const_iterator begin() const;
00442 const_iterator end() const;
00446 iterator begin();
00450 iterator end();
00451
00452 #if defined(STLSOFT_LF_BIDIRECTIONAL_ITERATOR_SUPPORT)
00456 const_reverse_iterator rbegin() const;
00460 const_reverse_iterator rend() const;
00464 reverse_iterator rbegin();
00468 reverse_iterator rend();
00469 #endif
00471
00474 private:
00475
00476 size_type length_() const;
00477
00478
00479 ss_bool_t is_valid() const;
00480
00481
00482 static ss_sint_t compare_(char_type const* lhs, size_type lhs_len, char_type const* rhs, size_type rhs_len);
00483
00484
00485 #if defined(STLSOFT_CF_MEMBER_TEMPLATE_RANGE_METHOD_SUPPORT)
00486 template <ss_typename_param_k II>
00487 # if defined(STLSOFT_COMPILER_IS_MWERKS) || \
00488 defined(STLSOFT_COMPILER_IS_DMC)
00489
00490 class_type& assign_(II first, II last, stlsoft_ns_qual_std(input_iterator_tag) const*)
00491 # else
00492 class_type& assign_(II first, II last, stlsoft_ns_qual_std(input_iterator_tag))
00493 # endif
00494 {
00495 stlsoft_ns_qual_std(copy)(first, last, stlsoft_ns_qual_std(back_inserter)(*this));
00496
00497 return *this;
00498 }
00499 template <ss_typename_param_k II>
00500 # if defined(STLSOFT_COMPILER_IS_MWERKS) || \
00501 defined(STLSOFT_COMPILER_IS_DMC)
00502
00503 class_type& assign_(II first, II last, stlsoft_ns_qual_std(forward_iterator_tag) const*)
00504 # else
00505 class_type& assign_(II first, II last, stlsoft_ns_qual_std(forward_iterator_tag))
00506 # endif
00507 {
00508 buffer_type_ buffer(static_cast<ss_size_t>(stlsoft_ns_qual_std(distance)(first, last)));
00509
00510 stlsoft_ns_qual_std(copy)(first, last, buffer.begin());
00511 assign(buffer.data(), buffer.size());
00512
00513 return *this;
00514 }
00515 #endif
00516
00517
00518 #if defined(STLSOFT_CF_MEMBER_TEMPLATE_RANGE_METHOD_SUPPORT)
00519 template <ss_typename_param_k II>
00520 # if defined(STLSOFT_COMPILER_IS_MWERKS) || \
00521 defined(STLSOFT_COMPILER_IS_DMC)
00522 class_type& append_(II first, II last, stlsoft_ns_qual_std(input_iterator_tag) const*)
00523 # else
00524 class_type& append_(II first, II last, stlsoft_ns_qual_std(input_iterator_tag))
00525 # endif
00526 {
00527 stlsoft_ns_qual_std(copy)(first, last, stlsoft_ns_qual_std(back_inserter)(*this));
00528
00529 STLSOFT_ASSERT(is_valid());
00530 return *this;
00531 }
00532 template <ss_typename_param_k II>
00533 # if defined(STLSOFT_COMPILER_IS_MWERKS) || \
00534 defined(STLSOFT_COMPILER_IS_DMC)
00535 class_type& append_(II first, II last, stlsoft_ns_qual_std(forward_iterator_tag) const*)
00536 # else
00537 class_type& append_(II first, II last, stlsoft_ns_qual_std(forward_iterator_tag))
00538 # endif
00539 {
00540 buffer_type_ buffer(static_cast<ss_size_t>(stlsoft_ns_qual_std(distance)(first, last)));
00541
00542 stlsoft_ns_qual_std(copy)(first, last, &buffer[0]);
00543 append(buffer.data(), buffer.size());
00544
00545 STLSOFT_ASSERT(is_valid());
00546 return *this;
00547 }
00548 #endif
00550
00553 private:
00554 value_type m_buffer[internalSize + 1];
00555 ss_size_t m_length;
00557 };
00558
00559
00560
00561
00562
00563 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
00564
00565
00566
00567 template< ss_typename_param_k C
00568 , ss_size_t CCH
00569 , ss_typename_param_k T
00570 >
00571 inline ss_bool_t operator ==(basic_static_string<C, CCH, T> const& lhs, basic_static_string<C, CCH, T> const& rhs)
00572 {
00573 #ifdef _DEBUG
00574
00575 #endif
00576
00577 return lhs.compare(rhs) == 0;
00578 }
00579
00580 template< ss_typename_param_k C
00581 , ss_size_t CCH
00582 , ss_typename_param_k T
00583 >
00584 #ifdef STLSOFT_CF_TEMPLATE_OUTOFCLASSFN_QUALIFIED_TYPE_SUPPORT
00585 inline ss_bool_t operator ==(basic_static_string<C, CCH, T> const& lhs, ss_typename_type_k basic_static_string<C, CCH, T>::char_type const* rhs)
00586 #else
00587 inline ss_bool_t operator ==(basic_static_string<C, CCH, T> const& lhs, C const* rhs)
00588 #endif
00589 {
00590 return lhs.compare(rhs) == 0;
00591 }
00592
00593 template< ss_typename_param_k C
00594 , ss_size_t CCH
00595 , ss_typename_param_k T
00596 >
00597 #ifdef STLSOFT_CF_TEMPLATE_OUTOFCLASSFN_QUALIFIED_TYPE_SUPPORT
00598 inline ss_bool_t operator ==(ss_typename_type_k basic_static_string<C, CCH, T>::char_type const* lhs, basic_static_string<C, CCH, T> const& rhs)
00599 #else
00600 inline ss_bool_t operator ==(C *lhs, basic_static_string<C, CCH, T> const& rhs)
00601 #endif
00602 {
00603 return rhs.compare(lhs) == 0;
00604 }
00605
00606
00607
00608 template< ss_typename_param_k C
00609 , ss_size_t CCH
00610 , ss_typename_param_k T
00611 >
00612 inline ss_bool_t operator !=(basic_static_string<C, CCH, T> const& lhs, basic_static_string<C, CCH, T> const& rhs)
00613 {
00614 return lhs.compare(rhs) != 0;
00615 }
00616 template< ss_typename_param_k C
00617 , ss_size_t CCH
00618 , ss_typename_param_k T
00619 >
00620 #ifdef STLSOFT_CF_TEMPLATE_OUTOFCLASSFN_QUALIFIED_TYPE_SUPPORT
00621 inline ss_bool_t operator !=(basic_static_string<C, CCH, T> const& lhs, ss_typename_type_k basic_static_string<C, CCH, T>::char_type const* rhs)
00622 #else
00623 inline ss_bool_t operator !=(basic_static_string<C, CCH, T> const& lhs, C const* rhs)
00624 #endif
00625 {
00626 return lhs.compare(rhs) != 0;
00627 }
00628 template< ss_typename_param_k C
00629 , ss_size_t CCH
00630 , ss_typename_param_k T
00631 >
00632 #ifdef STLSOFT_CF_TEMPLATE_OUTOFCLASSFN_QUALIFIED_TYPE_SUPPORT
00633 inline ss_bool_t operator !=(ss_typename_type_k basic_static_string<C, CCH, T>::char_type const* lhs, basic_static_string<C, CCH, T> const& rhs)
00634 #else
00635 inline ss_bool_t operator !=(C const* lhs, basic_static_string<C, CCH, T> const& rhs)
00636 #endif
00637 {
00638 return rhs.compare(lhs) != 0;
00639 }
00640
00641
00642
00643 template< ss_typename_param_k C
00644 , ss_size_t CCH
00645 , ss_typename_param_k T
00646 >
00647 inline ss_bool_t operator <(basic_static_string<C, CCH, T> const& lhs, basic_static_string<C, CCH, T> const& rhs)
00648 {
00649 return lhs.compare(rhs) < 0;
00650 }
00651
00652 template< ss_typename_param_k C
00653 , ss_size_t CCH
00654 , ss_typename_param_k T
00655 >
00656 #ifdef STLSOFT_CF_TEMPLATE_OUTOFCLASSFN_QUALIFIED_TYPE_SUPPORT
00657 inline ss_bool_t operator <(basic_static_string<C, CCH, T> const& lhs, ss_typename_type_k basic_static_string<C, CCH, T>::char_type const* rhs)
00658 #else
00659 inline ss_bool_t operator <(basic_static_string<C, CCH, T> const& lhs, C const* rhs)
00660 #endif
00661 {
00662 return lhs.compare(rhs) < 0;
00663 }
00664
00665 template< ss_typename_param_k C
00666 , ss_size_t CCH
00667 , ss_typename_param_k T
00668 >
00669 #ifdef STLSOFT_CF_TEMPLATE_OUTOFCLASSFN_QUALIFIED_TYPE_SUPPORT
00670 inline ss_bool_t operator <(ss_typename_type_k basic_static_string<C, CCH, T>::char_type const* lhs, basic_static_string<C, CCH, T> const& rhs)
00671 #else
00672 inline ss_bool_t operator <(C const* lhs, basic_static_string<C, CCH, T> const& rhs)
00673 #endif
00674 {
00675 return rhs.compare(lhs) > 0;
00676 }
00677
00678
00679
00680 template< ss_typename_param_k C
00681 , ss_size_t CCH
00682 , ss_typename_param_k T
00683 >
00684 inline ss_bool_t operator <=(basic_static_string<C, CCH, T> const& lhs, basic_static_string<C, CCH, T> const& rhs)
00685 {
00686 return lhs.compare(rhs) <= 0;
00687 }
00688 template< ss_typename_param_k C
00689 , ss_size_t CCH
00690 , ss_typename_param_k T
00691 >
00692 #ifdef STLSOFT_CF_TEMPLATE_OUTOFCLASSFN_QUALIFIED_TYPE_SUPPORT
00693 inline ss_bool_t operator <=(basic_static_string<C, CCH, T> const& lhs, ss_typename_type_k basic_static_string<C, CCH, T>::char_type const* rhs)
00694 #else
00695 inline ss_bool_t operator <=(basic_static_string<C, CCH, T> const& lhs, C const* rhs)
00696 #endif
00697 {
00698 return lhs.compare(rhs) <= 0;
00699 }
00700 template< ss_typename_param_k C
00701 , ss_size_t CCH
00702 , ss_typename_param_k T
00703 >
00704 #ifdef STLSOFT_CF_TEMPLATE_OUTOFCLASSFN_QUALIFIED_TYPE_SUPPORT
00705 inline ss_bool_t operator <=(ss_typename_type_k basic_static_string<C, CCH, T>::char_type const* lhs, basic_static_string<C, CCH, T> const& rhs)
00706 #else
00707 inline ss_bool_t operator <=(C const* lhs, basic_static_string<C, CCH, T> const& rhs)
00708 #endif
00709 {
00710 return rhs.compare(lhs) >= 0;
00711 }
00712
00713
00714
00715 template< ss_typename_param_k C
00716 , ss_size_t CCH
00717 , ss_typename_param_k T
00718 >
00719 inline ss_bool_t operator >(basic_static_string<C, CCH, T> const& lhs, basic_static_string<C, CCH, T> const& rhs)
00720 {
00721 return lhs.compare(rhs) > 0;
00722 }
00723 template< ss_typename_param_k C
00724 , ss_size_t CCH
00725 , ss_typename_param_k T
00726 >
00727 #ifdef STLSOFT_CF_TEMPLATE_OUTOFCLASSFN_QUALIFIED_TYPE_SUPPORT
00728 inline ss_bool_t operator >(basic_static_string<C, CCH, T> const& lhs, ss_typename_type_k basic_static_string<C, CCH, T>::char_type const* rhs)
00729 #else
00730 inline ss_bool_t operator >(basic_static_string<C, CCH, T> const& lhs, C const* rhs)
00731 #endif
00732 {
00733 return lhs.compare(rhs) > 0;
00734 }
00735 template< ss_typename_param_k C
00736 , ss_size_t CCH
00737 , ss_typename_param_k T
00738 >
00739 #ifdef STLSOFT_CF_TEMPLATE_OUTOFCLASSFN_QUALIFIED_TYPE_SUPPORT
00740 inline ss_bool_t operator >(ss_typename_type_k basic_static_string<C, CCH, T>::char_type const* lhs, basic_static_string<C, CCH, T> const& rhs)
00741 #else
00742 inline ss_bool_t operator >(C const* lhs, basic_static_string<C, CCH, T> const& rhs)
00743 #endif
00744 {
00745 return rhs.compare(lhs) < 0;
00746 }
00747
00748
00749
00750 template< ss_typename_param_k C
00751 , ss_size_t CCH
00752 , ss_typename_param_k T
00753 >
00754 inline ss_bool_t operator >=(basic_static_string<C, CCH, T> const& lhs, basic_static_string<C, CCH, T> const& rhs)
00755 {
00756 return lhs.compare(rhs) >= 0;
00757 }
00758 template< ss_typename_param_k C
00759 , ss_size_t CCH
00760 , ss_typename_param_k T
00761 >
00762 #ifdef STLSOFT_CF_TEMPLATE_OUTOFCLASSFN_QUALIFIED_TYPE_SUPPORT
00763 inline ss_bool_t operator >=(basic_static_string<C, CCH, T> const& lhs, ss_typename_type_k basic_static_string<C, CCH, T>::char_type const* rhs)
00764 #else
00765 inline ss_bool_t operator >=(basic_static_string<C, CCH, T> const& lhs, C const* rhs)
00766 #endif
00767 {
00768 return lhs.compare(rhs) >= 0;
00769 }
00770 template< ss_typename_param_k C
00771 , ss_size_t CCH
00772 , ss_typename_param_k T
00773 >
00774 #ifdef STLSOFT_CF_TEMPLATE_OUTOFCLASSFN_QUALIFIED_TYPE_SUPPORT
00775 inline ss_bool_t operator >=(ss_typename_type_k basic_static_string<C, CCH, T>::char_type const* lhs, basic_static_string<C, CCH, T> const& rhs)
00776 #else
00777 inline ss_bool_t operator >=(C const* lhs, basic_static_string<C, CCH, T> const& rhs)
00778 #endif
00779 {
00780 return rhs.compare(lhs) <= 0;
00781 }
00782
00783 #endif
00784
00785
00786
00787
00788
00789 template< ss_typename_param_k C
00790 , ss_size_t CCH
00791 , ss_typename_param_k T
00792 >
00793 inline void swap(basic_static_string<C, CCH, T>& lhs, basic_static_string<C, CCH, T>& rhs)
00794 {
00795 lhs.swap(rhs);
00796 }
00797
00798
00799
00800
00801
00802 #ifndef STLSOFT_CF_TEMPLATE_SHIMS_NOT_SUPPORTED
00803
00804
00805
00806 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
00807 template <ss_size_t CCH, ss_typename_param_k T >
00808 inline ss_char_a_t const* c_str_ptr_null_a(stlsoft_ns_qual(basic_static_string)<ss_char_a_t, CCH, T> const& s)
00809 {
00810 return (0 != s.length()) ? s.c_str() : NULL;
00811 }
00812 template <ss_size_t CCH, ss_typename_param_k T >
00813 inline ss_char_w_t const* c_str_ptr_null_w(stlsoft_ns_qual(basic_static_string)<ss_char_w_t, CCH, T> const& s)
00814 {
00815 return (0 != s.length()) ? s.c_str() : NULL;
00816 }
00817 #endif
00818
00823 template< ss_typename_param_k C
00824 , ss_size_t CCH
00825 , ss_typename_param_k T
00826 >
00827 inline C const* c_str_ptr_null(stlsoft_ns_qual(basic_static_string)<C, CCH, T> const& s)
00828 {
00829 return (0 != s.length()) ? s.c_str() : NULL;
00830 }
00831
00832
00833
00834 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
00835 template <ss_size_t CCH, ss_typename_param_k T >
00836 inline ss_char_a_t const* c_str_ptr_a(stlsoft_ns_qual(basic_static_string)<ss_char_a_t, CCH, T> const& s)
00837 {
00838 return s.c_str();
00839 }
00840 template <ss_size_t CCH, ss_typename_param_k T >
00841 inline ss_char_w_t const* c_str_ptr_w(stlsoft_ns_qual(basic_static_string)<ss_char_w_t, CCH, T> const& s)
00842 {
00843 return s.c_str();
00844 }
00845 #endif
00846
00851 template< ss_typename_param_k C
00852 , ss_size_t CCH
00853 , ss_typename_param_k T
00854 >
00855 inline C const* c_str_ptr(stlsoft_ns_qual(basic_static_string)<C, CCH, T> const& s)
00856 {
00857 return s.c_str();
00858 }
00859
00860
00861
00862 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
00863 template <ss_size_t CCH, ss_typename_param_k T >
00864 inline ss_char_a_t const* c_str_data_a(stlsoft_ns_qual(basic_static_string)<ss_char_a_t, CCH, T> const& s)
00865 {
00866 return s.data();
00867 }
00868 template <ss_size_t CCH, ss_typename_param_k T >
00869 inline ss_char_w_t const* c_str_data_w(stlsoft_ns_qual(basic_static_string)<ss_char_w_t, CCH, T> const& s)
00870 {
00871 return s.data();
00872 }
00873 #endif
00874
00879 template< ss_typename_param_k C
00880 , ss_size_t CCH
00881 , ss_typename_param_k T
00882 >
00883 inline C const* c_str_data(stlsoft_ns_qual(basic_static_string)<C, CCH, T> const& s)
00884 {
00885 return s.data();
00886 }
00887
00888
00889
00890 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
00891
00892 template <ss_size_t CCH, ss_typename_param_k T >
00893 inline ss_size_t c_str_len_a(stlsoft_ns_qual(basic_static_string)<ss_char_a_t, CCH, T> const& s)
00894 {
00895 return s.length();
00896 }
00897 template <ss_size_t CCH, ss_typename_param_k T >
00898 inline ss_size_t c_str_len_w(stlsoft_ns_qual(basic_static_string)<ss_char_w_t, CCH, T> const& s)
00899 {
00900 return s.length();
00901 }
00902
00903 #endif
00904
00909 template< ss_typename_param_k C
00910 , ss_size_t CCH
00911 , ss_typename_param_k T
00912 >
00913 inline ss_size_t c_str_len(stlsoft_ns_qual(basic_static_string)<C, CCH, T> const& s)
00914 {
00915 return s.length();
00916 }
00917
00918 #endif
00919
00920
00921
00926 template< ss_typename_param_k S
00927 , ss_typename_param_k C
00928 , ss_size_t CCH
00929 , ss_typename_param_k T
00930 >
00931 inline S& operator <<(S& s, stlsoft_ns_qual(basic_static_string)<C, CCH, T> const& str)
00932 {
00933 s << str.c_str();
00934
00935 return s;
00936 }
00937
00938
00939
00940
00941
00942 #ifdef STLSOFT_UNITTEST
00943 # include "./unittest/static_string_unittest_.h"
00944 #endif
00945
00946
00947
00948
00949
00950 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
00951
00952 template< ss_typename_param_k C
00953 , ss_size_t CCH
00954 , ss_typename_param_k T
00955 >
00956 inline ss_typename_type_ret_k basic_static_string<C, CCH, T>::size_type basic_static_string<C, CCH, T>::length_() const
00957 {
00958 if(m_length == static_cast<ss_size_t>(-1))
00959 {
00960 ss_size_t &_m_length = const_cast<class_type *>(this)->m_length;
00961
00962 _m_length = traits_type::length(m_buffer);
00963 }
00964
00965 return m_length;
00966 }
00967
00968 template< ss_typename_param_k C
00969 , ss_size_t CCH
00970 , ss_typename_param_k T
00971 >
00972 inline ss_bool_t basic_static_string<C, CCH, T>::is_valid() const
00973 {
00974 char_type const* b = &m_buffer[0];
00975 char_type const* const e = &m_buffer[STLSOFT_NUM_ELEMENTS(m_buffer) - 1];
00976
00977 for(; b != e && '\0' != *b; ++b)
00978 {}
00979
00980 if(b == e)
00981 {
00982 #ifdef STLSOFT_UNITTEST
00983 printf("%08x: string contents have been overwritten! Contents=[%*s]\n", static_cast<unsigned>(reinterpret_cast<ss_size_t>(this)), static_cast<int>(max_size()), &m_buffer[0]);
00984 #endif
00985
00986 return false;
00987 }
00988 else if(m_length != static_cast<ss_size_t>(-1) &&
00989 m_length > max_size())
00990 {
00991 #ifdef STLSOFT_UNITTEST
00992 printf("%08x: length (%ld) greater than maximum allowed (%ld)\n", static_cast<unsigned>(reinterpret_cast<ss_size_t>(this)), static_cast<long>(m_length), static_cast<long>(max_size()));
00993 #endif
00994
00995 return false;
00996 }
00997 else if(m_length != static_cast<ss_size_t>(-1) &&
00998 '\0' != m_buffer[m_length])
00999 {
01000 #ifdef STLSOFT_UNITTEST
01001 printf("%08x: string not nul-terminated at index (%ld); maximum allowed (%ld)\n", static_cast<unsigned>(reinterpret_cast<ss_size_t>(this)), static_cast<long>(m_length), static_cast<long>(max_size()));
01002 #endif
01003
01004 return false;
01005 }
01006
01007 return true;
01008 }
01009
01010 template< ss_typename_param_k C
01011 , ss_size_t CCH
01012 , ss_typename_param_k T
01013 >
01014 inline basic_static_string<C, CCH, T>::basic_static_string()
01015 : m_length(static_cast<ss_size_t>(-1))
01016 {
01017 m_buffer[0] = '\0';
01018 m_buffer[max_size()] = '\0';
01019
01020 STLSOFT_ASSERT(is_valid());
01021 }
01022
01023 template< ss_typename_param_k C
01024 , ss_size_t CCH
01025 , ss_typename_param_k T
01026 >
01027 inline basic_static_string<C, CCH, T>::basic_static_string(class_type const& rhs)
01028 : m_length(rhs.length())
01029 {
01030 traits_type::copy(m_buffer, rhs.m_buffer, rhs.length());
01031
01032 m_buffer[m_length] = '\0';
01033 m_buffer[max_size()] = '\0';
01034
01035 STLSOFT_ASSERT(is_valid());
01036
01037 #ifdef _DEBUG
01038
01039 #endif
01040 }
01041
01042 template< ss_typename_param_k C
01043 , ss_size_t CCH
01044 , ss_typename_param_k T
01045 >
01046 inline basic_static_string<C, CCH, T>::basic_static_string(class_type const& rhs, size_type pos)
01047 : m_length(rhs.length() - pos)
01048 {
01049 traits_type::copy(m_buffer, rhs.m_buffer + pos, m_length);
01050
01051 m_buffer[m_length] = '\0';
01052 m_buffer[max_size()] = '\0';
01053
01054 STLSOFT_ASSERT(is_valid());
01055 }
01056
01057 template< ss_typename_param_k C
01058 , ss_size_t CCH
01059 , ss_typename_param_k T
01060 >
01061 inline basic_static_string<C, CCH, T>::basic_static_string(class_type const& rhs, size_type pos, size_type n)
01062 : m_length(n)
01063 {
01064 STLSOFT_MESSAGE_ASSERT("incident string too large for static_string construction", !(max_size() < n));
01065
01066
01067 traits_type::copy(m_buffer, rhs.m_buffer + pos, n);
01068
01069 m_buffer[m_length] = '\0';
01070 m_buffer[max_size()] = '\0';
01071
01072 STLSOFT_ASSERT(is_valid());
01073 }
01074
01075 template< ss_typename_param_k C
01076 , ss_size_t CCH
01077 , ss_typename_param_k T
01078 >
01079 inline basic_static_string<C, CCH, T>::basic_static_string(char_type const* s)
01080 : m_length((NULL != s) ? traits_type::length(s) : 0)
01081 {
01082 STLSOFT_MESSAGE_ASSERT("incident string too large for static_string construction", !(max_size() < m_length));
01083
01084
01085
01086 traits_type::copy(m_buffer, s, m_length);
01087
01088 m_buffer[m_length] = '\0';
01089 m_buffer[max_size()] = '\0';
01090
01091 STLSOFT_ASSERT(is_valid());
01092 }
01093
01094 template< ss_typename_param_k C
01095 , ss_size_t CCH
01096 , ss_typename_param_k T
01097 >
01098 inline basic_static_string<C, CCH, T>::basic_static_string(char_type const* s, size_type n)
01099 : m_length(n)
01100 {
01101 STLSOFT_MESSAGE_ASSERT("incident string too large for static_string construction", !(max_size() < n));
01102
01103 traits_type::copy(m_buffer, s, n);
01104
01105 m_buffer[m_length] = '\0';
01106 m_buffer[max_size()] = '\0';
01107
01108 STLSOFT_ASSERT(is_valid());
01109 }
01110
01111 template< ss_typename_param_k C
01112 , ss_size_t CCH
01113 , ss_typename_param_k T
01114 >
01115 inline basic_static_string<C, CCH, T>::basic_static_string(size_type n, char_type c)
01116 : m_length(n)
01117 {
01118 traits_type::assign(m_buffer, n, c);
01119
01120 m_buffer[m_length] = '\0';
01121 m_buffer[max_size()] = '\0';
01122
01123 STLSOFT_ASSERT(is_valid());
01124 }
01125
01126 #if !defined(STLSOFT_CF_MEMBER_TEMPLATE_RANGE_METHOD_SUPPORT)
01127 template< ss_typename_param_k C
01128 , ss_size_t CCH
01129 , ss_typename_param_k T
01130 >
01131 inline basic_static_string<C, CCH, T>::basic_static_string(char_type const* f, char_type const* t)
01132 : m_length(t - f)
01133 {
01134 STLSOFT_MESSAGE_ASSERT("incident string too large for static_string construction", !(max_size() < m_length));
01135
01136 traits_type::copy(m_buffer, f, m_length);
01137
01138 m_buffer[m_length] = '\0';
01139 m_buffer[max_size()] = '\0';
01140
01141 STLSOFT_ASSERT(is_valid());
01142 }
01143 #endif
01144
01145 template< ss_typename_param_k C
01146 , ss_size_t CCH
01147 , ss_typename_param_k T
01148 >
01149 inline basic_static_string<C, CCH, T>::~basic_static_string() stlsoft_throw_0()
01150 {
01151 STLSOFT_ASSERT(is_valid());
01152 }
01153
01154
01155
01156
01157 template< ss_typename_param_k C
01158 , ss_size_t CCH
01159 , ss_typename_param_k T
01160 >
01161 inline ss_typename_type_ret_k basic_static_string<C, CCH, T>::class_type& basic_static_string<C, CCH, T>::assign(const ss_typename_type_k basic_static_string<C, CCH, T>::char_type *s)
01162 {
01163 STLSOFT_ASSERT(is_valid());
01164
01165 #if 0
01166 m_length = static_cast<ss_size_t>(-1);
01167 traits_type::copy(m_buffer, s, CCH);
01168 m_buffer[max_size()] = '\0';
01169 #else
01170 class_type t(s);
01171 t.swap(*this);
01172 #endif
01173
01174 STLSOFT_ASSERT(is_valid());
01175
01176 return *this;
01177 }
01178
01179 template< ss_typename_param_k C
01180 , ss_size_t CCH
01181 , ss_typename_param_k T
01182 >
01183 inline ss_typename_type_ret_k basic_static_string<C, CCH, T>::class_type& basic_static_string<C, CCH, T>::assign(const ss_typename_type_k basic_static_string<C, CCH, T>::char_type *s, ss_typename_type_k basic_static_string<C, CCH, T>::size_type n)
01184 {
01185 STLSOFT_MESSAGE_ASSERT("incident string too large for static_string assignment", !(max_size() < n));
01186
01187 STLSOFT_ASSERT(is_valid());
01188
01189 #if 0
01190 traits_type::copy(m_buffer, s, n);
01191
01192 m_length = n;
01193 m_buffer[m_length] = '\0';
01194 m_buffer[max_size()] = '\0';
01195 #else
01196 class_type t(s, n);
01197 t.swap(*this);
01198 #endif
01199
01200 STLSOFT_ASSERT(is_valid());
01201
01202 return *this;
01203 }
01204
01205 template< ss_typename_param_k C
01206 , ss_size_t CCH
01207 , ss_typename_param_k T
01208 >
01209 inline ss_typename_type_ret_k basic_static_string<C, CCH, T>::class_type& basic_static_string<C, CCH, T>::assign( ss_typename_type_k basic_static_string<C, CCH, T>::class_type const& rhs
01210 , ss_typename_type_k basic_static_string<C, CCH, T>::size_type pos
01211 , ss_typename_type_k basic_static_string<C, CCH, T>::size_type n)
01212 {
01213 STLSOFT_MESSAGE_ASSERT("incident string too large for static_string assignment", !(max_size() < n));
01214
01215 STLSOFT_ASSERT(is_valid());
01216
01217 #if 0
01218 traits_type::copy(m_buffer, rhs.m_buffer + pos, n);
01219
01220 m_length = n;
01221 m_buffer[m_length] = '\0';
01222 m_buffer[max_size()] = '\0';
01223 #else
01224 class_type t(rhs, pos, n);
01225 t.swap(*this);
01226 #endif
01227
01228 STLSOFT_ASSERT(is_valid());
01229
01230 return *this;
01231 }
01232
01233 template< ss_typename_param_k C
01234 , ss_size_t CCH
01235 , ss_typename_param_k T
01236 >
01237 inline ss_typename_type_ret_k basic_static_string<C, CCH, T>::class_type& basic_static_string<C, CCH, T>::assign(ss_typename_type_k basic_static_string<C, CCH, T>::class_type const& rhs)
01238 {
01239 STLSOFT_ASSERT(is_valid());
01240
01241
01242
01243 #ifdef _DEBUG
01244 const class_type result(rhs);
01245 #endif
01246
01247
01248
01249
01250
01251 class_type t(rhs);
01252
01253
01254
01255 t.swap(*this);
01256
01257
01258
01259
01260
01261
01262 #ifdef _DEBUG
01263
01264 STLSOFT_ASSERT(result == *this);
01265 #endif
01266
01267
01268
01269 STLSOFT_ASSERT(is_valid());
01270
01271
01272
01273 return *this;
01274 }
01275
01276 template< ss_typename_param_k C
01277 , ss_size_t CCH
01278 , ss_typename_param_k T
01279 >
01280 inline ss_typename_type_ret_k basic_static_string<C, CCH, T>::class_type& basic_static_string<C, CCH, T>::assign( ss_typename_type_k basic_static_string<C, CCH, T>::size_type n
01281 , ss_typename_type_k basic_static_string<C, CCH, T>::char_type c)
01282 {
01283 STLSOFT_MESSAGE_ASSERT("incident string too large for static_string assignment", !(max_size() < n));
01284
01285 STLSOFT_ASSERT(is_valid());
01286
01287 #if 0
01288 traits_type::assign(m_buffer, n, c);
01289
01290 m_length = n;
01291 m_buffer[m_length] = '\0';
01292 m_buffer[max_size()] = '\0';
01293 #else
01294 class_type t(n, c);
01295 t.swap(*this);
01296 #endif
01297
01298 STLSOFT_ASSERT(is_valid());
01299
01300 return *this;
01301 }
01302
01303 #if !defined(STLSOFT_CF_MEMBER_TEMPLATE_RANGE_METHOD_SUPPORT)
01304 template< ss_typename_param_k C
01305 , ss_size_t CCH
01306 , ss_typename_param_k T
01307 >
01308 inline ss_typename_type_ret_k basic_static_string<C, CCH, T>::class_type& basic_static_string<C, CCH, T>::assign(ss_typename_type_k basic_static_string<C, CCH, T>::const_iterator first, ss_typename_type_k basic_static_string<C, CCH, T>::const_iterator last)
01309 {
01310 STLSOFT_ASSERT(is_valid());
01311
01312
01313
01314 return assign(&(*first), last - first);
01315 }
01316 #endif
01317
01318 template< ss_typename_param_k C
01319 , ss_size_t CCH
01320 , ss_typename_param_k T
01321 >
01322 inline ss_typename_type_ret_k basic_static_string<C, CCH, T>::class_type const& basic_static_string<C, CCH, T>::operator =(ss_typename_type_k basic_static_string<C, CCH, T>::class_type const& rhs)
01323 {
01324 STLSOFT_ASSERT(is_valid());
01325
01326 return assign(rhs);
01327 }
01328
01329 template< ss_typename_param_k C
01330 , ss_size_t CCH
01331 , ss_typename_param_k T
01332 >
01333 inline ss_typename_type_ret_k basic_static_string<C, CCH, T>::class_type const& basic_static_string<C, CCH, T>::operator =(ss_typename_type_k basic_static_string<C, CCH, T>::char_type const* s)
01334 {
01335 STLSOFT_ASSERT(is_valid());
01336
01337 return assign(s);
01338 }
01339
01340 template< ss_typename_param_k C
01341 , ss_size_t CCH
01342 , ss_typename_param_k T
01343 >
01344 inline ss_typename_type_ret_k basic_static_string<C, CCH, T>::class_type const& basic_static_string<C, CCH, T>::operator =(ss_typename_type_k basic_static_string<C, CCH, T>::char_type c)
01345 {
01346 STLSOFT_ASSERT(is_valid());
01347
01348 m_length = 1;
01349 m_buffer[0] = c;
01350 m_buffer[1] = c;
01351
01352 STLSOFT_ASSERT(is_valid());
01353
01354 return *this;
01355 }
01356
01357
01358 template< ss_typename_param_k C
01359 , ss_size_t CCH
01360 , ss_typename_param_k T
01361 >
01362 inline ss_typename_type_ret_k basic_static_string<C, CCH, T>::size_type basic_static_string<C, CCH, T>::size() const
01363 {
01364 return class_type::length();
01365 }
01366
01367 template< ss_typename_param_k C
01368 , ss_size_t CCH
01369 , ss_typename_param_k T
01370 >
01371 inline ss_typename_type_ret_k basic_static_string<C, CCH, T>::size_type basic_static_string<C, CCH, T>::max_size()
01372 {
01373 return internalSize;
01374 }
01375
01376 template< ss_typename_param_k C
01377 , ss_size_t CCH
01378 , ss_typename_param_k T
01379 >
01380 inline ss_typename_type_ret_k basic_static_string<C, CCH, T>::size_type basic_static_string<C, CCH, T>::length() const
01381 {
01382 STLSOFT_ASSERT(is_valid());
01383
01384 return length_();
01385 }
01386
01387 template< ss_typename_param_k C
01388 , ss_size_t CCH
01389 , ss_typename_param_k T
01390 >
01391 inline ss_typename_type_ret_k basic_static_string<C, CCH, T>::size_type basic_static_string<C, CCH, T>::capacity() const
01392 {
01393 STLSOFT_ASSERT(is_valid());
01394
01395 return class_type::max_size();
01396 }
01397
01398 template< ss_typename_param_k C
01399 , ss_size_t CCH
01400 , ss_typename_param_k T
01401 >
01402 inline ss_bool_t basic_static_string<C, CCH, T>::empty() const
01403 {
01404 STLSOFT_ASSERT(is_valid());
01405
01406 return m_buffer[0] == 0;
01407 }
01408
01409 template< ss_typename_param_k C
01410 , ss_size_t CCH
01411 , ss_typename_param_k T
01412 >
01413 inline ss_sint_t basic_static_string<C, CCH, T>::compare_( ss_typename_type_k basic_static_string<C, CCH, T>::value_type const* lhs
01414 , ss_typename_type_k basic_static_string<C, CCH, T>::size_type lhs_len
01415 , ss_typename_type_k basic_static_string<C, CCH, T>::value_type const* rhs
01416 , ss_typename_type_k basic_static_string<C, CCH, T>::size_type rhs_len)
01417 {
01418 size_type cmp_len = (lhs_len < rhs_len) ? lhs_len : rhs_len;
01419 ss_int_t result = traits_type::compare(lhs, rhs, cmp_len);
01420
01421 if(result == 0)
01422 {
01423 result = static_cast<ss_int_t>(lhs_len) - static_cast<ss_int_t>(rhs_len);
01424 }
01425
01426 #ifdef _DEBUG
01427
01428 #endif
01429
01430 return result;
01431 }
01432
01433 template< ss_typename_param_k C
01434 , ss_size_t CCH
01435 , ss_typename_param_k T
01436 >
01437 inline ss_sint_t basic_static_string<C, CCH, T>::compare(ss_typename_type_k basic_static_string<C, CCH, T>::size_type pos, ss_typename_type_k basic_static_string<C, CCH, T>::size_type cch, ss_typename_type_k basic_static_string<C, CCH, T>::value_type const* s, ss_typename_type_k basic_static_string<C, CCH, T>::size_type cchRhs) const
01438 {
01439 STLSOFT_ASSERT(is_valid());
01440
01441 size_type lhs_len = length();
01442
01443 if(!(pos < lhs_len))
01444 {
01445 pos = lhs_len;
01446 }
01447 else
01448 {
01449 lhs_len -= pos;
01450 }
01451
01452 if(cch < lhs_len)
01453 {
01454 lhs_len = cch;
01455 }
01456
01457 size_type rhs_len = (s == 0) ? 0 : traits_type::length(s);
01458
01459 if(cchRhs < rhs_len)
01460 {
01461 rhs_len = cchRhs;
01462 }
01463
01464 STLSOFT_ASSERT(is_valid());
01465
01466 return compare_(m_buffer + pos, lhs_len, s, rhs_len);
01467 }
01468
01469 template< ss_typename_param_k C
01470 , ss_size_t CCH
01471 , ss_typename_param_k T
01472 >
01473 inline ss_sint_t basic_static_string<C, CCH, T>::compare(ss_typename_type_k basic_static_string<C, CCH, T>::size_type pos, ss_typename_type_k basic_static_string<C, CCH, T>::size_type cch, ss_typename_type_k basic_static_string<C, CCH, T>::value_type const* s) const
01474 {
01475 STLSOFT_ASSERT(is_valid());
01476
01477 size_type lhs_len = length();
01478
01479 if(!(pos < lhs_len))
01480 {
01481 pos = lhs_len;
01482 }
01483 else
01484 {
01485 lhs_len -= pos;
01486 }
01487
01488 if(cch < lhs_len)
01489 {
01490 lhs_len = cch;
01491 }
01492
01493 size_type rhs_len = (s == 0) ? 0 : traits_type::length(s);
01494
01495 STLSOFT_ASSERT(is_valid());
01496
01497 return compare_(m_buffer + pos, lhs_len, s, rhs_len);
01498 }
01499
01500 template< ss_typename_param_k C
01501 , ss_size_t CCH
01502 , ss_typename_param_k T
01503 >
01504 inline ss_sint_t basic_static_string<C, CCH, T>::compare(ss_typename_type_k basic_static_string<C, CCH, T>::value_type const* s) const
01505 {
01506 STLSOFT_ASSERT(is_valid());
01507
01508 size_type lhs_len = length();
01509 size_type rhs_len = (s == 0) ? 0 : traits_type::length(s);
01510
01511 STLSOFT_ASSERT(is_valid());
01512
01513 return compare_(m_buffer, lhs_len, s, rhs_len);
01514 }
01515
01516 template< ss_typename_param_k C
01517 , ss_size_t CCH
01518 , ss_typename_param_k T
01519 >
01520 inline ss_sint_t basic_static_string<C, CCH, T>::compare(ss_typename_type_k basic_static_string<C, CCH, T>::size_type pos, ss_typename_type_k basic_static_string<C, CCH, T>::size_type cch, ss_typename_type_k basic_static_string<C, CCH, T>::class_type const& rhs, ss_typename_type_k basic_static_string<C, CCH, T>::size_type posRhs, ss_typename_type_k basic_static_string<C, CCH, T>::size_type cchRhs) const
01521 {
01522 STLSOFT_ASSERT(is_valid());
01523
01524 size_type lhs_len = length();
01525
01526 if(!(pos < lhs_len))
01527 {
01528 pos = lhs_len;
01529 }
01530 else
01531 {
01532 lhs_len -= pos;
01533 }
01534
01535 if(cch < lhs_len)
01536 {
01537 lhs_len = cch;
01538 }
01539
01540 size_type rhs_len = rhs.length();
01541
01542 if(!(posRhs < rhs_len))
01543 {
01544 posRhs = rhs_len;
01545 }
01546 else
01547 {
01548 rhs_len -= posRhs;
01549 }
01550
01551 if(cchRhs < rhs_len)
01552 {
01553 rhs_len = cchRhs;
01554 }
01555
01556 STLSOFT_ASSERT(is_valid());
01557
01558 return compare_(m_buffer + pos, lhs_len, rhs.m_buffer + posRhs, rhs_len);
01559 }
01560
01561 template< ss_typename_param_k C
01562 , ss_size_t CCH
01563 , ss_typename_param_k T
01564 >
01565 inline ss_sint_t basic_static_string<C, CCH, T>::compare(ss_typename_type_k basic_static_string<C, CCH, T>::size_type pos, ss_typename_type_k basic_static_string<C, CCH, T>::size_type cch, ss_typename_type_k basic_static_string<C, CCH, T>::class_type const& rhs) const
01566 {
01567 STLSOFT_ASSERT(is_valid());
01568
01569 size_type lhs_len = length();
01570
01571 if(!(pos < lhs_len))
01572 {
01573 pos = lhs_len;
01574 }
01575 else
01576 {
01577 lhs_len -= pos;
01578 }
01579
01580 if(cch < lhs_len)
01581 {
01582 lhs_len = cch;
01583 }
01584
01585 size_type rhs_len = rhs.length();
01586
01587 STLSOFT_ASSERT(is_valid());
01588
01589 return compare_(m_buffer + pos, lhs_len, rhs.m_buffer, rhs_len);
01590 }
01591
01592 template< ss_typename_param_k C
01593 , ss_size_t CCH
01594 , ss_typename_param_k T
01595 >
01596 inline ss_sint_t basic_static_string<C, CCH, T>::compare(ss_typename_type_k basic_static_string<C, CCH, T>::class_type const& rhs) const
01597 {
01598 STLSOFT_ASSERT(is_valid());
01599
01600 size_type lhs_len = length();
01601 size_type rhs_len = rhs.length();
01602
01603 STLSOFT_ASSERT(is_valid());
01604
01605 #ifdef _DEBUG
01606
01607 #endif
01608
01609 return compare_(&m_buffer[0], lhs_len, &rhs.m_buffer[0], rhs_len);
01610 }
01611
01612
01613 template< ss_typename_param_k C
01614 , ss_size_t CCH
01615 , ss_typename_param_k T
01616 >
01617 inline void basic_static_string<C, CCH, T>::resize( ss_typename_type_k basic_static_string<C, CCH, T>::size_type n
01618 , ss_typename_type_k basic_static_string<C, CCH, T>::value_type ch )
01619 {
01620 STLSOFT_MESSAGE_ASSERT("resize request too large for static_string", !(max_size() < n));
01621
01622 STLSOFT_ASSERT(is_valid());
01623
01624 size_type const len = length();
01625
01626 if(len != n)
01627 {
01628 if(len < n)
01629 {
01630 traits_type::assign(m_buffer + len, n - len, ch);
01631 }
01632
01633 m_length = n;
01634 m_buffer[n] = 0;
01635 }
01636
01637 STLSOFT_ASSERT(is_valid());
01638 }
01639
01640 template< ss_typename_param_k C
01641 , ss_size_t CCH
01642 , ss_typename_param_k T
01643 >
01644 inline void basic_static_string<C, CCH, T>::clear()
01645 {
01646 STLSOFT_ASSERT(is_valid());
01647
01648 m_length = static_cast<ss_size_t>(-1);
01649 m_buffer[0] = 0;
01650
01651 STLSOFT_ASSERT(is_valid());
01652 }
01653
01654 template< ss_typename_param_k C
01655 , ss_size_t CCH
01656 , ss_typename_param_k T
01657 >
01658 inline ss_typename_type_ret_k basic_static_string<C, CCH, T>::reference basic_static_string<C, CCH, T>::operator [](ss_typename_type_k basic_static_string<C, CCH, T>::size_type index)
01659 {
01660 STLSOFT_MESSAGE_ASSERT("index access out of range in static_string", index < size());
01661
01662 STLSOFT_ASSERT(is_valid());
01663
01664 return m_buffer[index];
01665 }
01666
01667 template< ss_typename_param_k C
01668 , ss_size_t CCH
01669 , ss_typename_param_k T
01670 >
01671 inline ss_typename_type_ret_k basic_static_string<C, CCH, T>::const_reference basic_static_string<C, CCH, T>::operator [](ss_typename_type_k basic_static_string<C, CCH, T>::size_type index) const
01672 {
01673 STLSOFT_MESSAGE_ASSERT("index access out of range in static_string", index < size() + 1);
01674
01675 STLSOFT_ASSERT(is_valid());
01676
01677 return m_buffer[index];
01678 }
01679
01680
01681 #ifdef STLSOFT_CF_EXCEPTION_SUPPORT
01682 template< ss_typename_param_k C
01683 , ss_size_t CCH
01684 , ss_typename_param_k T
01685 >
01686 inline ss_typename_type_ret_k basic_static_string<C, CCH, T>::reference basic_static_string<C, CCH, T>::at(ss_typename_type_k basic_static_string<C, CCH, T>::size_type index)
01687 {
01688 STLSOFT_ASSERT(is_valid());
01689
01690 if(index >= size())
01691 {
01692 STLSOFT_THROW_X(stlsoft_ns_qual_std(out_of_range)("index out of range"));
01693 }
01694
01695 STLSOFT_ASSERT(is_valid());
01696
01697 return m_buffer[index];
01698 }
01699
01700 template< ss_typename_param_k C
01701 , ss_size_t CCH
01702 , ss_typename_param_k T
01703 >
01704 inline ss_typename_type_ret_k basic_static_string<C, CCH, T>::const_reference basic_static_string<C, CCH, T>::at(ss_typename_type_k basic_static_string<C, CCH, T>::size_type index) const
01705 {
01706 STLSOFT_ASSERT(is_valid());
01707
01708 if(index > size())
01709 {
01710 STLSOFT_THROW_X(stlsoft_ns_qual_std(out_of_range)("index out of range"));
01711 }
01712
01713 STLSOFT_ASSERT(is_valid());
01714
01715 return m_buffer[index];
01716 }
01717 #endif
01718
01719
01720 template< ss_typename_param_k C
01721 , ss_size_t CCH
01722 , ss_typename_param_k T
01723 >
01724 inline ss_typename_type_ret_k basic_static_string<C, CCH, T>::value_type const* basic_static_string<C, CCH, T>::c_str() const
01725 {
01726 STLSOFT_ASSERT(is_valid());
01727
01728 return m_buffer;
01729 }
01730
01731
01732
01733 template< ss_typename_param_k C
01734 , ss_size_t CCH
01735 , ss_typename_param_k T
01736 >
01737 inline ss_typename_type_ret_k basic_static_string<C, CCH, T>::class_type& basic_static_string<C, CCH, T>::append( ss_typename_type_k basic_static_string<C, CCH, T>::char_type const* s
01738 , ss_typename_type_k basic_static_string<C, CCH, T>::size_type n)
01739 {
01740 STLSOFT_MESSAGE_ASSERT("resize request too large for static_string", !(max_size() < n + length()));
01741
01742 STLSOFT_ASSERT(is_valid());
01743
01744 if(0 != n)
01745 {
01746 traits_type::copy(m_buffer + m_length, s, n);
01747
01748 m_length += n;
01749 m_buffer[m_length] = 0;
01750 }
01751
01752 STLSOFT_ASSERT(is_valid());
01753
01754 return *this;
01755 }
01756
01757 template< ss_typename_param_k C
01758 , ss_size_t CCH
01759 , ss_typename_param_k T
01760 >
01761 inline ss_typename_type_ret_k basic_static_string<C, CCH, T>::class_type& basic_static_string<C, CCH, T>::append(ss_typename_type_k basic_static_string<C, CCH, T>::char_type const* s)
01762 {
01763 STLSOFT_ASSERT(is_valid());
01764
01765 return append(s, (NULL == s) ? 0 : traits_type::length(s));
01766 }
01767
01768 template< ss_typename_param_k C
01769 , ss_size_t CCH
01770 , ss_typename_param_k T
01771 >
01772 inline ss_typename_type_ret_k basic_static_string<C, CCH, T>::class_type& basic_static_string<C, CCH, T>::append( ss_typename_type_k basic_static_string<C, CCH, T>::class_type const& rhs
01773 , ss_typename_type_k basic_static_string<C, CCH, T>::size_type pos
01774 , ss_typename_type_k basic_static_string<C, CCH, T>::size_type cch)
01775 {
01776 STLSOFT_ASSERT(is_valid());
01777
01778 char_type const* s = rhs.m_buffer;
01779 size_type len = rhs.length();
01780
01781 if(len < pos)
01782 {
01783 pos = len;
01784 }
01785
01786 if(len - pos < cch)
01787 {
01788 cch = len - pos;
01789 }
01790
01791 if(NULL != s)
01792 {
01793 s += pos;
01794 }
01795 else
01796 {
01797 cch = 0;
01798 }
01799
01800 STLSOFT_ASSERT(is_valid());
01801
01802 return append(s, cch);
01803 }
01804
01805 template< ss_typename_param_k C
01806 , ss_size_t CCH
01807 , ss_typename_param_k T
01808 >
01809 inline ss_typename_type_ret_k basic_static_string<C, CCH, T>::class_type& basic_static_string<C, CCH, T>::append(ss_typename_type_k basic_static_string<C, CCH, T>::class_type const& s)
01810 {
01811 STLSOFT_ASSERT(is_valid());
01812
01813 return append(s.m_buffer, s.length());
01814 }
01815
01816 template< ss_typename_param_k C
01817 , ss_size_t CCH
01818 , ss_typename_param_k T
01819 >
01820 inline ss_typename_type_ret_k basic_static_string<C, CCH, T>::class_type& basic_static_string<C, CCH, T>::append( ss_typename_type_k basic_static_string<C, CCH, T>::size_type n
01821 , ss_typename_type_k basic_static_string<C, CCH, T>::char_type ch)
01822 {
01823 STLSOFT_MESSAGE_ASSERT("resize request too large for static_string", !(max_size() < n + length()));
01824
01825
01826
01827 STLSOFT_ASSERT(is_valid());
01828
01829 if(0 != n)
01830 {
01831 traits_type::assign(m_buffer + m_length, n, ch);
01832
01833 m_length += n;
01834 m_buffer[m_length] = 0;
01835 }
01836
01837
01838
01839 STLSOFT_ASSERT(is_valid());
01840
01841 return *this;
01842 }
01843
01844 #if !defined(STLSOFT_CF_MEMBER_TEMPLATE_RANGE_METHOD_SUPPORT)
01845 template< ss_typename_param_k C
01846 , ss_size_t CCH
01847 , ss_typename_param_k T
01848 >
01849 inline ss_typename_type_ret_k basic_static_string<C, CCH, T>::class_type& basic_static_string<C, CCH, T>::append( ss_typename_type_k basic_static_string<C, CCH, T>::const_iterator first
01850 , ss_typename_type_k basic_static_string<C, CCH, T>::const_iterator last)
01851 {
01852 STLSOFT_ASSERT(is_valid());
01853
01854
01855
01856 return append(&(*first), last - first);
01857 }
01858 #endif
01859
01860 template< ss_typename_param_k C
01861 , ss_size_t CCH
01862 , ss_typename_param_k T
01863 >
01864 inline ss_typename_type_ret_k basic_static_string<C, CCH, T>::class_type& basic_static_string<C, CCH, T>::operator +=(ss_typename_type_k basic_static_string<C, CCH, T>::char_type ch)
01865 {
01866 STLSOFT_ASSERT(is_valid());
01867
01868 return append(1, ch);
01869 }
01870
01871 template< ss_typename_param_k C
01872 , ss_size_t CCH
01873 , ss_typename_param_k T
01874 >
01875 inline ss_typename_type_ret_k basic_static_string<C, CCH, T>::class_type& basic_static_string<C, CCH, T>::operator +=(const ss_typename_type_k basic_static_string<C, CCH, T>::char_type *s)
01876 {
01877 STLSOFT_ASSERT(is_valid());
01878
01879 return append(s);
01880 }
01881
01882 template< ss_typename_param_k C
01883 , ss_size_t CCH
01884 , ss_typename_param_k T
01885 >
01886 inline ss_typename_type_ret_k basic_static_string<C, CCH, T>::class_type& basic_static_string<C, CCH, T>::operator +=(const ss_typename_type_k basic_static_string<C, CCH, T>::class_type& rhs)
01887 {
01888 STLSOFT_ASSERT(is_valid());
01889
01890 return append(rhs);
01891 }
01892
01893 template< ss_typename_param_k C
01894 , ss_size_t CCH
01895 , ss_typename_param_k T
01896 >
01897 inline void basic_static_string<C, CCH, T>::push_back(ss_typename_type_k basic_static_string<C, CCH, T>::char_type ch)
01898 {
01899 STLSOFT_ASSERT(is_valid());
01900
01901 append(1, ch);
01902 }
01903
01904 template< ss_typename_param_k C
01905 , ss_size_t CCH
01906 , ss_typename_param_k T
01907 >
01908 inline void basic_static_string<C, CCH, T>::pop_back()
01909 {
01910 STLSOFT_ASSERT(is_valid());
01911
01912 if (m_length != 0) {
01913 m_buffer[--m_length] = 0;
01914 }
01915
01916 }
01917
01918 template< ss_typename_param_k C
01919 , ss_size_t CCH
01920 , ss_typename_param_k T
01921 >
01922 inline void basic_static_string<C, CCH, T>::reserve(ss_typename_type_k basic_static_string<C, CCH, T>::size_type n)
01923 {
01924 STLSOFT_ASSERT(is_valid());
01925
01926 STLSOFT_MESSAGE_ASSERT("reserve request out of range in static_string", !(max_size() < n));
01927
01928 STLSOFT_SUPPRESS_UNUSED(n);
01929 }
01930
01931 template< ss_typename_param_k C
01932 , ss_size_t CCH
01933 , ss_typename_param_k T
01934 >
01935 inline void basic_static_string<C, CCH, T>::swap(ss_typename_type_k basic_static_string<C, CCH, T>::class_type& other)
01936 {
01937
01938
01939 STLSOFT_ASSERT(is_valid());
01940
01941
01942
01943 value_type buffer[internalSize];
01944
01945
01946
01947 traits_type::copy( buffer, other.m_buffer, 1 + other.m_length);
01948 traits_type::copy(other.m_buffer, m_buffer, 1 + m_length);
01949 traits_type::copy( m_buffer, buffer, 1 + other.m_length);
01950
01951
01952
01953 std_swap(m_length, other.m_length);
01954
01955
01956
01957 STLSOFT_ASSERT(is_valid());
01958 }
01959
01960 template< ss_typename_param_k C
01961 , ss_size_t CCH
01962 , ss_typename_param_k T
01963 >
01964 inline ss_typename_type_ret_k basic_static_string<C, CCH, T>::value_type const* basic_static_string<C, CCH, T>::data() const
01965 {
01966 STLSOFT_ASSERT(is_valid());
01967
01968 return m_buffer;
01969 }
01970
01971 template< ss_typename_param_k C
01972 , ss_size_t CCH
01973 , ss_typename_param_k T
01974 >
01975 inline ss_typename_type_ret_k basic_static_string<C, CCH, T>::size_type basic_static_string<C, CCH, T>::copy(ss_typename_type_k basic_static_string<C, CCH, T>::value_type *dest, ss_typename_type_k basic_static_string<C, CCH, T>::size_type cch_, ss_typename_type_k basic_static_string<C, CCH, T>::size_type pos ) const
01976 {
01977 STLSOFT_ASSERT(is_valid());
01978
01979 size_type len = length();
01980
01981 if(pos < len)
01982 {
01983 if(len < pos + cch_)
01984 {
01985 cch_ = len - pos;
01986 }
01987
01988 traits_type::copy(dest, data() + pos, cch_);
01989 }
01990 else
01991 {
01992 cch_ = 0;
01993 }
01994
01995 STLSOFT_ASSERT(is_valid());
01996
01997 return cch_;
01998 }
01999
02000 template< ss_typename_param_k C
02001 , ss_size_t CCH
02002 , ss_typename_param_k T
02003 >
02004 inline ss_typename_type_ret_k basic_static_string<C, CCH, T>::const_iterator basic_static_string<C, CCH, T>::begin() const
02005 {
02006 STLSOFT_ASSERT(is_valid());
02007
02008 return m_buffer;
02009 }
02010
02011 template< ss_typename_param_k C
02012 , ss_size_t CCH
02013 , ss_typename_param_k T
02014 >
02015 inline ss_typename_type_ret_k basic_static_string<C, CCH, T>::const_iterator basic_static_string<C, CCH, T>::end() const
02016 {
02017 STLSOFT_ASSERT(is_valid());
02018
02019 return m_buffer + length_();
02020 }
02021
02022 template< ss_typename_param_k C
02023 , ss_size_t CCH
02024 , ss_typename_param_k T
02025 >
02026 inline ss_typename_type_ret_k basic_static_string<C, CCH, T>::iterator basic_static_string<C, CCH, T>::begin()
02027 {
02028 STLSOFT_ASSERT(is_valid());
02029
02030 return m_buffer;
02031 }
02032
02033 template< ss_typename_param_k C
02034 , ss_size_t CCH
02035 , ss_typename_param_k T
02036 >
02037 inline ss_typename_type_ret_k basic_static_string<C, CCH, T>::iterator basic_static_string<C, CCH, T>::end()
02038 {
02039 STLSOFT_ASSERT(is_valid());
02040
02041 return m_buffer + length_();
02042 }
02043
02044
02045 #if defined(STLSOFT_LF_BIDIRECTIONAL_ITERATOR_SUPPORT)
02046 template< ss_typename_param_k C
02047 , ss_size_t CCH
02048 , ss_typename_param_k T
02049 >
02050 inline ss_typename_type_ret_k basic_static_string<C, CCH, T>::const_reverse_iterator basic_static_string<C, CCH, T>::rbegin() const
02051 {
02052 STLSOFT_ASSERT(is_valid());
02053
02054 return const_reverse_iterator(end());
02055 }
02056
02057 template< ss_typename_param_k C
02058 , ss_size_t CCH
02059 , ss_typename_param_k T
02060 >
02061 inline ss_typename_type_ret_k basic_static_string<C, CCH, T>::const_reverse_iterator basic_static_string<C, CCH, T>::rend() const
02062 {
02063 STLSOFT_ASSERT(is_valid());
02064
02065 return const_reverse_iterator(begin());
02066 }
02067
02068 template< ss_typename_param_k C
02069 , ss_size_t CCH
02070 , ss_typename_param_k T
02071 >
02072 inline ss_typename_type_ret_k basic_static_string<C, CCH, T>::reverse_iterator basic_static_string<C, CCH, T>::rbegin()
02073 {
02074 STLSOFT_ASSERT(is_valid());
02075
02076 return reverse_iterator(end());
02077 }
02078
02079 template< ss_typename_param_k C
02080 , ss_size_t CCH
02081 , ss_typename_param_k T
02082 >
02083 inline ss_typename_type_ret_k basic_static_string<C, CCH, T>::reverse_iterator basic_static_string<C, CCH, T>::rend()
02084 {
02085 STLSOFT_ASSERT(is_valid());
02086
02087 return reverse_iterator(begin());
02088 }
02089 #endif
02090
02091 #endif
02092
02093
02094
02095 #ifndef _STLSOFT_NO_NAMESPACE
02096 }
02097 #endif
02098
02099
02100
02101
02102 #if defined(STLSOFT_CF_std_NAMESPACE)
02103 # if ( ( defined(STLSOFT_COMPILER_IS_INTEL) && \
02104 defined(_MSC_VER))) && \
02105 _MSC_VER < 1310
02106 namespace std
02107 {
02108 template< ss_typename_param_k C
02109 , stlsoft_ns_qual(ss_size_t) CCH
02110 , ss_typename_param_k T
02111 >
02112 inline void swap(stlsoft_ns_qual(basic_static_string)<C, CCH, T>& lhs, stlsoft_ns_qual(basic_static_string)<C, CCH, T>& rhs)
02113 {
02114 lhs.swap(rhs);
02115 }
02116 }
02117 # endif
02118 #endif
02119
02120
02121
02122 #endif
02123
02124