aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaolo Carlini <pcarlini@suse.de>2007-01-18 12:03:35 +0000
committerPaolo Carlini <paolo@gcc.gnu.org>2007-01-18 12:03:35 +0000
commit9521dd6bd14f4915eecc79f886b805d3e1eb1ff7 (patch)
treebc73149696da051bfa175aaabfeeb69c2d25b183
parent463c03f1bc2380d46a39e63efd00df157a18fee2 (diff)
downloadgcc-9521dd6bd14f4915eecc79f886b805d3e1eb1ff7.zip
gcc-9521dd6bd14f4915eecc79f886b805d3e1eb1ff7.tar.gz
gcc-9521dd6bd14f4915eecc79f886b805d3e1eb1ff7.tar.bz2
basic_string.h (basic_string<>::_S_compare): Add.
2007-01-18 Paolo Carlini <pcarlini@suse.de> * include/bits/basic_string.h (basic_string<>::_S_compare): Add. (compare(const basic_string&)): Use it. * include/bits/basic_string.tcc (compare(size_type, size_type, const basic_string&), compare(size_type, size_type, const basic_string&, size_type, size_type), compare(const _CharT*), compare(size_type, size_type, const _CharT*), compare(size_type, size_type, const _CharT*, size_type)): Likewise. * include/ext/vstring_util.h (__vstring_utility<>::_S_compare): Add. * include/ext/vstring.h (compare(const __versa_string&)): Use it. * include/ext/vstring.tcc (compare(size_type, size_type, const __versa_string&), compare(size_type, size_type, const __versa_string&, size_type, size_type), compare(const _CharT*), compare(size_type, size_type, const _CharT*), compare(size_type, size_type, const _CharT*, size_type)): Likewise. From-SVN: r120896
-rw-r--r--libstdc++-v3/ChangeLog17
-rw-r--r--libstdc++-v3/include/bits/basic_string.h18
-rw-r--r--libstdc++-v3/include/bits/basic_string.tcc13
-rw-r--r--libstdc++-v3/include/ext/vstring.h4
-rw-r--r--libstdc++-v3/include/ext/vstring.tcc12
-rw-r--r--libstdc++-v3/include/ext/vstring_util.h16
6 files changed, 63 insertions, 17 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index ed498f9..53fc417 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,3 +1,20 @@
+2007-01-18 Paolo Carlini <pcarlini@suse.de>
+
+ * include/bits/basic_string.h (basic_string<>::_S_compare): Add.
+ (compare(const basic_string&)): Use it.
+ * include/bits/basic_string.tcc (compare(size_type, size_type,
+ const basic_string&), compare(size_type, size_type,
+ const basic_string&, size_type, size_type), compare(const _CharT*),
+ compare(size_type, size_type, const _CharT*), compare(size_type,
+ size_type, const _CharT*, size_type)): Likewise.
+ * include/ext/vstring_util.h (__vstring_utility<>::_S_compare): Add.
+ * include/ext/vstring.h (compare(const __versa_string&)): Use it.
+ * include/ext/vstring.tcc (compare(size_type, size_type,
+ const __versa_string&), compare(size_type, size_type,
+ const __versa_string&, size_type, size_type), compare(const _CharT*),
+ compare(size_type, size_type, const _CharT*), compare(size_type,
+ size_type, const _CharT*, size_type)): Likewise.
+
2007-01-15 Ian Lance Taylor <iant@google.com>
Paolo Carlini <pcarlini@suse.de>
diff --git a/libstdc++-v3/include/bits/basic_string.h b/libstdc++-v3/include/bits/basic_string.h
index 3c41107..5093068 100644
--- a/libstdc++-v3/include/bits/basic_string.h
+++ b/libstdc++-v3/include/bits/basic_string.h
@@ -1,6 +1,7 @@
// Components for manipulating sequences of characters -*- C++ -*-
-// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006
+// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
+// 2006, 2007
// Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
@@ -389,6 +390,19 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
_S_copy_chars(_CharT* __p, const _CharT* __k1, const _CharT* __k2)
{ _M_copy(__p, __k1, __k2 - __k1); }
+ static int
+ _S_compare(size_type __n1, size_type __n2)
+ {
+ const difference_type __d = difference_type(__n1 - __n2);
+
+ if (__d > numeric_limits<int>::max())
+ return numeric_limits<int>::max();
+ else if (__d < numeric_limits<int>::min())
+ return numeric_limits<int>::min();
+ else
+ return int(__d);
+ }
+
void
_M_mutate(size_type __pos, size_type __len1, size_type __len2);
@@ -1933,7 +1947,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
int __r = traits_type::compare(_M_data(), __str.data(), __len);
if (!__r)
- __r = __size - __osize;
+ __r = _S_compare(__size, __osize);
return __r;
}
diff --git a/libstdc++-v3/include/bits/basic_string.tcc b/libstdc++-v3/include/bits/basic_string.tcc
index fadf9b3..3437fda 100644
--- a/libstdc++-v3/include/bits/basic_string.tcc
+++ b/libstdc++-v3/include/bits/basic_string.tcc
@@ -1,6 +1,7 @@
// Components for manipulating sequences of characters -*- C++ -*-
-// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006
+// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
+// 2006, 2007
// Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
@@ -902,7 +903,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
const size_type __len = std::min(__n, __osize);
int __r = traits_type::compare(_M_data() + __pos, __str.data(), __len);
if (!__r)
- __r = __n - __osize;
+ __r = _S_compare(__n, __osize);
return __r;
}
@@ -920,7 +921,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
int __r = traits_type::compare(_M_data() + __pos1,
__str.data() + __pos2, __len);
if (!__r)
- __r = __n1 - __n2;
+ __r = _S_compare(__n1, __n2);
return __r;
}
@@ -935,7 +936,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
const size_type __len = std::min(__size, __osize);
int __r = traits_type::compare(_M_data(), __s, __len);
if (!__r)
- __r = __size - __osize;
+ __r = _S_compare(__size, __osize);
return __r;
}
@@ -951,7 +952,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
const size_type __len = std::min(__n1, __osize);
int __r = traits_type::compare(_M_data() + __pos, __s, __len);
if (!__r)
- __r = __n1 - __osize;
+ __r = _S_compare(__n1, __osize);
return __r;
}
@@ -967,7 +968,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
const size_type __len = std::min(__n1, __n2);
int __r = traits_type::compare(_M_data() + __pos, __s, __len);
if (!__r)
- __r = __n1 - __n2;
+ __r = _S_compare(__n1, __n2);
return __r;
}
diff --git a/libstdc++-v3/include/ext/vstring.h b/libstdc++-v3/include/ext/vstring.h
index 3f14822..32bc94e 100644
--- a/libstdc++-v3/include/ext/vstring.h
+++ b/libstdc++-v3/include/ext/vstring.h
@@ -1,6 +1,6 @@
// Versatile string -*- C++ -*-
-// Copyright (C) 2005, 2006 Free Software Foundation, Inc.
+// Copyright (C) 2005, 2006, 2007 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
@@ -1675,7 +1675,7 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
int __r = traits_type::compare(this->_M_data(), __str.data(), __len);
if (!__r)
- __r = __size - __osize;
+ __r = _S_compare(__size, __osize);
return __r;
}
diff --git a/libstdc++-v3/include/ext/vstring.tcc b/libstdc++-v3/include/ext/vstring.tcc
index f541772..69dd5f0 100644
--- a/libstdc++-v3/include/ext/vstring.tcc
+++ b/libstdc++-v3/include/ext/vstring.tcc
@@ -1,6 +1,6 @@
// Versatile string -*- C++ -*-
-// Copyright (C) 2005, 2006 Free Software Foundation, Inc.
+// Copyright (C) 2005, 2006, 2007 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
@@ -467,7 +467,7 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
int __r = traits_type::compare(this->_M_data() + __pos,
__str.data(), __len);
if (!__r)
- __r = __n - __osize;
+ __r = _S_compare(__n, __osize);
return __r;
}
@@ -486,7 +486,7 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
int __r = traits_type::compare(this->_M_data() + __pos1,
__str.data() + __pos2, __len);
if (!__r)
- __r = __n1 - __n2;
+ __r = _S_compare(__n1, __n2);
return __r;
}
@@ -502,7 +502,7 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
const size_type __len = std::min(__size, __osize);
int __r = traits_type::compare(this->_M_data(), __s, __len);
if (!__r)
- __r = __size - __osize;
+ __r = _S_compare(__size, __osize);
return __r;
}
@@ -519,7 +519,7 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
const size_type __len = std::min(__n1, __osize);
int __r = traits_type::compare(this->_M_data() + __pos, __s, __len);
if (!__r)
- __r = __n1 - __osize;
+ __r = _S_compare(__n1, __osize);
return __r;
}
@@ -536,7 +536,7 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
const size_type __len = std::min(__n1, __n2);
int __r = traits_type::compare(this->_M_data() + __pos, __s, __len);
if (!__r)
- __r = __n1 - __n2;
+ __r = _S_compare(__n1, __n2);
return __r;
}
diff --git a/libstdc++-v3/include/ext/vstring_util.h b/libstdc++-v3/include/ext/vstring_util.h
index a17de08..e29d8bf 100644
--- a/libstdc++-v3/include/ext/vstring_util.h
+++ b/libstdc++-v3/include/ext/vstring_util.h
@@ -1,6 +1,6 @@
// Versatile string utility -*- C++ -*-
-// Copyright (C) 2005, 2006 Free Software Foundation, Inc.
+// Copyright (C) 2005, 2006, 2007 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
@@ -55,6 +55,7 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
typedef _Traits traits_type;
typedef typename _Traits::char_type value_type;
typedef typename _CharT_alloc_type::size_type size_type;
+ typedef typename _CharT_alloc_type::difference_type difference_type;
typedef typename _CharT_alloc_type::pointer pointer;
typedef typename _CharT_alloc_type::const_pointer const_pointer;
@@ -169,6 +170,19 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
static void
_S_copy_chars(_CharT* __p, const _CharT* __k1, const _CharT* __k2)
{ _S_copy(__p, __k1, __k2 - __k1); }
+
+ static int
+ _S_compare(size_type __n1, size_type __n2)
+ {
+ const difference_type __d = difference_type(__n1 - __n2);
+
+ if (__d > std::numeric_limits<int>::max())
+ return std::numeric_limits<int>::max();
+ else if (__d < std::numeric_limits<int>::min())
+ return std::numeric_limits<int>::min();
+ else
+ return int(__d);
+ }
};
_GLIBCXX_END_NAMESPACE