Author: sebor
Date: Mon Apr 2 16:14:45 2007
New Revision: 524965
URL: http://svn.apache.org/viewvc?view=rev&rev=524965
Log:
2007-04-02 Martin Sebor <[EMAIL PROTECTED]>
STDCXX-383
* string (_C_off): Convenience functions to compute the unsigned
distance between two iterators or the offset of an iterator from
the beginning of the container.
(insert, erase, replace): Used _C_off() to silence HP aCC 3.76
remark #4271-D: type conversion may lose sign.
Modified:
incubator/stdcxx/trunk/include/string
incubator/stdcxx/trunk/include/string.cc
Modified: incubator/stdcxx/trunk/include/string
URL:
http://svn.apache.org/viewvc/incubator/stdcxx/trunk/include/string?view=diff&rev=524965&r1=524964&r2=524965
==============================================================================
--- incubator/stdcxx/trunk/include/string (original)
+++ incubator/stdcxx/trunk/include/string Mon Apr 2 16:14:45 2007
@@ -406,8 +406,7 @@
// 21.3.5.4, p10
iterator insert (iterator __pos, value_type __c) {
- _RWSTD_ASSERT_RANGE (_C_make_iter (_C_data), __pos);
- size_type __inx = __pos - _C_make_iter (_C_data);
+ const size_type __inx = _C_off (__pos);
return insert (__inx, &__c, 1), begin () + __inx;
}
@@ -428,16 +427,13 @@
void insert (iterator __p, size_type __n, value_type __c, int) {
// unnamed arg is used for overload resolution
- replace (__p - _C_make_iter (_C_data), size_type (), __n, __c);
+ replace (_C_off (__p), size_type (), __n, __c);
}
void insert (iterator __p,
const_pointer __first, const_pointer __last, void*) {
- // unnamed arg is used for overload resolution
- const iterator __begin = _C_make_iter (_C_data);
- _RWSTD_ASSERT_RANGE (__begin, __p);
if (__first >= _C_data && __first <= _C_data + size ())
- insert (__p - __begin, basic_string (__first, __last));
+ insert (_C_off (__p), basic_string (__first, __last));
else
replace (__p, __p, __first, __last);
}
@@ -449,7 +445,7 @@
// unnamed arg is used for overload resolution
if (!(__first == __last)) {
const const_pointer __pf = &*__first;
- insert (__p, __pf, __pf + (__last - __first));
+ insert (__p, __pf, __pf + _C_off (__first, __last));
}
}
@@ -464,11 +460,8 @@
#else // if defined (_RWSTD_NO_INLINE_MEMBER_TEMPLATES)
void insert (iterator __p, const_pointer __first, const_pointer __last) {
- // unnamed arg is used for overload resolution
- const iterator __begin = _C_make_iter (_C_data);
- _RWSTD_ASSERT_RANGE (__begin, __p);
if (__first >= _C_data && __first <= _C_data + size ())
- insert (__p - __begin, basic_string (__first, __last));
+ insert (_C_off (__p), basic_string (__first, __last));
else
replace (__p, __p, __first, __last);
}
@@ -477,8 +470,7 @@
void insert (iterator __it, size_type __n, value_type __c) {
- _RWSTD_ASSERT_RANGE (_C_make_iter (_C_data), __it);
- replace (__it - _C_make_iter (_C_data), size_type (), __n, __c);
+ replace (_C_off (__it), size_type (), __n, __c);
}
basic_string& insert (size_type __pos, size_type __n, value_type __c) {
@@ -493,12 +485,9 @@
}
iterator erase (iterator __first, iterator __last) {
- _RWSTD_ASSERT_RANGE (_C_make_iter (_C_data), __first);
- _RWSTD_ASSERT_RANGE (__first, __last);
+ const size_type __pos = _C_off (__first);
- const difference_type __pos = __first - _C_make_iter (_C_data);
-
- replace (__pos, __last - __first, const_pointer (), size_type ());
+ replace (__pos, _C_off (__first, __last), const_pointer(),
size_type());
return _C_make_iter (_C_data + __pos);
}
@@ -571,17 +560,15 @@
// 21.3.5.6, p11
basic_string&
replace (iterator __first, iterator __last, const basic_string &__str) {
- return replace (__first - _C_make_iter (_C_data),
- __last - __first, __str);
+ return replace (_C_off (__first), _C_off (__first, __last), __str);
}
// 21.3.5.6, p15
basic_string&
replace (iterator __first, iterator __last,
const_pointer __s, size_type __n) {
- replace (__first - _C_make_iter (_C_data), __last - __first,
- __s, __n);
- return *this;;
+ replace (_C_off (__first), _C_off (__first, __last), __s, __n);
+ return *this;
}
// 21.3.5.6, p17
@@ -593,8 +580,7 @@
// 21.3.5.6, p19
basic_string&
replace (iterator __first, iterator __last, size_type __n, value_type __c)
{
- return replace (__first - _C_make_iter (_C_data), __last - __first,
- __n, __c);
+ return replace (_C_off (__first), _C_off (__first, __last), __n, __c);
}
#if !defined (_RWSTD_NO_INLINE_MEMBER_TEMPLATES) \
@@ -621,9 +607,7 @@
basic_string&
replace (iterator __first, iterator __last,
size_type __n, value_type __c, int) {
- // unnamed arg is used for overload resolution
- return replace (__first - _C_make_iter (_C_data), __last - __first,
- __n, __c);
+ return replace (_C_off (__first), _C_off (__first, __last), __n, __c);
}
// 21.3.5.6, p21
@@ -640,8 +624,8 @@
basic_string&
replace (iterator __first1, iterator __last1,
const_pointer __first2, const_pointer __last2) {
- replace (__first1 - _C_make_iter (_C_data), __last1 - __first1,
- __first2, __last2 - __first2);
+ replace (_C_off (__first1), _C_off (__first1, __last1),
+ __first2, _C_off (__first2, __last2));
return *this;
}
@@ -846,6 +830,18 @@
private:
#endif
+
+ static size_type
+ _C_off (const_iterator __first, const_iterator __last) {
+ _RWSTD_ASSERT_RANGE (__first, __last);
+ return size_type (__last - __first);
+ }
+
+ size_type
+ _C_off (const_iterator __it) const {
+ _RWSTD_ASSERT_RANGE (__it, _C_make_iter (_C_data));
+ return _C_off (_C_make_iter (_C_data), __it);
+ }
void _C_clone (size_type);
Modified: incubator/stdcxx/trunk/include/string.cc
URL:
http://svn.apache.org/viewvc/incubator/stdcxx/trunk/include/string.cc?view=diff&rev=524965&r1=524964&r2=524965
==============================================================================
--- incubator/stdcxx/trunk/include/string.cc (original)
+++ incubator/stdcxx/trunk/include/string.cc Mon Apr 2 16:14:45 2007
@@ -6,22 +6,23 @@
*
***************************************************************************
*
- * Copyright 2005-2006 The Apache Software Foundation or its licensors,
- * as applicable.
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at
*
- * Copyright 1994-2006 Rogue Wave Software.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied. See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ * Copyright 1994-2006 Rogue Wave Software.
*
**************************************************************************/
@@ -522,15 +523,14 @@
for ( ; !(__first2 == __last2); ++__first1, ++__first2) {
- size_type __off = __first1 - __s._C_make_iter (__s._C_data);
+ const size_type __off = __s._C_off (__first1);
_RWSTD_REQUIRES (__off <= __s.max_size(),
(_RWSTD_ERROR_LENGTH_ERROR,
_RWSTD_FUNC ("basic_string::replace(iterator, "
"iterator, InputIterator, "
"InputIterator)"),
- __first1 - __s._C_make_iter (__s._C_data),
- __s.max_size ()));
+ __s._C_off (__first1), __s.max_size ()));
// extend the string if necessary
if (__first1 == __last1) {
@@ -557,10 +557,12 @@
traits_type::assign (*__first1, *__first2);
}
- if (!(__first1 == __last1))
- __s.replace (__first1 - __s._C_make_iter (__s._C_data),
- __last1 - __first1,
- size_type (), value_type ());
+ if (!(__first1 == __last1)) {
+ const size_type __pos = __s._C_off (__first1);
+ const size_type __n = __s._C_off (__first1, __last1);
+
+ __s.replace (__pos, __n, size_type (), value_type ());
+ }
return __s;
}
@@ -604,9 +606,9 @@
_RWSTD_ASSERT_RANGE (__first1, __last1);
_RWSTD_ASSERT_RANGE (__first2, __last2);
- difference_type __n2 = _DISTANCE (__first2, __last2, difference_type);
- size_type __n = __last1 - __first1;
- size_type __pos = __first1 - __s._C_make_iter (__s._C_data);
+ const size_type __n2 = _DISTANCE (__first2, __last2, size_type);
+ const size_type __n = __s._C_off (__first1, __last1);
+ const size_type __pos = __s._C_off (__first1);
_RWSTD_REQUIRES (__pos <= __s.size (),
(_RWSTD_ERROR_OUT_OF_RANGE,
@@ -641,7 +643,7 @@
_C_string_ref_type * __temp = __s._C_get_rep (__cap, __len);
if (__pos) traits_type::copy(__temp->data(), __s._C_data, __pos);
- for (__d = 0; __d < (size_type)__n2; __d++)
+ for (__d = 0; __d < __n2; __d++)
traits_type::assign (*(__temp->data()+__pos+__d), *__first2++);
if (__rem)
traits_type::copy (__temp->data () + __pos + __n2,
@@ -654,7 +656,7 @@
if (__rem)
traits_type::move(__s._C_data+__pos+__n2, __s._C_data+__pos+__n,
__rem);
- for (__d = 0; __d < (size_type)__n2; __d++)
+ for (__d = 0; __d < __n2; __d++)
traits_type::assign (*(__s._C_data+__pos+__d), *__first2++);
traits_type::assign (__s._C_data[__s._C_pref()->_C_size._C_size
= __len], value_type());