mirror of
https://github.com/ZDoom/gzdoom-gles.git
synced 2024-11-15 17:11:24 +00:00
- added Unicode aware MakeUpper/MakeLower functions to FString and ZScript's String and deprecated ToUpper/ToLower because their semantics did not allow fixing them.
This commit is contained in:
parent
f2a43353c4
commit
1e0228c13a
4 changed files with 50 additions and 16 deletions
|
@ -260,6 +260,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 ()
|
||||
|
|
|
@ -233,7 +233,8 @@ public:
|
|||
|
||||
void ToUpper ();
|
||||
void ToLower ();
|
||||
void SwapCase ();
|
||||
FString MakeUpper();
|
||||
FString MakeLower();
|
||||
|
||||
void StripLeft ();
|
||||
void StripLeft (const FString &charset);
|
||||
|
|
|
@ -878,8 +878,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;
|
||||
|
|
Loading…
Reference in a new issue