1*404b540aSrobert // Versatile string utility -*- C++ -*- 2*404b540aSrobert 3*404b540aSrobert // Copyright (C) 2005, 2006, 2007 Free Software Foundation, Inc. 4*404b540aSrobert // 5*404b540aSrobert // This file is part of the GNU ISO C++ Library. This library is free 6*404b540aSrobert // software; you can redistribute it and/or modify it under the 7*404b540aSrobert // terms of the GNU General Public License as published by the 8*404b540aSrobert // Free Software Foundation; either version 2, or (at your option) 9*404b540aSrobert // any later version. 10*404b540aSrobert 11*404b540aSrobert // This library is distributed in the hope that it will be useful, 12*404b540aSrobert // but WITHOUT ANY WARRANTY; without even the implied warranty of 13*404b540aSrobert // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14*404b540aSrobert // GNU General Public License for more details. 15*404b540aSrobert 16*404b540aSrobert // You should have received a copy of the GNU General Public License along 17*404b540aSrobert // with this library; see the file COPYING. If not, write to the Free 18*404b540aSrobert // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 19*404b540aSrobert // USA. 20*404b540aSrobert 21*404b540aSrobert // As a special exception, you may use this file as part of a free software 22*404b540aSrobert // library without restriction. Specifically, if other files instantiate 23*404b540aSrobert // templates or use macros or inline functions from this file, or you compile 24*404b540aSrobert // this file and link it with other files to produce an executable, this 25*404b540aSrobert // file does not by itself cause the resulting executable to be covered by 26*404b540aSrobert // the GNU General Public License. This exception does not however 27*404b540aSrobert // invalidate any other reasons why the executable file might be covered by 28*404b540aSrobert // the GNU General Public License. 29*404b540aSrobert 30*404b540aSrobert /** @file ext/vstring_util.h 31*404b540aSrobert * This file is a GNU extension to the Standard C++ Library. 32*404b540aSrobert * This is an internal header file, included by other library headers. 33*404b540aSrobert * You should not attempt to use it directly. 34*404b540aSrobert */ 35*404b540aSrobert 36*404b540aSrobert #ifndef _VSTRING_UTIL_H 37*404b540aSrobert #define _VSTRING_UTIL_H 1 38*404b540aSrobert 39*404b540aSrobert #pragma GCC system_header 40*404b540aSrobert 41*404b540aSrobert #include <ext/vstring_fwd.h> 42*404b540aSrobert #include <debug/debug.h> 43*404b540aSrobert #include <bits/stl_function.h> // For less 44*404b540aSrobert #include <bits/functexcept.h> 45*404b540aSrobert #include <locale> 46*404b540aSrobert #include <algorithm> // For std::distance, srd::search. 47*404b540aSrobert #include <bits/ostream_insert.h> 48*404b540aSrobert 49*404b540aSrobert _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx) 50*404b540aSrobert 51*404b540aSrobert template<typename _CharT, typename _Traits, typename _Alloc> 52*404b540aSrobert struct __vstring_utility 53*404b540aSrobert { 54*404b540aSrobert typedef typename _Alloc::template rebind<_CharT>::other _CharT_alloc_type; 55*404b540aSrobert 56*404b540aSrobert typedef _Traits traits_type; 57*404b540aSrobert typedef typename _Traits::char_type value_type; 58*404b540aSrobert typedef typename _CharT_alloc_type::size_type size_type; 59*404b540aSrobert typedef typename _CharT_alloc_type::pointer pointer; 60*404b540aSrobert typedef typename _CharT_alloc_type::const_pointer const_pointer; 61*404b540aSrobert 62*404b540aSrobert // For __sso_string. 63*404b540aSrobert typedef __gnu_cxx:: 64*404b540aSrobert __normal_iterator<pointer, __gnu_cxx:: 65*404b540aSrobert __versa_string<_CharT, _Traits, _Alloc, 66*404b540aSrobert __sso_string_base> > 67*404b540aSrobert __sso_iterator; 68*404b540aSrobert typedef __gnu_cxx:: 69*404b540aSrobert __normal_iterator<const_pointer, __gnu_cxx:: 70*404b540aSrobert __versa_string<_CharT, _Traits, _Alloc, 71*404b540aSrobert __sso_string_base> > 72*404b540aSrobert __const_sso_iterator; 73*404b540aSrobert 74*404b540aSrobert // For __rc_string. 75*404b540aSrobert typedef __gnu_cxx:: 76*404b540aSrobert __normal_iterator<pointer, __gnu_cxx:: 77*404b540aSrobert __versa_string<_CharT, _Traits, _Alloc, 78*404b540aSrobert __rc_string_base> > 79*404b540aSrobert __rc_iterator; 80*404b540aSrobert typedef __gnu_cxx:: 81*404b540aSrobert __normal_iterator<const_pointer, __gnu_cxx:: 82*404b540aSrobert __versa_string<_CharT, _Traits, _Alloc, 83*404b540aSrobert __rc_string_base> > 84*404b540aSrobert __const_rc_iterator; 85*404b540aSrobert 86*404b540aSrobert // NB: When the allocator is empty, deriving from it saves space 87*404b540aSrobert // (http://www.cantrip.org/emptyopt.html). 88*404b540aSrobert template<typename _Alloc1> 89*404b540aSrobert struct _Alloc_hider 90*404b540aSrobert : public _Alloc1 91*404b540aSrobert { _Alloc_hider__vstring_utility::_Alloc_hider92*404b540aSrobert _Alloc_hider(const _Alloc1& __a, _CharT* __ptr) 93*404b540aSrobert : _Alloc1(__a), _M_p(__ptr) { } 94*404b540aSrobert 95*404b540aSrobert _CharT* _M_p; // The actual data. 96*404b540aSrobert }; 97*404b540aSrobert 98*404b540aSrobert // For use in _M_construct (_S_construct) forward_iterator_tag. 99*404b540aSrobert template<typename _Type> 100*404b540aSrobert static bool _S_is_null_pointer__vstring_utility101*404b540aSrobert _S_is_null_pointer(_Type* __ptr) 102*404b540aSrobert { return __ptr == 0; } 103*404b540aSrobert 104*404b540aSrobert template<typename _Type> 105*404b540aSrobert static bool _S_is_null_pointer__vstring_utility106*404b540aSrobert _S_is_null_pointer(_Type) 107*404b540aSrobert { return false; } 108*404b540aSrobert 109*404b540aSrobert // When __n = 1 way faster than the general multichar 110*404b540aSrobert // traits_type::copy/move/assign. 111*404b540aSrobert static void _S_copy__vstring_utility112*404b540aSrobert _S_copy(_CharT* __d, const _CharT* __s, size_type __n) 113*404b540aSrobert { 114*404b540aSrobert if (__n == 1) 115*404b540aSrobert traits_type::assign(*__d, *__s); 116*404b540aSrobert else 117*404b540aSrobert traits_type::copy(__d, __s, __n); 118*404b540aSrobert } 119*404b540aSrobert 120*404b540aSrobert static void _S_move__vstring_utility121*404b540aSrobert _S_move(_CharT* __d, const _CharT* __s, size_type __n) 122*404b540aSrobert { 123*404b540aSrobert if (__n == 1) 124*404b540aSrobert traits_type::assign(*__d, *__s); 125*404b540aSrobert else 126*404b540aSrobert traits_type::move(__d, __s, __n); 127*404b540aSrobert } 128*404b540aSrobert 129*404b540aSrobert static void _S_assign__vstring_utility130*404b540aSrobert _S_assign(_CharT* __d, size_type __n, _CharT __c) 131*404b540aSrobert { 132*404b540aSrobert if (__n == 1) 133*404b540aSrobert traits_type::assign(*__d, __c); 134*404b540aSrobert else 135*404b540aSrobert traits_type::assign(__d, __n, __c); 136*404b540aSrobert } 137*404b540aSrobert 138*404b540aSrobert // _S_copy_chars is a separate template to permit specialization 139*404b540aSrobert // to optimize for the common case of pointers as iterators. 140*404b540aSrobert template<typename _Iterator> 141*404b540aSrobert static void _S_copy_chars__vstring_utility142*404b540aSrobert _S_copy_chars(_CharT* __p, _Iterator __k1, _Iterator __k2) 143*404b540aSrobert { 144*404b540aSrobert for (; __k1 != __k2; ++__k1, ++__p) 145*404b540aSrobert traits_type::assign(*__p, *__k1); // These types are off. 146*404b540aSrobert } 147*404b540aSrobert 148*404b540aSrobert static void _S_copy_chars__vstring_utility149*404b540aSrobert _S_copy_chars(_CharT* __p, __sso_iterator __k1, __sso_iterator __k2) 150*404b540aSrobert { _S_copy_chars(__p, __k1.base(), __k2.base()); } 151*404b540aSrobert 152*404b540aSrobert static void _S_copy_chars__vstring_utility153*404b540aSrobert _S_copy_chars(_CharT* __p, __const_sso_iterator __k1, 154*404b540aSrobert __const_sso_iterator __k2) 155*404b540aSrobert { _S_copy_chars(__p, __k1.base(), __k2.base()); } 156*404b540aSrobert 157*404b540aSrobert static void _S_copy_chars__vstring_utility158*404b540aSrobert _S_copy_chars(_CharT* __p, __rc_iterator __k1, __rc_iterator __k2) 159*404b540aSrobert { _S_copy_chars(__p, __k1.base(), __k2.base()); } 160*404b540aSrobert 161*404b540aSrobert static void _S_copy_chars__vstring_utility162*404b540aSrobert _S_copy_chars(_CharT* __p, __const_rc_iterator __k1, 163*404b540aSrobert __const_rc_iterator __k2) 164*404b540aSrobert { _S_copy_chars(__p, __k1.base(), __k2.base()); } 165*404b540aSrobert 166*404b540aSrobert static void _S_copy_chars__vstring_utility167*404b540aSrobert _S_copy_chars(_CharT* __p, _CharT* __k1, _CharT* __k2) 168*404b540aSrobert { _S_copy(__p, __k1, __k2 - __k1); } 169*404b540aSrobert 170*404b540aSrobert static void _S_copy_chars__vstring_utility171*404b540aSrobert _S_copy_chars(_CharT* __p, const _CharT* __k1, const _CharT* __k2) 172*404b540aSrobert { _S_copy(__p, __k1, __k2 - __k1); } 173*404b540aSrobert }; 174*404b540aSrobert 175*404b540aSrobert _GLIBCXX_END_NAMESPACE 176*404b540aSrobert 177*404b540aSrobert #endif /* _VSTRING_UTIL_H */ 178