diff --git a/Core/GDCore/Extensions/Builtin/StringInstructionsExtension.cpp b/Core/GDCore/Extensions/Builtin/StringInstructionsExtension.cpp index df29a5ae3b0d..a6f87cc55265 100644 --- a/Core/GDCore/Extensions/Builtin/StringInstructionsExtension.cpp +++ b/Core/GDCore/Extensions/Builtin/StringInstructionsExtension.cpp @@ -68,6 +68,15 @@ void GD_CORE_API BuiltinExtensionsImplementer::ImplementsStringInstructionsExten .AddParameter("string", _("Text")) .AddParameter("expression", _("Position of the character (the first letter is at position 0)")); + extension.AddStrExpression("StrRepeat", + _("Repeat a text"), + _("Repeat a text"), + _("Manipulation on text"), + "res/conditions/toujours24.png") + + .AddParameter("string", _("Text to repeat")) + .AddParameter("expression", _("Repetition count")); + extension.AddExpression("StrLength", _("Length of a text"), _("Length of a text"), @@ -77,7 +86,6 @@ void GD_CORE_API BuiltinExtensionsImplementer::ImplementsStringInstructionsExten .AddParameter("string", _("Text")); - extension.AddExpression("StrFind", _("Search in a text"), _("Search in a text (return the position of the result or -1 if not found)"), @@ -88,7 +96,6 @@ void GD_CORE_API BuiltinExtensionsImplementer::ImplementsStringInstructionsExten .AddParameter("string", _("Text to search for")); - extension.AddExpression("StrRFind", _("Search in a text from end"), _("Search in a text from the end (return the position of the result or -1 if not found)"), diff --git a/Extensions/TextEntryObject/TextEntryObject.cpp b/Extensions/TextEntryObject/TextEntryObject.cpp index 09371b9d68ab..ce4a6f04a7bb 100644 --- a/Extensions/TextEntryObject/TextEntryObject.cpp +++ b/Extensions/TextEntryObject/TextEntryObject.cpp @@ -58,7 +58,6 @@ void RuntimeTextEntryObject::Update(const RuntimeScene & scene) //Skip some non displayable characters if (characters[i] > 30 && (characters[i] < 127 || characters[i] > 159)) { - std::cout << characters[i] << std::endl; text += static_cast(characters[i]); } else if (characters[i] == 8) diff --git a/GDCpp/GDCpp/Extensions/Builtin/StringInstructionsExtension.cpp b/GDCpp/GDCpp/Extensions/Builtin/StringInstructionsExtension.cpp index 648a159345a3..6d1b004423f3 100644 --- a/GDCpp/GDCpp/Extensions/Builtin/StringInstructionsExtension.cpp +++ b/GDCpp/GDCpp/Extensions/Builtin/StringInstructionsExtension.cpp @@ -22,6 +22,7 @@ StringInstructionsExtension::StringInstructionsExtension() GetAllStrExpressions()["ToLowerCase"].SetFunctionName("GDpriv::StringTools::ToLowerCase").SetIncludeFile("GDCpp/Extensions/Builtin/StringTools.h"); GetAllStrExpressions()["SubStr"].SetFunctionName("GDpriv::StringTools::SubStr").SetIncludeFile("GDCpp/Extensions/Builtin/StringTools.h"); GetAllStrExpressions()["StrAt"].SetFunctionName("GDpriv::StringTools::StrAt").SetIncludeFile("GDCpp/Extensions/Builtin/StringTools.h"); + GetAllStrExpressions()["StrRepeat"].SetFunctionName("GDpriv::StringTools::StrRepeat").SetIncludeFile("GDCpp/Extensions/Builtin/StringTools.h"); GetAllExpressions()["StrLength"].SetFunctionName("GDpriv::StringTools::StrLen").SetIncludeFile("GDCpp/Extensions/Builtin/StringTools.h"); GetAllExpressions()["StrFind"].SetFunctionName("GDpriv::StringTools::StrFind").SetIncludeFile("GDCpp/Extensions/Builtin/StringTools.h"); GetAllExpressions()["StrRFind"].SetFunctionName("GDpriv::StringTools::StrRFind").SetIncludeFile("GDCpp/Extensions/Builtin/StringTools.h"); diff --git a/GDCpp/GDCpp/Extensions/Builtin/StringTools.cpp b/GDCpp/GDCpp/Extensions/Builtin/StringTools.cpp index 26e8fe1b7356..d6accab41cfd 100644 --- a/GDCpp/GDCpp/Extensions/Builtin/StringTools.cpp +++ b/GDCpp/GDCpp/Extensions/Builtin/StringTools.cpp @@ -45,7 +45,7 @@ gd::String GD_API FromCodePoint(int32_t codepoint) } /** - * Expression function for getting the uppercased version of a string + * Expression function for getting the uppercase version of a string */ gd::String GD_API ToUpperCase(const gd::String & str) { @@ -53,13 +53,27 @@ gd::String GD_API ToUpperCase(const gd::String & str) } /** - * Expression function for getting the uppercased version of a string + * Expression function for getting the lowercase version of a string */ gd::String GD_API ToLowerCase(const gd::String & str) { return str.LowerCase(); } +/** + * Expression function for getting a repeated version of a string + */ +gd::String GD_API StrRepeat(const gd::String & str, std::size_t repCount) +{ + gd::String result; + + result.Raw().reserve(str.Raw().size() * repCount); + for(std::size_t i = 0; i < repCount; ++i) + result.Raw() += str.Raw(); + + return result; +} + /** * Expression function for getting a substring from a string */ diff --git a/GDCpp/GDCpp/Extensions/Builtin/StringTools.h b/GDCpp/GDCpp/Extensions/Builtin/StringTools.h index 3ed6eb5bc2c3..321f56e732eb 100644 --- a/GDCpp/GDCpp/Extensions/Builtin/StringTools.h +++ b/GDCpp/GDCpp/Extensions/Builtin/StringTools.h @@ -24,6 +24,7 @@ gd::String GD_API NewLine(); gd::String GD_API FromCodePoint(int32_t codepoint); gd::String GD_API ToUpperCase(const gd::String & str); gd::String GD_API ToLowerCase(const gd::String & str); +gd::String GD_API StrRepeat(const gd::String & str, std::size_t repCount); std::size_t GD_API StrLen(const gd::String & str); int GD_API StrFind(const gd::String & str, const gd::String & findwhat); int GD_API StrRFind(const gd::String & str, const gd::String & findwhat); diff --git a/GDJS/GDJS/Extensions/Builtin/StringInstructionsExtension.cpp b/GDJS/GDJS/Extensions/Builtin/StringInstructionsExtension.cpp index 91292ae57088..c88b614e3520 100644 --- a/GDJS/GDJS/Extensions/Builtin/StringInstructionsExtension.cpp +++ b/GDJS/GDJS/Extensions/Builtin/StringInstructionsExtension.cpp @@ -35,6 +35,8 @@ StringInstructionsExtension::StringInstructionsExtension() .SetFunctionName("gdjs.evtTools.string.subStr"); GetAllStrExpressions()["StrAt"] .SetFunctionName("gdjs.evtTools.string.strAt"); + GetAllStrExpressions()["StrRepeat"] + .SetFunctionName("gdjs.evtTools.string.strRepeat"); GetAllExpressions()["StrLength"] .SetFunctionName("gdjs.evtTools.string.strLen"); GetAllExpressions()["StrFind"] diff --git a/GDJS/Runtime/events-tools/stringtools.js b/GDJS/Runtime/events-tools/stringtools.js index 5934303eacab..5b50dc369f68 100644 --- a/GDJS/Runtime/events-tools/stringtools.js +++ b/GDJS/Runtime/events-tools/stringtools.js @@ -74,6 +74,19 @@ gdjs.evtTools.string.strAt = function(str, start) { return ""; }; +/** + * Return the string repeated. + * @method strAt + * @private + */ +gdjs.evtTools.string.strRepeat = function(str, count) { + var result = ""; + for ( var i = 0; i < count; i++ ) + result += str; + + return result; +} + /** * Return the length of the string * @method strLen