Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
R
riscv-gcc-1
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
riscv-gcc-1
Commits
bdb0f0f5
Commit
bdb0f0f5
authored
Jun 20, 2003
by
Doug Gregor
Committed by
Doug Gregor
Jun 20, 2003
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix basic_string::replace for integral types
From-SVN: r68286
parent
49a2166f
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
54 additions
and
19 deletions
+54
-19
libstdc++-v3/ChangeLog
+12
-0
libstdc++-v3/include/bits/basic_string.h
+23
-3
libstdc++-v3/include/bits/basic_string.tcc
+16
-16
libstdc++-v3/testsuite/21_strings/basic_string/assign/char/1.cc
+3
-0
No files found.
libstdc++-v3/ChangeLog
View file @
bdb0f0f5
2003-06-20 Doug Gregor <dgregor@apple.com>
* include/bits/basic_string.h (basic_string::replace): Dispatch
_InputIterator version based on _Is_integer.
* include/bits/basic_string.tcc (basic_string::replace):
Renamed replace(iterator, iterator, size_type, _CharT) to
_M_replace_aux.
* testsuite/21_strings/basic_string/assign/char/1.cc (test01):
Test basic_string::assign(_InputIterator, _InputIterator),
which calls basic_string::replace(iterator, iterator,
_Input_iterator, _InputIterator).
2003-06-20 Benjamin Kosnik <bkoz@redhat.com>
* testsuite/testsuite_performance.h (resource_counter): Don't use
...
...
libstdc++-v3/include/bits/basic_string.h
View file @
bdb0f0f5
...
...
@@ -625,14 +625,15 @@ namespace std
{
return
this
->
replace
(
__i1
,
__i2
,
__s
,
traits_type
::
length
(
__s
));
}
basic_string
&
replace
(
iterator
__i1
,
iterator
__i2
,
size_type
__n
,
_CharT
__c
);
replace
(
iterator
__i1
,
iterator
__i2
,
size_type
__n
,
_CharT
__c
)
{
return
_M_replace_aux
(
__i1
,
__i2
,
__n
,
__c
);
}
template
<
class
_InputIterator
>
basic_string
&
replace
(
iterator
__i1
,
iterator
__i2
,
_InputIterator
__k1
,
_InputIterator
__k2
)
{
return
_M_replace
(
__i1
,
__i2
,
__k1
,
__k2
,
typename
iterator_traits
<
_InputIterator
>::
iterator_category
());
}
{
typedef
typename
_Is_integer
<
_InputIterator
>::
_Integral
_Integral
;
return
_M_replace_dispatch
(
__i1
,
__i2
,
__k1
,
__k2
,
_Integral
());
}
// Specializations for the common case of pointer and iterator:
// useful to avoid the overhead of temporary buffering in _M_replace.
...
...
@@ -659,6 +660,25 @@ namespace std
}
private
:
template
<
class
_Integer
>
basic_string
&
_M_replace_dispatch
(
iterator
__i1
,
iterator
__i2
,
_Integer
__n
,
_Integer
__val
,
__true_type
)
{
return
_M_replace_aux
(
__i1
,
__i2
,
__n
,
__val
);
}
template
<
class
_InputIterator
>
basic_string
&
_M_replace_dispatch
(
iterator
__i1
,
iterator
__i2
,
_InputIterator
__k1
,
_InputIterator
__k2
,
__false_type
)
{
typedef
typename
iterator_traits
<
_InputIterator
>::
iterator_category
_Category
;
return
_M_replace
(
__i1
,
__i2
,
__k1
,
__k2
,
_Category
());
}
basic_string
&
_M_replace_aux
(
iterator
__i1
,
iterator
__i2
,
size_type
__n2
,
_CharT
__c
);
template
<
class
_InputIterator
>
basic_string
&
_M_replace
(
iterator
__i1
,
iterator
__i2
,
_InputIterator
__k1
,
...
...
libstdc++-v3/include/bits/basic_string.tcc
View file @
bdb0f0f5
...
...
@@ -621,6 +621,22 @@ namespace std
// else nothing (in particular, avoid calling _M_mutate() unnecessarily.)
}
template<typename _CharT, typename _Traits, typename _Alloc>
basic_string<_CharT, _Traits, _Alloc>&
basic_string<_CharT, _Traits, _Alloc>::
_M_replace_aux(iterator __i1, iterator __i2, size_type __n2, _CharT __c)
{
size_type __n1 = __i2 - __i1;
size_type __off1 = __i1 - _M_ibegin();
if (max_size() - (this->size() - __n1) <= __n2)
__throw_length_error("basic_string::replace");
_M_mutate (__off1, __n1, __n2);
// Invalidated __i1, __i2
if (__n2)
traits_type::assign(_M_data() + __off1, __n2, __c);
return *this;
}
// This is the general replace helper, which currently gets instantiated both
// for input iterators and reverse iterators. It buffers internally and then
// calls _M_replace_safe.
...
...
@@ -761,22 +777,6 @@ namespace std
}
template<typename _CharT, typename _Traits, typename _Alloc>
basic_string<_CharT, _Traits, _Alloc>&
basic_string<_CharT, _Traits, _Alloc>::
replace(iterator __i1, iterator __i2, size_type __n2, _CharT __c)
{
const size_type __n1 = __i2 - __i1;
const size_type __off1 = __i1 - _M_ibegin();
if (max_size() - (this->size() - __n1) <= __n2)
__throw_length_error("basic_string::replace");
_M_mutate (__off1, __n1, __n2);
// Invalidated __i1, __i2
if (__n2)
traits_type::assign(_M_data() + __off1, __n2, __c);
return *this;
}
template<typename _CharT, typename _Traits, typename _Alloc>
typename basic_string<_CharT, _Traits, _Alloc>::size_type
basic_string<_CharT, _Traits, _Alloc>::
copy(_CharT* __s, size_type __n, size_type __pos) const
...
...
libstdc++-v3/testsuite/21_strings/basic_string/assign/char/1.cc
View file @
bdb0f0f5
...
...
@@ -44,6 +44,9 @@ test01()
aux
.
assign
(
aux
,
i
+
1
,
string
::
npos
);
VERIFY
(
aux
.
c_str
()[
9
]
==
'B'
);
VERIFY
(
aux
==
"/Hanalei Bay/Kauai/Hawaii"
);
aux
.
assign
(
10
,
0
);
VERIFY
(
aux
.
length
()
==
10
);
}
int
main
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment