1 // Versatile string utility -*- C++ -*-
3 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010
4 // Free Software Foundation, Inc.
6 // This file is part of the GNU ISO C++ Library. This library is free
7 // software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the
9 // Free Software Foundation; either version 3, or (at your option)
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // Under Section 7 of GPL version 3, you are granted additional
18 // permissions described in the GCC Runtime Library Exception, version
19 // 3.1, as published by the Free Software Foundation.
21 // You should have received a copy of the GNU General Public License and
22 // a copy of the GCC Runtime Library Exception along with this program;
23 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24 // <http://www.gnu.org/licenses/>.
26 /** @file ext/vstring_util.h
27 * This is an internal header file, included by other library headers.
28 * Do not attempt to use it directly. @headername{ext/vstring.h}
31 #ifndef _VSTRING_UTIL_H
32 #define _VSTRING_UTIL_H 1
34 #pragma GCC system_header
36 #include <ext/vstring_fwd.h>
37 #include <debug/debug.h>
38 #include <bits/stl_function.h> // For less
39 #include <bits/functexcept.h>
40 #include <bits/localefwd.h>
41 #include <bits/ostream_insert.h>
42 #include <bits/stl_iterator.h>
43 #include <ext/numeric_traits.h>
44 #include <bits/move.h>
45 #include <bits/range_access.h>
47 _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx
)
49 template<typename _CharT
, typename _Traits
, typename _Alloc
>
50 struct __vstring_utility
52 typedef typename
_Alloc::template rebind
<_CharT
>::other _CharT_alloc_type
;
54 typedef _Traits traits_type
;
55 typedef typename
_Traits::char_type value_type
;
56 typedef typename
_CharT_alloc_type::size_type size_type
;
57 typedef typename
_CharT_alloc_type::difference_type difference_type
;
58 typedef typename
_CharT_alloc_type::pointer pointer
;
59 typedef typename
_CharT_alloc_type::const_pointer const_pointer
;
63 __normal_iterator
<pointer
, __gnu_cxx::
64 __versa_string
<_CharT
, _Traits
, _Alloc
,
68 __normal_iterator
<const_pointer
, __gnu_cxx::
69 __versa_string
<_CharT
, _Traits
, _Alloc
,
75 __normal_iterator
<pointer
, __gnu_cxx::
76 __versa_string
<_CharT
, _Traits
, _Alloc
,
80 __normal_iterator
<const_pointer
, __gnu_cxx::
81 __versa_string
<_CharT
, _Traits
, _Alloc
,
85 // NB: When the allocator is empty, deriving from it saves space
86 // (http://www.cantrip.org/emptyopt.html).
87 template<typename _Alloc1
>
91 _Alloc_hider(_CharT
* __ptr
)
92 : _Alloc1(), _M_p(__ptr
) { }
94 _Alloc_hider(const _Alloc1
& __a
, _CharT
* __ptr
)
95 : _Alloc1(__a
), _M_p(__ptr
) { }
97 _CharT
* _M_p
; // The actual data.
100 // When __n = 1 way faster than the general multichar
101 // traits_type::copy/move/assign.
103 _S_copy(_CharT
* __d
, const _CharT
* __s
, size_type __n
)
106 traits_type::assign(*__d
, *__s
);
108 traits_type::copy(__d
, __s
, __n
);
112 _S_move(_CharT
* __d
, const _CharT
* __s
, size_type __n
)
115 traits_type::assign(*__d
, *__s
);
117 traits_type::move(__d
, __s
, __n
);
121 _S_assign(_CharT
* __d
, size_type __n
, _CharT __c
)
124 traits_type::assign(*__d
, __c
);
126 traits_type::assign(__d
, __n
, __c
);
129 // _S_copy_chars is a separate template to permit specialization
130 // to optimize for the common case of pointers as iterators.
131 template<typename _Iterator
>
133 _S_copy_chars(_CharT
* __p
, _Iterator __k1
, _Iterator __k2
)
135 for (; __k1
!= __k2
; ++__k1
, ++__p
)
136 traits_type::assign(*__p
, *__k1
); // These types are off.
140 _S_copy_chars(_CharT
* __p
, __sso_iterator __k1
, __sso_iterator __k2
)
141 { _S_copy_chars(__p
, __k1
.base(), __k2
.base()); }
144 _S_copy_chars(_CharT
* __p
, __const_sso_iterator __k1
,
145 __const_sso_iterator __k2
)
146 { _S_copy_chars(__p
, __k1
.base(), __k2
.base()); }
149 _S_copy_chars(_CharT
* __p
, __rc_iterator __k1
, __rc_iterator __k2
)
150 { _S_copy_chars(__p
, __k1
.base(), __k2
.base()); }
153 _S_copy_chars(_CharT
* __p
, __const_rc_iterator __k1
,
154 __const_rc_iterator __k2
)
155 { _S_copy_chars(__p
, __k1
.base(), __k2
.base()); }
158 _S_copy_chars(_CharT
* __p
, _CharT
* __k1
, _CharT
* __k2
)
159 { _S_copy(__p
, __k1
, __k2
- __k1
); }
162 _S_copy_chars(_CharT
* __p
, const _CharT
* __k1
, const _CharT
* __k2
)
163 { _S_copy(__p
, __k1
, __k2
- __k1
); }
166 _S_compare(size_type __n1
, size_type __n2
)
168 const difference_type __d
= difference_type(__n1
- __n2
);
170 if (__d
> __numeric_traits_integer
<int>::__max
)
171 return __numeric_traits_integer
<int>::__max
;
172 else if (__d
< __numeric_traits_integer
<int>::__min
)
173 return __numeric_traits_integer
<int>::__min
;
179 _GLIBCXX_END_NAMESPACE
181 #endif /* _VSTRING_UTIL_H */