diff --git a/include/eepp/core/string.hpp b/include/eepp/core/string.hpp index 13c3f66ea..c3fcf59c3 100644 --- a/include/eepp/core/string.hpp +++ b/include/eepp/core/string.hpp @@ -171,9 +171,15 @@ class EE_API String { /** Replace all occurrences of the search string with the replacement string. */ static void replaceAll( std::string &target, const std::string& that, const std::string& with ); + /** Replace all occurrences of the search string with the replacement string. */ + static void replaceAll( String &target, const String& that, const String& with ); + /** Replace the first ocurrence of the search string with the replacement string. */ static void replace( std::string& target, const std::string& that, const std::string& with ); + /** Replace the first ocurrence of the search string with the replacement string. */ + static void replace( String& target, const String& that, const String& with ); + /** Removes the numbers at the end of the string */ static std::string removeNumbersAtEnd( std::string txt ); diff --git a/include/eepp/scene/action.hpp b/include/eepp/scene/action.hpp index f4ade102c..5e5c25338 100644 --- a/include/eepp/scene/action.hpp +++ b/include/eepp/scene/action.hpp @@ -50,6 +50,8 @@ class EE_API Action { Uint32 addEventListener( const ActionType & actionType, const ActionCallback & callback ); + Action * on( const ActionType & actionType, const ActionCallback & callback ); + void removeEventListener( const Uint32 & callbackId ); void sendEvent( const ActionType & actionType ); diff --git a/src/eepp/core/string.cpp b/src/eepp/core/string.cpp index 4b0cdf27d..c6f8d1279 100644 --- a/src/eepp/core/string.cpp +++ b/src/eepp/core/string.cpp @@ -203,6 +203,16 @@ void String::replaceAll( std::string &target, const std::string& that, const std } } +void String::replaceAll( String &target, const String& that, const String& with ) { + std::string::size_type pos=0; + + while( ( pos = target.find( that, pos ) ) != String::InvalidPos ) { + target.erase( pos, that.length() ); + target.insert( pos, with ); + pos += with.length(); + } +} + void String::replace( std::string& target, const std::string& that, const std::string& with ) { std::size_t start_pos = target.find( that ); @@ -212,6 +222,15 @@ void String::replace( std::string& target, const std::string& that, const std::s target.replace( start_pos, that.length(), with ); } +void String::replace( String& target, const String& that, const String& with ) { + std::size_t start_pos = target.find( that ); + + if( start_pos == String::InvalidPos ) + return; + + target.replace( start_pos, that.length(), with ); +} + std::string String::removeNumbersAtEnd( std::string txt ) { while ( txt.size() && txt[ txt.size() - 1 ] >= '0' && txt[ txt.size() - 1 ] <= '9' ) { txt.resize( txt.size() - 1 ); diff --git a/src/eepp/scene/action.cpp b/src/eepp/scene/action.cpp index 43f2d42ea..c1445b9f0 100644 --- a/src/eepp/scene/action.cpp +++ b/src/eepp/scene/action.cpp @@ -54,6 +54,11 @@ Uint32 Action::addEventListener( const ActionType& actionType, const ActionCallb return mNumCallBacks; } +Action * Action::on(const Action::ActionType& actionType, const Action::ActionCallback& callback) { + addEventListener( actionType, callback ); + return this; +} + void Action::removeEventListener( const Uint32& callbackId ) { for ( auto it = mCallbacks.begin(); it != mCallbacks.end(); ++it ) { std::map event = it->second;