Skip to content
Snippets Groups Projects
Commit e4a6b6bc authored by Marco Biasini's avatar Marco Biasini
Browse files

remove recently added exception from StringRef.substr and add a comment explantion the change

parent 45fa8787
No related branches found
No related tags found
No related merge requests found
...@@ -72,19 +72,22 @@ public: ...@@ -72,19 +72,22 @@ public:
} }
return s; 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 StringRef substr(size_t pos, size_t n=std::string::npos) const
{ {
if (n==std::string::npos) { if (n==std::string::npos) {
assert(pos>=0 && begin_+pos<=end_); assert(begin_+pos<=end_);
if(!(pos>=0 && begin_+pos<=end_)){
throw Error("out of bounds");
}
return StringRef(begin_+pos, this->length()-pos); return StringRef(begin_+pos, this->length()-pos);
} else { } else {
assert(pos>=0 && begin_+pos+n<=end_); assert(begin_+pos+n<=end_);
if(!(pos>=0 && begin_+pos+n<=end_)){
throw Error("out of bounds");
}
return StringRef(begin_+pos, n); return StringRef(begin_+pos, n);
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment