Skip to content
Permalink
Browse files

- added Unicode aware MakeUpper/MakeLower functions to FString and ZS…

…cript's String and deprecated ToUpper/ToLower because their semantics did not allow fixing them.
  • Loading branch information...
coelckers committed Apr 13, 2019
1 parent 325b744 commit f7561f25d60279e5df07200460a513270a8c355d
Showing with 50 additions and 16 deletions.
  1. +22 −0 src/scripting/vmthunks.cpp
  2. +22 −13 src/utility/zstring.cpp
  3. +2 −1 src/utility/zstring.h
  4. +4 −2 wadsrc/static/zscript/base.zs
@@ -263,6 +263,28 @@ DEFINE_ACTION_FUNCTION_NATIVE(FStringStruct, ToLower, StringToLower)
return 0;
}

static void StringMakeUpper(FString *self, FString *out)
{
*out = self->MakeUpper();
}

DEFINE_ACTION_FUNCTION_NATIVE(FStringStruct, MakeUpper, StringMakeUpper)
{
PARAM_SELF_STRUCT_PROLOGUE(FString);
ACTION_RETURN_STRING(self->MakeUpper());
}

static void StringMakeLower(FString *self, FString *out)
{
*out = self->MakeLower();
}

DEFINE_ACTION_FUNCTION_NATIVE(FStringStruct, MakeLower, StringMakeLower)
{
PARAM_SELF_STRUCT_PROLOGUE(FString);
ACTION_RETURN_STRING(self->MakeLower());
}

static int StringToInt(FString *self, int base)
{
return (int)self->ToLong(base);
@@ -40,6 +40,7 @@
#include "zstring.h"
#include "v_text.h"
#include "utf8.h"
#include "fontinternals.h"

FNullStringData FString::NullString =
{
@@ -680,22 +681,30 @@ void FString::ToLower ()
UnlockBuffer();
}

void FString::SwapCase ()
FString FString::MakeLower()
{
LockBuffer();
size_t max = Len();
for (size_t i = 0; i < max; ++i)
TArray<uint8_t> builder(Len());
int pos = 0;
while (int c = GetNextCharacter(pos))
{
if (isupper(Chars[i]))
{
Chars[i] = (char)tolower(Chars[i]);
}
else
{
Chars[i] = (char)toupper(Chars[i]);
}
if (c < 65536) c = lowerforupper[c];
auto cp = MakeUTF8(c);
while (auto uc = *cp++) builder.Push(uc);
}
UnlockBuffer();
return FString(builder);
}

FString FString::MakeUpper()
{
TArray<uint8_t> builder(Len());
int pos = 0;
while (int c = GetNextCharacter(pos))
{
if (c < 65536) c = upperforlower[c];
auto cp = MakeUTF8(c);
while (auto uc = *cp++) builder.Push(uc);
}
return FString(builder);
}

void FString::StripLeft ()
@@ -238,7 +238,8 @@ class FString

void ToUpper ();
void ToLower ();
void SwapCase ();
FString MakeUpper();
FString MakeLower();

void StripLeft ();
void StripLeft (const FString &charset);
@@ -905,8 +905,10 @@ struct StringStruct native
native int IndexOf(String substr, int startIndex = 0) const;
deprecated("3.5.1") native int LastIndexOf(String substr, int endIndex = 2147483647) const;
native int RightIndexOf(String substr, int endIndex = 2147483647) const;
native void ToUpper();
native void ToLower();
deprecated("4.1") native void ToUpper();
deprecated("4.1") native void ToLower();
native String MakeUpper();
native String MakeLower();
native int ToInt(int base = 0) const;
native double ToDouble() const;
native void Split(out Array<String> tokens, String delimiter, EmptyTokenType keepEmpty = TOK_KEEPEMPTY) const;

0 comments on commit f7561f2

Please sign in to comment.
You can’t perform that action at this time.