diff options
Diffstat (limited to 'src/functionreplace.cpp')
| -rw-r--r-- | src/functionreplace.cpp | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/src/functionreplace.cpp b/src/functionreplace.cpp new file mode 100644 index 0000000..d269083 --- /dev/null +++ b/src/functionreplace.cpp | |||
| @@ -0,0 +1,47 @@ | |||
| 1 | #include "functionreplace.h" | ||
| 2 | |||
| 3 | FunctionReplace::FunctionReplace() | ||
| 4 | { | ||
| 5 | } | ||
| 6 | |||
| 7 | FunctionReplace::~FunctionReplace() | ||
| 8 | { | ||
| 9 | } | ||
| 10 | |||
| 11 | Bu::FString FunctionReplace::getName() const | ||
| 12 | { | ||
| 13 | return "replace"; | ||
| 14 | } | ||
| 15 | |||
| 16 | Variable FunctionReplace::call( Variable &input, VarList lParams ) | ||
| 17 | { | ||
| 18 | Bu::FString sA, sB; | ||
| 19 | sA = lParams.first().getString(); | ||
| 20 | sB = lParams.last().getString(); | ||
| 21 | switch( input.getType() ) | ||
| 22 | { | ||
| 23 | case Variable::typeString: | ||
| 24 | { | ||
| 25 | Variable vOut( input.getString().replace( sA, sB ) ); | ||
| 26 | return vOut; | ||
| 27 | } | ||
| 28 | break; | ||
| 29 | |||
| 30 | case Variable::typeList: | ||
| 31 | { | ||
| 32 | Variable vOut( Variable::typeList ); | ||
| 33 | for( VarList::iterator i = input.begin(); i; i++ ) | ||
| 34 | { | ||
| 35 | vOut.append( (*i).getString().replace( sA, sB ) ); | ||
| 36 | } | ||
| 37 | return vOut; | ||
| 38 | } | ||
| 39 | break; | ||
| 40 | |||
| 41 | default: | ||
| 42 | break; | ||
| 43 | } | ||
| 44 | throw Bu::ExceptionBase( | ||
| 45 | "replace does not work on non-string or non-list types."); | ||
| 46 | } | ||
| 47 | |||
