Skip to content

Instantly share code, notes, and snippets.

@neilmanuell
Created July 7, 2011 09:58
Show Gist options
  • Save neilmanuell/1069216 to your computer and use it in GitHub Desktop.
Save neilmanuell/1069216 to your computer and use it in GitHub Desktop.
package org.osflash.statemachine.supporting {
public function injectThis( value:String):ITokenInjector {
return new InjectTokenIntoString( value );
}
}
package org.osflash.statemachine.supporting {
public class InjectTokenIntoString implements ITokenInjector {
private var _value:String;
public function InjectTokenIntoString( value:String ) {
_value = value;
}
public function withThis( keyword:String, replace:* ):ITokenInjector {
inject( keyword, replace );
return this;
}
public function finallyWith( keyword:String, replace:* ):String {
inject( keyword, replace );
return _value;
}
private function inject( keyword:String, replace:* ):void {
const regexp:RegExp = new RegExp( "\\$\\{(" + keyword + ")\\}", "g" );
_value = _value.replace( regexp, replace.toString() );
}
public function toString():String {
return _value;
}
}
}
package revisual.utils {
public interface ITokenInjector {
function withThis( keyword:String, replace:* ):ITokenInjector
function finallyWith( keyword:String, replace:* ):String
function toString():String;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment