diff options
author | Aki <please@ignore.pl> | 2022-04-12 18:00:33 +0200 |
---|---|---|
committer | Aki <please@ignore.pl> | 2022-04-12 18:00:33 +0200 |
commit | 220f110e298a211d0f508ed33bae0fa9e9bf4689 (patch) | |
tree | e8189e5adacbef69f2d5ad0d58551c411c85c3df /FoundationEx | |
parent | e21edf8b0b2b3bfd054f34664d8425bcd64adb78 (diff) | |
download | starshatter-220f110e298a211d0f508ed33bae0fa9e9bf4689.zip starshatter-220f110e298a211d0f508ed33bae0fa9e9bf4689.tar.gz starshatter-220f110e298a211d0f508ed33bae0fa9e9bf4689.tar.bz2 |
Added simple formatting function for Text
Diffstat (limited to 'FoundationEx')
-rw-r--r-- | FoundationEx/Text.cpp | 13 | ||||
-rw-r--r-- | FoundationEx/Text.h | 1 |
2 files changed, 14 insertions, 0 deletions
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 <cctype> +#include <cstdarg> #include <cstring> // +-------------------------------------------------------------------+ @@ -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(); |