![]() |
MCRO
C++23 utilities for Unreal Engine.
|
Use leading FMT_ or trailing _FMT fake text literals to create modern formatted strings with a better API.
More...
#include <string>#include "CoreMinimal.h"#include "Mcro/Text.h"#include "Mcro/TextMacros.h"#include "Mcro/Enums.h"#include "Mcro/Macros.h"Go to the source code of this file.
Macros | |
| #define | MCRO_FMT_NAMED_ARG_TRANSFORM(s, data, elem) |
| #define | MCRO_FMT_NAMED_ARG(key, value) |
| #define | MCRO_FMT_NAMED(seq) |
| #define | MCRO_FMT_NAMED_0(seq) |
| #define | MCRO_FMT_ORDERED(...) |
| #define | MCRO_FMT_ARGS(...) |
| #define | FMT_(...) |
Leading fake text literal which makes using FString::Format(...); much more comfortable. | |
| #define | _FMT(...) |
Trailing fake text literal which makes using FString::Format(...); much more comfortable. | |
| #define | FMT_LOG(categoryName, verbosity, format, ...) |
Similar to UE_LOGFMT, but implemented via MCRO's own _FMT macro. So it's more convenient to pass format arguments. | |
Functions | |
| template<size_t N> | |
| FString | operator% (FStringFormatOrderedArguments &&args, const TCHAR(&format)[N]) |
| template<size_t N> | |
| FString | operator% (const TCHAR(&format)[N], FStringFormatOrderedArguments &&args) |
| template<size_t N> | |
| FString | operator% (FStringFormatNamedArguments &&args, const TCHAR(&format)[N]) |
| template<size_t N> | |
| FString | operator% (const TCHAR(&format)[N], FStringFormatNamedArguments &&args) |
| FORCEINLINE FText | operator% (FText const &format, FStringFormatOrderedArguments &&args) |
| FORCEINLINE FText | operator% (FText const &format, FStringFormatNamedArguments &&args) |
Use leading FMT_ or trailing _FMT fake text literals to create modern formatted strings with a better API.
The major difference from PRINTF_ or FString::Printf(...) is that FMT macros can take user defined string conversions into account, so more types can be used directly as arguments.
Definition in file FmtMacros.h.
| #define _FMT | ( | ... | ) |
Trailing fake text literal which makes using FString::Format(...); much more comfortable.
FMT macros allow more types to be used directly in the format arguments expression because Mcro::Text has a couple of conversion utilities. If the first argument of _FMT is a sequence of ("key", value) pairs enclosed in parentheses, then named format arguments are assumed. Ordered format arguments are assumed otherwise. The two modes cannot be mixed.
Usage:
The following argument types are supported out-of-box:
FStringFormatArg and what's implicitly convertable toFString, FStringView, int32, uint32, int64, uint64, float, doubleANSICHAR, WIDECHAR, UCS2CHAR, UTF8CHAR pointer stringsToString() member method which produces one of the above typeFText and FName for exampleThis variant also allows to operate on FText instead of const TCHAR* strings if the fake string literal macro before _FMT yields FText. This version however still uses FString's under the hood, and it is not yet using vanilla FText::Format features
TAsFormatArgument template functor for your preferred type and return a value which is implicitly convertible to FStringFormatArg in the Mcro::Text namespace. For example check Enums.h to see how that's done with enums. For your own types you can also implement a ToString() member method to get automatic support._FMT((A, a) (B, b) (C, c))) must not have comma , between the individual pairs. This is because named argument pairs are passed into this macro as a "sequence" instead of variadic arguments. Ordered format arguments however should be passed in as regular variadic arguments separated by comma , as nature intended.FMT macros are the only things in MCRO where excessive preprocessing is used Definition at line 208 of file FmtMacros.h.
| #define FMT_ | ( | ... | ) |
Leading fake text literal which makes using FString::Format(...); much more comfortable.
FMT macros allow more types to be used directly in the format arguments expression because Mcro::Text has a couple of conversion utilities. If the first argument of FMT_ is a sequence of ("key", value) pairs enclosed in parentheses, then named format arguments are assumed. Ordered format arguments are assumed otherwise. The two modes cannot be mixed.
Usage:
The following argument types are supported out-of-box:
FStringFormatArg and what's implicitly convertable toFString, FStringView, int32, uint32, int64, uint64, float, doubleANSICHAR, WIDECHAR, UCS2CHAR, UTF8CHAR pointer stringsToString() member method which produces one of the above typeFText and FName for exampleTAsFormatArgument template functor for your preferred type and return a value which is implicitly convertible to FStringFormatArg in the Mcro::Text namespace. For example check Enums.h to see how that's done with enums. For your own types you can also implement a ToString() member method to get automatic support.FMT_((A, a) (B, b) (C, c))) must not have comma , between the individual pairs. This is because named argument pairs are passed into this macro as a "sequence" instead of variadic arguments. Ordered format arguments however should be passed in as regular variadic arguments separated by comma , as nature intended.FMT macros are the only things in MCRO where excessive preprocessing is used Definition at line 154 of file FmtMacros.h.
| #define FMT_LOG | ( | categoryName, | |
| verbosity, | |||
| format, | |||
| ... ) |
Similar to UE_LOGFMT, but implemented via MCRO's own _FMT macro. So it's more convenient to pass format arguments.
This is naively implemented via regular UE_LOG which gets a single string format argument which is fed the result of the _FMT macro. UE_LOGFMT may have better performance or may have more insights to format arguments.
The same argument syntax applies here as with _FMT regarding the distinction between named and ordered arguments.
Named arguments:
Ordered arguments:
Definition at line 246 of file FmtMacros.h.
| #define MCRO_FMT_ARGS | ( | ... | ) |
Definition at line 102 of file FmtMacros.h.
| #define MCRO_FMT_NAMED | ( | seq | ) |
Definition at line 84 of file FmtMacros.h.
| #define MCRO_FMT_NAMED_0 | ( | seq | ) |
Definition at line 90 of file FmtMacros.h.
| #define MCRO_FMT_NAMED_ARG | ( | key, | |
| value ) |
Definition at line 82 of file FmtMacros.h.
| #define MCRO_FMT_NAMED_ARG_TRANSFORM | ( | s, | |
| data, | |||
| elem ) |
Definition at line 81 of file FmtMacros.h.
| #define MCRO_FMT_ORDERED | ( | ... | ) |
Definition at line 100 of file FmtMacros.h.
| FString operator% | ( | const TCHAR(&) | format[N], |
| FStringFormatNamedArguments && | args ) |
Definition at line 60 of file FmtMacros.h.
| FString operator% | ( | const TCHAR(&) | format[N], |
| FStringFormatOrderedArguments && | args ) |
Definition at line 44 of file FmtMacros.h.
| FString operator% | ( | FStringFormatNamedArguments && | args, |
| const TCHAR(&) | format[N] ) |
Definition at line 52 of file FmtMacros.h.
| FString operator% | ( | FStringFormatOrderedArguments && | args, |
| const TCHAR(&) | format[N] ) |
Definition at line 36 of file FmtMacros.h.
| FORCEINLINE FText operator% | ( | FText const & | format, |
| FStringFormatNamedArguments && | args ) |
Definition at line 74 of file FmtMacros.h.
| FORCEINLINE FText operator% | ( | FText const & | format, |
| FStringFormatOrderedArguments && | args ) |
Definition at line 67 of file FmtMacros.h.