@@ -26,6 +26,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
2626#include " exceptionobject.h"
2727#include < iostream>
2828#include < cmath>
29+ #include < algorithm>
2930
3031CommonModule_StringUtils::CommonModule_StringUtils (Class *c) : Object(c)
3132{
@@ -228,6 +229,32 @@ Class *CommonModule_StringUtils::registerClass(ModuleSystem *moduleSystem)
228229 */
229230 c->registerFunction (" safe_tags" , {VarType::fromString (" string" )}, VarType::fromString (" string" ), CommonModule_StringUtils::StringUtils_safe_tags);
230231 moduleSystem->getFunctionSystem ()->registerFunction (" safe_tags" , {VarType::fromString (" string" )}, VarType::fromString (" string" ), CommonModule_StringUtils::StringUtils_safe_tags);
232+
233+ /* *
234+ * @class StringUtils
235+ *
236+ * Converts the given string to upper case and returns it.
237+ *
238+ * Since: V0.2.0
239+ * @works_without_class
240+ *
241+ * function strtoupper(string val) : string
242+ */
243+ c->registerFunction (" strtoupper" , {VarType::fromString (" string" )}, VarType::fromString (" string" ), CommonModule_StringUtils::StringUtils_strtoupper);
244+ moduleSystem->getFunctionSystem ()->registerFunction (" strtoupper" , {VarType::fromString (" string" )}, VarType::fromString (" string" ), CommonModule_StringUtils::StringUtils_strtoupper);
245+
246+
247+ /* *
248+ * @class StringUtils
249+ *
250+ * Converts the given string to lower case and returns it
251+ * Since: V0.2.0
252+ * @works_without_class
253+ *
254+ * function strtolower(string val) : string
255+ */
256+ c->registerFunction (" strtolower" , {VarType::fromString (" string" )}, VarType::fromString (" string" ), CommonModule_StringUtils::StringUtils_strtolower);
257+ moduleSystem->getFunctionSystem ()->registerFunction (" strtolower" , {VarType::fromString (" string" )}, VarType::fromString (" string" ), CommonModule_StringUtils::StringUtils_strtolower);
231258}
232259
233260void CommonModule_StringUtils::StringUtils_getASCIIString (Interpreter *interpreter, std::vector<Value> values, Value *return_value, std::shared_ptr<Object> object, Scope *caller_scope)
@@ -376,4 +403,18 @@ void CommonModule_StringUtils::StringUtils_safe_tags(Interpreter *interpreter, s
376403 result = str_replace (result, " <" , " <" );
377404 result = str_replace (result, " >" , " >" );
378405 return_value->set (result);
406+ }
407+
408+ void CommonModule_StringUtils::StringUtils_strtoupper (Interpreter* interpreter, std::vector<Value> values, Value* return_value, std::shared_ptr<Object> object, Scope* caller_scope)
409+ {
410+ std::string s = values[0 ].svalue ;
411+ std::transform (s.begin (), s.end (), s.begin (), ::toupper);
412+ return_value->set (s);
413+ }
414+
415+ void CommonModule_StringUtils::StringUtils_strtolower (Interpreter* interpreter, std::vector<Value> values, Value* return_value, std::shared_ptr<Object> object, Scope* caller_scope)
416+ {
417+ std::string s = values[0 ].svalue ;
418+ std::transform (s.begin (), s.end (), s.begin (), ::tolower);
419+ return_value->set (s);
379420}
0 commit comments