UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
LazyPrintf.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "CoreTypes.h"
8
9// to avoid limits with the Printf parameter count, for more readability and type safety
11{
12public:
13 // constructor
15 : CurrentInputPos(InputWithPercentS)
16 {
17 // to avoid reallocations
18 CurrentState.Empty(50 * 1024);
19 }
20
22 {
23 // internal error more %s than %s in MaterialTemplate.usf
24 check(!ProcessUntilPercentS());
25
26 // copy all remaining input data
27 CurrentState += CurrentInputPos;
28
29 return CurrentState;
30 }
31
32 // %s
33 void PushParam(const TCHAR* Data)
34 {
35 if(ProcessUntilPercentS())
36 {
37 CurrentState += Data;
38 }
39 else
40 {
41 // internal error, more ReplacePercentS() calls than %s in MaterialTemplate.ush
42 check(0);
43 }
44 }
45
46private:
47
48 // @param Pattern e.g. TEXT("%s")
49 bool ProcessUntilPercentS()
50 {
51 const TCHAR* Found = FCString::Strstr(CurrentInputPos, TEXT("%s"));
52
53 if(Found == 0)
54 {
55 return false;
56 }
57
58 // copy from input until %s
59 while(CurrentInputPos < Found)
60 {
61 // can cause reallocations we could avoid
62 CurrentState += *CurrentInputPos++;
63 }
64
65 // jump over %s
66 CurrentInputPos += 2;
67
68 return true;
69 }
70
71 const TCHAR* CurrentInputPos;
72 FString CurrentState;
73};
#define check(expr)
Definition AssertionMacros.h:314
#define TEXT(x)
Definition Platform.h:1272
FPlatformTypes::TCHAR TCHAR
Either ANSICHAR or WIDECHAR, depending on whether the platform supports wide characters or the requir...
Definition Platform.h:1135
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
Definition LazyPrintf.h:11
FString GetResultString()
Definition LazyPrintf.h:21
FLazyPrintf(const TCHAR *InputWithPercentS)
Definition LazyPrintf.h:14
void PushParam(const TCHAR *Data)
Definition LazyPrintf.h:33
static UE_FORCEINLINE_HINT const CharType * Strstr(const CharType *String, const CharType *Find)
Definition CString.h:1066