From 43880bbbe1ef31507da44cc954c7e37ad156acc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Lu=C3=ADs=20Vaz=20Silva?= Date: Sun, 18 Dec 2022 21:19:36 -0300 Subject: [PATCH] Expose StripLeft and StripLeftRight to ZScript --- .../scripting/interface/stringformat.cpp | 28 +++++++++++++++++++ wadsrc/static/zscript/engine/base.zs | 2 ++ 2 files changed, 30 insertions(+) diff --git a/src/common/scripting/interface/stringformat.cpp b/src/common/scripting/interface/stringformat.cpp index 4bfe34ff62..77ce54ed68 100644 --- a/src/common/scripting/interface/stringformat.cpp +++ b/src/common/scripting/interface/stringformat.cpp @@ -578,6 +578,34 @@ DEFINE_ACTION_FUNCTION_NATIVE(FStringStruct, StripRight, StringStripRight) return 0; } +static void StringStripLeft(FString* self, const FString& junk) +{ + if (junk.IsNotEmpty()) self->StripLeft(junk); + else self->StripLeft(); +} + +DEFINE_ACTION_FUNCTION_NATIVE(FStringStruct, StripLeft, StringStripLeft) +{ + PARAM_SELF_STRUCT_PROLOGUE(FString); + PARAM_STRING(junk); + StringStripLeft(self, junk); + return 0; +} + +static void StringStripLeftRight(FString* self, const FString& junk) +{ + if (junk.IsNotEmpty()) self->StripLeftRight(junk); + else self->StripLeftRight(); +} + +DEFINE_ACTION_FUNCTION_NATIVE(FStringStruct, StripLeftRight, StringStripLeftRight) +{ + PARAM_SELF_STRUCT_PROLOGUE(FString); + PARAM_STRING(junk); + StringStripLeftRight(self, junk); + return 0; +} + static void StringSplit(FString* self, TArray* tokens, const FString& delimiter, int keepEmpty) { self->Split(*tokens, delimiter, static_cast(keepEmpty)); diff --git a/wadsrc/static/zscript/engine/base.zs b/wadsrc/static/zscript/engine/base.zs index cd2269661b..ea6440bbc6 100644 --- a/wadsrc/static/zscript/engine/base.zs +++ b/wadsrc/static/zscript/engine/base.zs @@ -881,7 +881,9 @@ struct StringStruct native native int CodePointCount() const; native int, int GetNextCodePoint(int position) const; native void Substitute(String str, String replace); + native void StripLeft(String junk = ""); native void StripRight(String junk = ""); + native void StripLeftRight(String junk = ""); } struct Translation version("2.4")