Plasma Engine  2.0
Loading...
Searching...
No Matches
FormatString.h
1#pragma once
2
3#ifndef PL_INCLUDING_BASICS_H
4# error "Please don't include FormatString.h directly, but instead include Foundation/Basics.h"
5#endif
6
8
9#include <Foundation/Strings/StringView.h>
10
11#include <Foundation/Strings/Implementation/FormatStringArgs.h>
12
58class PL_FOUNDATION_DLL plFormatString
59{
60 PL_DISALLOW_COPY_AND_ASSIGN(plFormatString); // pass by reference, never pass by value
61
62public:
63 PL_ALWAYS_INLINE plFormatString() = default;
64 PL_ALWAYS_INLINE plFormatString(const char* szString) { m_sString = szString; }
65 PL_ALWAYS_INLINE plFormatString(plStringView sString) { m_sString = sString; }
67 virtual ~plFormatString() = default;
68
76 [[nodiscard]] virtual plStringView GetText(plStringBuilder&) const { return m_sString; }
77
80 virtual const char* GetTextCStr(plStringBuilder& out_sString) const;
81
82 bool IsEmpty() const { return m_sString.IsEmpty(); }
83
87 plStringView BuildFormattedText(plStringBuilder& ref_sStorage, plStringView* pArgs, plUInt32 uiNumArgs) const;
88
89protected:
90 plStringView m_sString;
91};
92
93#include <Foundation/Strings/Implementation/FormatStringImpl.h>
94
95template <typename... ARGS>
96PL_ALWAYS_INLINE plFormatStringImpl<ARGS...> plFmt(const char* szFormat, ARGS&&... args)
97{
98 return plFormatStringImpl<ARGS...>(szFormat, std::forward<ARGS>(args)...);
99}
Implements formating of strings with placeholders and formatting options.
Definition FormatString.h:59
virtual plStringView GetText(plStringBuilder &) const
Generates the formatted text. Make sure to only call this function once and only when the formatted s...
Definition FormatString.h:76
Definition FormatStringImpl.h:9
plStringBuilder is a class that is meant for creating and modifying strings.
Definition StringBuilder.h:35
plStringView represent a read-only sub-string of a larger string, as it can store a dedicated string ...
Definition StringView.h:34