From 09860f7a0237a585dd269b33c6b7ee2df457e02a Mon Sep 17 00:00:00 2001 From: Jan Haller Date: Sun, 9 Feb 2014 22:18:34 +0100 Subject: [PATCH] Added String::substring() method Based on pull request #355 from abodelot --- include/SFML/System/String.hpp | 17 +++++++++++++++++ src/SFML/System/String.cpp | 7 +++++++ 2 files changed, 24 insertions(+) diff --git a/include/SFML/System/String.hpp b/include/SFML/System/String.hpp index 3abd4207..53d85fcf 100644 --- a/include/SFML/System/String.hpp +++ b/include/SFML/System/String.hpp @@ -437,6 +437,23 @@ public : //////////////////////////////////////////////////////////// void replace(const String& searchFor, const String& replaceWith); + //////////////////////////////////////////////////////////// + /// \brief Return a part of the string + /// + /// This function returns the substring that starts at index \a position + /// and spans \a length characters. + /// + /// \param position Index of the first character + /// \param length Number of characters to include in the substring (if + /// the string is shorter, as many characters as possible + /// are included). \ref InvalidPos can be used to include all + /// characters until the end of the string. + /// + /// \return String object containing a substring of this object + /// + //////////////////////////////////////////////////////////// + String substring(std::size_t position, std::size_t length = InvalidPos) const; + //////////////////////////////////////////////////////////// /// \brief Get a pointer to the C-style array of characters /// diff --git a/src/SFML/System/String.cpp b/src/SFML/System/String.cpp index ba02ea48..61f80e82 100644 --- a/src/SFML/System/String.cpp +++ b/src/SFML/System/String.cpp @@ -304,6 +304,13 @@ void String::replace(const String& searchFor, const String& replaceWith) } +//////////////////////////////////////////////////////////// +String String::substring(std::size_t position, std::size_t length) const +{ + return m_string.substr(position, length); +} + + //////////////////////////////////////////////////////////// const Uint32* String::getData() const {