Skip to content

Commit

Permalink
Add StrRepeat string expression to repeat a string
Browse files Browse the repository at this point in the history
  • Loading branch information
victorlevasseur committed Dec 29, 2016
1 parent fd67843 commit 7ad075c
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 5 deletions.
11 changes: 9 additions & 2 deletions Core/GDCore/Extensions/Builtin/StringInstructionsExtension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -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)"),
Expand All @@ -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)"),
Expand Down
1 change: 0 additions & 1 deletion Extensions/TextEntryObject/TextEntryObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<char32_t>(characters[i]);
}
else if (characters[i] == 8)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
18 changes: 16 additions & 2 deletions GDCpp/GDCpp/Extensions/Builtin/StringTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,35 @@ 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)
{
return str.UpperCase();
}

/**
* 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
*/
Expand Down
1 change: 1 addition & 0 deletions GDCpp/GDCpp/Extensions/Builtin/StringTools.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions GDJS/GDJS/Extensions/Builtin/StringInstructionsExtension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
13 changes: 13 additions & 0 deletions GDJS/Runtime/events-tools/stringtools.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7ad075c

Please sign in to comment.