diff --git a/modules/base/src/string_ref.hh b/modules/base/src/string_ref.hh index 21bf024b8c9faf7cb29efbedd2d559c17496ff50..802dd594069257ba17213a02d73144018e635b32 100644 --- a/modules/base/src/string_ref.hh +++ b/modules/base/src/string_ref.hh @@ -59,7 +59,9 @@ public: assert(!this->empty()); return *begin_; } - + + /// \brief find character in StringRef + /// \return iterator position when found, else iterator pointing to the end const_iterator find(char p) const { const char* s=begin_; while (s!=end_) { @@ -70,13 +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_); + assert(begin_+pos<=end_); return StringRef(begin_+pos, this->length()-pos); } else { - assert(pos>=0 && begin_+pos+n<=end_); + assert(begin_+pos+n<=end_); return StringRef(begin_+pos, n); } }