Ark Server API (ASA) - Wiki
Loading...
Searching...
No Matches
TextFilterUtils.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2#pragma once
3
4#include "Containers/Array.h"
5#include "Containers/UnrealString.h"
6#include "CoreTypes.h"
7#include "Misc/AssertionMacros.h"
8#include "Misc/CString.h"
9#include "UObject/NameTypes.h"
10
11/** Defines the comparison operators that can be used for a complex (key->value) comparison */
13{
14 Equal,
16 Less,
18 Greater,
20};
21
22/** Defines the different ways that a string can be compared while evaluating the expression */
24{
25 Exact,
26 Partial,
29};
30
32
33/**
34 * String used by the text filter.
35 * The given string will be stored as uppercase since filter text always performs case-insensitive string comparisons, so this will minimize ToUpper calls.
36 */
38{
39public:
40 /** Default constructor */
42
43 /** Move and copy constructors */
46
47 /** Construct from a string */
48 FTextFilterString(const FString& InString);
50 FTextFilterString(const TCHAR* InString);
51
52 /** Construct from a name */
53 FTextFilterString(const FName& InName);
54
55 /** Move and copy assignment */
58
59 /** Compare this string against the other, using the text comparison mode provided */
60 bool CompareText(const FTextFilterString& InOther, const ETextFilterTextComparisonMode InTextComparisonMode) const;
61
62 /** Compare this string against the other FString, using the text comparison mode provided */
63 bool CompareFString(const FString& InOther, const ETextFilterTextComparisonMode InTextComparisonMode) const;
64
65 /** Compare this string against the other FName, using the text comparison mode provided */
66 bool CompareName(const FName& InOther, const ETextFilterTextComparisonMode InTextComparisonMode) const;
67
68 /** Are the two given strings able to be compared numberically? */
69 bool CanCompareNumeric(const FTextFilterString& InOther) const;
70
71 /** Compare this string against the other, converting them to numbers and using the comparison operator provided - you should have tested CanCompareNumeric first! */
72 bool CompareNumeric(const FTextFilterString& InOther, const ETextFilterComparisonOperation InComparisonOperation) const;
73
74 /** Get the internal uppercase string of this filter string */
76 {
77 return InternalString;
78 }
79
80 /** Get the internal uppercase string of this filter string as an FName */
82 {
83 return FName(*InternalString);
84 }
85
86 /** Is the internal string empty? */
87 FORCEINLINE bool IsEmpty() const
88 {
89 return InternalString.IsEmpty();
90 }
91
92private:
93 /** Inline convert our internal string to uppercase */
95
96 /** The uppercase string to use for comparisons */
98
99 /** The uppercase ANSI version of string to use for comparisons */
101};
102
104{
105 template <typename CharType>
106 void IntToStringBuffer(CharType* Dest, int32 Source, int32 MaxLen)
107 {
108 int64 Num = Source; // This avoids having to deal with negating -MAX_int32-1
109 bool bIsNumberNegative = false;
110 const int32 TempBufferSize = 16; // 16 is big enough
112 int32 TempAt = TempBufferSize; // fill the temp string from the top down.
113
114 // Correctly handle negative numbers and convert to positive integer.
115 if( Num < 0 )
116 {
117 bIsNumberNegative = true;
118 Num = -Num;
119 }
120
121 TempNum[--TempAt] = 0; // NULL terminator
122
123 // Convert to string assuming base ten and a positive integer.
124 do
125 {
126 TempNum[--TempAt] = CharType('0') + (Num % 10);
127 Num /= 10;
128 } while( Num );
129
130 // Append sign as we're going to reverse string afterwards.
132 {
133 TempNum[--TempAt] = CharType('-');
134 }
135
136 const CharType* CharPtr = TempNum + TempAt;
137 const int32 NumChars = TempBufferSize - TempAt - 1;
138 if (NumChars < MaxLen)
139 {
141 }
142 else if (MaxLen > 0)
143 {
144 *Dest = 0;
145 }
146 }
147
148 /*
149 * Fills string buffer with FName including number without forcing converting to wide character
150 */
152 {
153 public:
154
156 {
157 }
158
159 FNameBufferWithNumber(const FName& Name) : bIsWide(false)
160 {
162 }
163
164 FNameBufferWithNumber(const FNameEntry* const NameEntry, int32 NumberInternal) : bIsWide(false)
165 {
166 Init(NameEntry, NumberInternal);
167 }
168
169 FORCEINLINE void Init(const FName& Name)
170 {
172 }
173
174 FORCEINLINE void Init(const FNameEntry* const NameEntry, int32 NumberInternal)
175 {
176 if (NameEntry == nullptr)
177 {
178 bIsWide = true;
179 FCString::Strncpy(WideName, TEXT("*INVALID*"), NAME_SIZE);
180 return;
181 }
182
183 if (NameEntry->IsWide())
184 {
185 bIsWide = true;
186 NameEntry->GetWideName(_WideName);
187 if (NumberInternal != NAME_NO_NUMBER_INTERNAL)
188 {
189 int32 Len = FCStringWide::Strlen(WideName);
190 WideName[Len++] = TEXT('_');
191 IntToStringBuffer(WideName + Len, NAME_INTERNAL_TO_EXTERNAL(NumberInternal), 16);
192 }
193 }
194 else
195 {
196 bIsWide = false;
197 NameEntry->GetAnsiName(_AnsiName);
198 if (NumberInternal != NAME_NO_NUMBER_INTERNAL)
199 {
200 int32 Len = FCStringAnsi::Strlen(AnsiName);
201 AnsiName[Len++] = '_';
202 IntToStringBuffer(AnsiName + Len, NAME_INTERNAL_TO_EXTERNAL(NumberInternal), 16);
203 }
204 }
205 }
206
207 FORCEINLINE bool IsWide() const
208 {
209 return bIsWide;
210 }
211
213 {
214 checkSlow(!IsWide());
215 return AnsiName;
216 }
217
219 {
220 checkSlow(IsWide());
221 return WideName;
222 }
223
225 {
227 }
228
229 private:
230
232
233 union
234 {
239 };
240 };
241
242 /** Convert a wide string to ansi if all characters are ansi */
243 bool TryConvertWideToAnsi(const FString& SourceWideString, TArray<ANSICHAR>& DestAnsiString);
244
245 /** Compare FNameEntry vs Wide or Ansi string */
246 int32 NameStrincmp(const FName& Name, const FString& WideOther, const TArray<ANSICHAR>& AnsiOther, int32 Length);
247
248 /** Utility function to perform a basic string test for the given values */
249 bool TestBasicStringExpression(const FTextFilterString& InValue1, const FTextFilterString& InValue2, const ETextFilterTextComparisonMode InTextComparisonMode);
250
251 /** Utility function to perform a complex expression test for the given values */
252 bool TestComplexExpression(const FTextFilterString& InValue1, const FTextFilterString& InValue2, const ETextFilterComparisonOperation InComparisonOperation, const ETextFilterTextComparisonMode InTextComparisonMode);
253}
#define checkSlow(expr)
#define NAME_NO_NUMBER_INTERNAL
Definition NameTypes.h:141
#define NAME_INTERNAL_TO_EXTERNAL(x)
Definition NameTypes.h:144
@ NAME_SIZE
Definition NameTypes.h:43
#define TEXT(x)
Definition Platform.h:1108
#define FORCEINLINE
Definition Platform.h:644
ETextFilterTextComparisonMode
@ NAME_WITH_NUMBER_SIZE
ETextFilterComparisonOperation
FORCEINLINE int32 GetNumber() const
Definition NameTypes.h:625
const FNameEntry * GetDisplayNameEntry() const
FTextFilterString(FTextFilterString &&Other)
bool CompareFString(const FString &InOther, const ETextFilterTextComparisonMode InTextComparisonMode) const
FTextFilterString & operator=(const FTextFilterString &Other)
FTextFilterString & operator=(FTextFilterString &&Other)
FORCEINLINE const FString & AsString() const
FORCEINLINE FName AsName() const
FTextFilterString(const FName &InName)
FTextFilterString(const FTextFilterString &Other)
bool CanCompareNumeric(const FTextFilterString &InOther) const
void UppercaseInternalString()
bool CompareName(const FName &InOther, const ETextFilterTextComparisonMode InTextComparisonMode) const
FTextFilterString(FString &&InString)
FTextFilterString(const TCHAR *InString)
bool CompareNumeric(const FTextFilterString &InOther, const ETextFilterComparisonOperation InComparisonOperation) const
bool CompareText(const FTextFilterString &InOther, const ETextFilterTextComparisonMode InTextComparisonMode) const
FORCEINLINE bool IsEmpty() const
TArray< ANSICHAR > InternalStringAnsi
FTextFilterString(const FString &InString)
void IntToStringBuffer(CharType *Dest, int32 Source, int32 MaxLen)
bool TestComplexExpression(const FTextFilterString &InValue1, const FTextFilterString &InValue2, const ETextFilterComparisonOperation InComparisonOperation, const ETextFilterTextComparisonMode InTextComparisonMode)
int32 NameStrincmp(const FName &Name, const FString &WideOther, const TArray< ANSICHAR > &AnsiOther, int32 Length)
bool TryConvertWideToAnsi(const FString &SourceWideString, TArray< ANSICHAR > &DestAnsiString)
bool TestBasicStringExpression(const FTextFilterString &InValue1, const FTextFilterString &InValue2, const ETextFilterTextComparisonMode InTextComparisonMode)
Definition NameTypes.h:221
void GetAnsiName(ANSICHAR(&OutName)[NAME_SIZE]) const
void GetWideName(WIDECHAR(&OutName)[NAME_SIZE]) const
FORCEINLINE bool IsWide() const
Definition NameTypes.h:251
FORCEINLINE WIDECHAR * GetWideNamePtr()
FORCEINLINE ANSICHAR * GetAnsiNamePtr()
FORCEINLINE void Init(const FName &Name)
WIDECHAR WideName[NAME_WITH_NUMBER_SIZE]
FORCEINLINE void Init(const FNameEntry *const NameEntry, int32 NumberInternal)
ANSICHAR AnsiName[NAME_WITH_NUMBER_SIZE]
FNameBufferWithNumber(const FNameEntry *const NameEntry, int32 NumberInternal)