From 220f110e298a211d0f508ed33bae0fa9e9bf4689 Mon Sep 17 00:00:00 2001 From: Aki Date: Tue, 12 Apr 2022 18:00:33 +0200 Subject: Added simple formatting function for Text --- FoundationEx/Text.cpp | 13 +++++++++++++ FoundationEx/Text.h | 1 + 2 files changed, 14 insertions(+) (limited to 'FoundationEx') diff --git a/FoundationEx/Text.cpp b/FoundationEx/Text.cpp index df828f7..ac86d5e 100644 --- a/FoundationEx/Text.cpp +++ b/FoundationEx/Text.cpp @@ -14,6 +14,7 @@ #include "Text.h" #include +#include #include // +-------------------------------------------------------------------+ @@ -655,3 +656,15 @@ Text::replace(const char* pattern, const char* substitution) return result; } + +Text +Text::format(const char* fmt, ...) +{ + char buf[2048]; + std::va_list args; + va_start(args, fmt); + int len = std::vsnprintf(buf, 2048, fmt, args); + Text result(buf, len); + va_end(args); + return result; +} diff --git a/FoundationEx/Text.h b/FoundationEx/Text.h index 736c6b9..b498689 100644 --- a/FoundationEx/Text.h +++ b/FoundationEx/Text.h @@ -125,6 +125,7 @@ public: Text substring(int start, int length); Text trim(); Text replace(const char* pattern, const char* substitution); + static Text format(const char* fmt, ...); private: void clone(); -- cgit v1.1