mirror of
https://github.com/SpartanJ/eepp.git
synced 2026-08-13 04:42:12 +03:00
Added String::replaceAll() and String::replace() for String type.
Added Action::on(). --HG-- branch : dev
This commit is contained in:
@@ -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 );
|
||||
|
||||
|
||||
@@ -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 );
|
||||
|
||||
@@ -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 );
|
||||
|
||||
@@ -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<Uint32, ActionCallback> event = it->second;
|
||||
|
||||
Reference in New Issue
Block a user