MCRO
C++23 utilities for Unreal Engine.
Loading...
Searching...
No Matches
TextMacros.h
Go to the documentation of this file.
1/** @noop License Comment
2 * @file
3 * @copyright
4 * This Source Code is subject to the terms of the Mozilla Public License, v2.0.
5 * If a copy of the MPL was not distributed with this file You can obtain one at
6 * https://mozilla.org/MPL/2.0/
7 *
8 * @author David Mórász
9 * @date 2025
10 */
11
12/**
13 * @file
14 * @brief
15 * Use leading `TEXT_` without parenthesis for Unreal compatible text literals.
16 */
17
18#pragma once
19
20#include "CoreMinimal.h"
21#include "Mcro/FunctionTraits.h"
22
23#define UTF8TEXT_PASTE_ u8""
24#define UTF16TEXT_PASTE_ u""
25
26#if PLATFORM_WIDECHAR_IS_CHAR16
27 #define WIDETEXT_PASTE_ UTF16TEXT_PASTE_
28#else
29 #define WIDETEXT_PASTE_ L""
30#endif
31
32#define UTF8TEXT_ UTF8TEXT_PASTE_ // TODO: UE::Core::Private::ToUTF8Literal with operator?
33#define UTF16TEXT_ UTF16TEXT_PASTE_
34#define WIDETEXT_ WIDETEXT_PASTE_
35
36#if PLATFORM_TCHAR_IS_UTF8CHAR
37 #define TEXT_PASTE_ UTF8TEXT_
38#else
39 #define TEXT_PASTE_ WIDETEXT_
40#endif
41
42/**
43 * @brief
44 * A convenience alternative to Unreal's own `TEXT` macro but this one doesn't require parenthesis around the text
45 * literal, relying on string literal concatenation rules of C++
46 */
47#define TEXT_ TEXT_PASTE_
48
49/** @brief This namespace is used by MCRO text literal macros, don't use it directly! */
51{
52 using namespace Mcro::FunctionTraits;
53
54 FORCEINLINE FText AsLocalizable_Advanced(const FTextKey& Namespace, const FTextKey& Key, const TCHAR* String)
55 {
56 return FText::AsLocalizable_Advanced(Namespace, Key, String);
57 }
59
60 FORCEINLINE FText AsCultureInvariant(const TCHAR* String)
61 {
62 return FText::AsCultureInvariant(String);
63 }
65}
66
67template <auto FunctionPtr>
69{
70 return deferrer(literal);
71}
72
73/**
74 * @brief
75 * A convenience alternative to Unreal's own `LOCTEXT` macro but this one doesn't require parenthesis around the text literal
76 */
77#define LOCTEXT_(key) \
78 Mcro::Text::Macros::FDefer_AsLocalizable_Advanced(TEXT(LOCTEXT_NAMESPACE), TEXT(key)) / TEXT_
79
80/**
81 * @brief
82 * A convenience alternative to Unreal's own `NSLOCTEXT` macro but this one doesn't require parenthesis around the text literal
83 */
84#define NSLOCTEXT_(ns, key) \
85 Mcro::Text::Macros::FDefer_AsLocalizable_Advanced(TEXT(ns), TEXT(key)) / TEXT_
86
87/**
88 * @brief
89 * A convenience alternative to Unreal's own `INVTEXT` macro but this one doesn't require parenthesis around the text literal
90 */
91#define INVTEXT_ \
92 Mcro::Text::Macros::FDefer_AsCultureInvariant() / TEXT_
auto operator/(Mcro::FunctionTraits::TDeferFunctionArguments< FunctionPtr > &&deferrer, const TCHAR *literal)
Definition TextMacros.h:68
This namespace is used by MCRO text literal macros, don't use it directly!
Definition TextMacros.h:51
FORCEINLINE FText AsLocalizable_Advanced(const FTextKey &Namespace, const FTextKey &Key, const TCHAR *String)
Definition TextMacros.h:54
FORCEINLINE FText AsCultureInvariant(const TCHAR *String)
Definition TextMacros.h:60
Defers a set of arguments for a function call later with its first argument. This is useful for devel...