CS Code convertion
Code convertion
Types
csString -> psString or FString
psStringArray with TArray<psString>
uint -> uint32
csHash<Value,Key> -> TMap<Key,Value> (notice the swap of Key and Value)
csArray<> -> TArray
csTicks -> time_t
csGetTicks() -> time(0)
Types conversion
FString to char* -> const char *myData = TCHAR_TO_ANSI(*NameString);
FString to TCHAR -> *myFString
char* to FString -> ANSI_TO_TCHAR(NameString);
Functions
Replace string.Format("hey %s", string) with string.Printf(TEXT("hey %s"), string)
csString.Truncate(5) -> FString.Left(5)
csString.DeleteAt(start,count) -> FString.RemoveAt(start,count)
csString.Downcase() -> FString.ToLower()
output.Insert(0, time_buffer) -> output.InsertAt(0, time_buffer)
output.GetAt(output.Length()-1) -> output [ output.Len()-1 ]
Cross platform types are defined in Platform.h , like uint32. Those can be included with #include "EngineMinimal.h"
CS_ASSERT() -> check()
strcasecmp and strcmp, I added those two defines, so the code can stay as it is
#define strcasecmp(expr1,expr2) FCString::Strcmp( ANSI_TO_TCHAR(expr1), ANSI_TO_TCHAR(expr2)) == 0 #define strcmp(expr1,expr2) FCString::Stricmp( ANSI_TO_TCHAR(expr1), ANSI_TO_TCHAR(expr2)) == 0
CPrintf(CON_CMDOUTPUT,str.GetDataSafe()); -> UE_LOG(LogTemp, Warning, TEXT("%s"), str);
time(NULL) -> FString buf = FDateTime().GetDate().ToString();
FText and Localization
FText is Unreal's class for user viewable strings. It is localizable. See https://docs.unrealengine.com/latest/INT/Programming/UnrealArchitecture/StringHandling/FText/index.html
Platform specific includes
If you want to include some code for a specific platform you can use:
- ifdef PLATFORM_WINDOWS
your stuff here
- endif