From aea178bbde7638851779a94f90a4a2ec3abff8cb Mon Sep 17 00:00:00 2001 From: Baptiste Wicht Date: Fri, 6 Apr 2018 09:20:13 +0200 Subject: [PATCH] Add std::string::erase --- tstl/include/string.hpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tstl/include/string.hpp b/tstl/include/string.hpp index 9242da4a..d7ab8753 100644 --- a/tstl/include/string.hpp +++ b/tstl/include/string.hpp @@ -305,6 +305,20 @@ public: (*this)[size()] = '\0'; } + /*! + * \brief Erase the character at the given position + */ + void erase(size_t position) { + if(position >= size()){ + return; + } + + std::copy(begin() + position + 1, end(), begin() + position); + + set_size(size() - 1); + (*this)[size()] = '\0'; + } + /*! * \brief Ensures a capacity of at least new_capacity */