From 393811919287d1e306a8b2aece4c0ba6f4402b22 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 13 Apr 2019 10:26:55 +0200 Subject: [PATCH] - added CharUpper and CharLower functions to ZScript. These, like MakeUpper and MakeLower, use the internal Unicode case conversion tables. --- src/scripting/vmthunks.cpp | 26 ++++++++++++++++++++++++++ wadsrc/static/zscript/base.zs | 2 ++ 2 files changed, 28 insertions(+) diff --git a/src/scripting/vmthunks.cpp b/src/scripting/vmthunks.cpp index 18d9b214e2..5cdd1aaca3 100644 --- a/src/scripting/vmthunks.cpp +++ b/src/scripting/vmthunks.cpp @@ -50,6 +50,7 @@ #include "am_map.h" #include "v_video.h" #include "gi.h" +#include "fontinternals.h" #include "intermission/intermission.h" DVector2 AM_GetPosition(); @@ -285,6 +286,31 @@ DEFINE_ACTION_FUNCTION_NATIVE(FStringStruct, MakeLower, StringMakeLower) ACTION_RETURN_STRING(self->MakeLower()); } +static int StringCharUpper(int ch) +{ + return ch >= 0 && ch < 65536 ? upperforlower[ch] : ch; +} + +DEFINE_ACTION_FUNCTION_NATIVE(FStringStruct, CharUpper, StringCharUpper) +{ + PARAM_PROLOGUE; + PARAM_INT(ch); + ACTION_RETURN_INT(StringCharUpper(ch)); +} + +static int StringCharLower(int ch) +{ + return ch >= 0 && ch < 65536 ? lowerforupper[ch] : ch; +} + +DEFINE_ACTION_FUNCTION_NATIVE(FStringStruct, CharLower, StringCharLower) +{ + PARAM_PROLOGUE; + PARAM_INT(ch); + ACTION_RETURN_INT(StringCharLower(ch)); +} + + static int StringToInt(FString *self, int base) { return (int)self->ToLong(base); diff --git a/wadsrc/static/zscript/base.zs b/wadsrc/static/zscript/base.zs index 0938c9ab8e..3c86611f31 100644 --- a/wadsrc/static/zscript/base.zs +++ b/wadsrc/static/zscript/base.zs @@ -909,6 +909,8 @@ struct StringStruct native deprecated("4.1") native void ToLower(); native String MakeUpper(); native String MakeLower(); + native static int CharUpper(int ch); + native static int CharLower(int ch); native int ToInt(int base = 0) const; native double ToDouble() const; native void Split(out Array tokens, String delimiter, EmptyTokenType keepEmpty = TOK_KEEPEMPTY) const;