Converted over to new name sanitization routine

This commit is contained in:
2026-03-28 20:04:48 -04:00
parent 88fa260c9d
commit 22fe60f431
3 changed files with 53 additions and 64 deletions

View File

@@ -4,6 +4,7 @@
#include "WingTypes.h"
#include "WingServer.h"
#include "WingHandler.h"
#include "WingTokenizer.h"
#include "Engine/Blueprint.h"
#include "Engine/MemberReference.h"
#include "Engine/World.h"
@@ -56,50 +57,31 @@
FString WingUtils::SanitizeName(const FString &InName)
{
FString Name = InName;
int32 Dst = 0;
for (int32 Src = 0; Src < Name.Len(); Src++)
{
TCHAR c = Name[Src];
if (c < 0x20 || c == 0x7F) continue;
if (c == ' ') c=L'·';
if (c == '<') c=L'';
if (c == '>') c=L'';
if (c == '(') c=L'';
if (c == ')') c=L'';
if (c == '=') c=L'';
if (c == ',') c=L'';
Name[Dst++] = c;
}
if (Dst == 0) Name[Dst++] = L'·';
Name.LeftInline(Dst);
return Name;
return WingTokenizer::ExternalizeID(InName);
}
FString WingUtils::UnsanitizeName(const FString &InName)
{
FString Name = InName;
int32 Dst = 0;
for (int32 Src = 0; Src < Name.Len(); Src++)
{
TCHAR c = Name[Src];
if (c < 0x20 || c == 0x7F) continue;
if (c == L'·') c=' ';
if (c == L'') c='<';
if (c == L'') c='>';
if (c == L'') c='(';
if (c == L'') c=')';
if (c == L'') c='=';
if (c == L'') c=',';
Name[Dst++] = c;
}
Name.LeftInline(Dst);
return Name;
FString Error;
return WingTokenizer::TryInternalizeID(InName, Error);
}
FString WingUtils::SanitizeName(FName Name)
{
return SanitizeName(Name.ToString());
return WingTokenizer::ExternalizeID(Name.ToString());
}
FString WingUtils::CheckProposedName(const FString &ExternalID)
{
FString InternalID = WingTokenizer::CheckInternalizeID(ExternalID);
if (!InternalID.IsEmpty() && WingTokenizer::WouldExternalizeReadably(InternalID))
{
UWingServer::Printf(TEXT("ERROR: id %s would not be a readable id, may not create item with this name"),
*ExternalID);
UWingServer::SuggestManual(WingManual::Section::IdentifierSanitization);
return FString();
}
return InternalID;
}
FString WingUtils::StandardizeMenuItem(const FString &Item)
@@ -128,16 +110,7 @@ FString WingUtils::StandardizeMenuItem(const FString &Item)
return Sanitized;
}
FString WingUtils::CheckProposedName(const FString &Name)
{
FString Unsanitized = UnsanitizeName(Name);
if ((Unsanitized.IsEmpty()) || (SanitizeName(Unsanitized) != Name))
{
UWingServer::Printf(TEXT("Names must not contain control characters or be empty\n"));
return FString();
}
return Unsanitized;
}
// ============================================================
// Name Lookup