MCRO
C++23 utilities for Unreal Engine.
Loading...
Searching...
No Matches
Text.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#pragma once
13
14#include <string>
15
16#include "CoreMinimal.h"
17#include "Mcro/Concepts.h"
18
19namespace Mcro::Text
20{
21 using namespace Mcro::Concepts;
22
23 using FUtf16StringView = TStringView<UTF16CHAR>;
24 using FUtf32StringView = TStringView<UTF32CHAR>;
25
26#if PLATFORM_TCHAR_IS_UTF8CHAR
27 using FStdString = std::string;
28 using FStdStringView = std::string_view;
29#else
30 using FStdString = std::wstring;
31 using FStdStringView = std::wstring_view;
32#endif
33
34 template<typename T>
35 concept CStringView = CSameAsDecayed<T, TStringView<typename T::ElementType>>;
36
37 template<typename T>
38 concept CStringOrView = CSameAsDecayed<T, FString> || CStringView<T>;
39
40 template<typename T>
41 concept CStringOrViewOrName = CStringOrView<T> || CSameAsDecayed<T, FName>;
42
43 template <typename T>
44 concept CStdStringOrViewUtf8 = CConvertibleToDecayed<T, std::string_view>;
45
46 template <typename T>
47 concept CStdStringOrViewWide = CConvertibleToDecayed<T, std::wstring_view>;
48
49 template <typename T>
50 concept CStdStringOrView = CConvertibleToDecayed<T, FStdStringView>;
51
52 template <typename T>
54
55 MCRO_API FStringView UnrealView(FStdStringView const& stdStr);
56 MCRO_API FUtf8StringView UnrealViewUtf8(std::string_view const& stdStr);
57 MCRO_API FUtf16StringView UnrealViewUtf16(std::wstring_view const& stdStr);
58 MCRO_API FStdStringView StdView(FString const& unrealStr);
59 MCRO_API FStdStringView StdView(FStringView const& unrealStr);
60 MCRO_API std::string_view StdView(FUtf8StringView const& unrealStr);
61 MCRO_API std::wstring_view StdView(FUtf16StringView const& unrealStr);
62
63 MCRO_API FString UnrealCopy(FStdStringView const& stdStr);
64 MCRO_API FString UnrealConvert(std::string_view const& stdStr);
65 MCRO_API FString UnrealConvert(std::wstring_view const& stdStr);
66
67 MCRO_API FName UnrealNameCopy(FStdStringView const& stdStr);
68 MCRO_API FName UnrealNameConvert(std::string_view const& stdStr);
69 MCRO_API FName UnrealNameConvert(std::wstring_view const& stdStr);
70
71 MCRO_API FStdString StdCopy(FStringView const& unrealStr);
72 MCRO_API FStdString StdCopy(FName const& unrealStr);
73 MCRO_API std::string StdConvertUtf8(FStringView const& unrealStr);
74 MCRO_API std::wstring StdConvertWide(FStringView const& unrealStr);
75
76 MCRO_API std::string StdConvertUtf8(FStdStringView const& stdStr);
77 MCRO_API std::wstring StdConvertWide(FStdStringView const& stdStr);
78
79 MCRO_API std::string StdConvertUtf8(FName const& unrealName);
80 MCRO_API std::wstring StdConvertWide(FName const& unrealName);
81
82 template <CSameAs<FString>... Args>
83 FString Join(const TCHAR* separator, Args... args)
84 {
85 return FString::Join(
86 TArray<FString>{args...}.FilterByPredicate([](const FString& str) { return !str.IsEmpty(); }),
87 separator
88 );
89 }
90
91 /** Copy of FString::PrintfImpl but not private so it can work with strings which were not literals */
92 MCRO_API FString DynamicPrintf(const TCHAR* fmt, ...);
93}
FString Join(const TCHAR *separator, Args... args)
Definition Text.h:83
MCRO_API std::string StdConvertUtf8(FStringView const &unrealStr)
MCRO_API FString DynamicPrintf(const TCHAR *fmt,...)
MCRO_API FString UnrealConvert(std::string_view const &stdStr)
MCRO_API FUtf16StringView UnrealViewUtf16(std::wstring_view const &stdStr)
std::wstring FStdString
Definition Text.h:30
MCRO_API FStringView UnrealView(FStdStringView const &stdStr)
MCRO_API FStdStringView StdView(FString const &unrealStr)
MCRO_API FName UnrealNameConvert(std::string_view const &stdStr)
TStringView< UTF16CHAR > FUtf16StringView
Definition Text.h:23
MCRO_API FName UnrealNameCopy(FStdStringView const &stdStr)
TStringView< UTF32CHAR > FUtf32StringView
Definition Text.h:24
MCRO_API std::wstring StdConvertWide(FStringView const &unrealStr)
MCRO_API FString UnrealCopy(FStdStringView const &stdStr)
MCRO_API FUtf8StringView UnrealViewUtf8(std::string_view const &stdStr)
MCRO_API FStdString StdCopy(FStringView const &unrealStr)
std::wstring_view FStdStringView
Definition Text.h:31