From e4a6b6bc02fb85db789c12bbf69e6db0b66d4a4a Mon Sep 17 00:00:00 2001 From: Marco Biasini <marco.biasini@unibas.ch> Date: Wed, 13 Jul 2011 08:29:13 +0200 Subject: [PATCH] remove recently added exception from StringRef.substr and add a comment explantion the change --- modules/base/src/string_ref.hh | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/modules/base/src/string_ref.hh b/modules/base/src/string_ref.hh index 3d2c49edf..cc5661eba 100644 --- a/modules/base/src/string_ref.hh +++ b/modules/base/src/string_ref.hh @@ -72,19 +72,22 @@ public: } return s; } + + /// \brief returns a substring of the string + /// + /// \param pos the starting position of the substring + /// \param length is the length of the string. if std::string::npos, the + /// substring goes from \p pos to the end of the string + /// The function does on purpose not perform any boundary check in release + /// mode. It's the duty of the caller to make sure the string has the required + /// length. StringRef substr(size_t pos, size_t n=std::string::npos) const { if (n==std::string::npos) { - assert(pos>=0 && begin_+pos<=end_); - if(!(pos>=0 && begin_+pos<=end_)){ - throw Error("out of bounds"); - } + assert(begin_+pos<=end_); return StringRef(begin_+pos, this->length()-pos); } else { - assert(pos>=0 && begin_+pos+n<=end_); - if(!(pos>=0 && begin_+pos+n<=end_)){ - throw Error("out of bounds"); - } + assert(begin_+pos+n<=end_); return StringRef(begin_+pos, n); } } -- GitLab