From b50d2becfc1441f00b800ccf6ac8700dc70df83d Mon Sep 17 00:00:00 2001 From: Brian Fiete Date: Wed, 8 Feb 2023 10:18:23 -0500 Subject: [PATCH] StrRemoveColors --- BeefLibs/Beefy2D/src/gfx/Font.bf | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/BeefLibs/Beefy2D/src/gfx/Font.bf b/BeefLibs/Beefy2D/src/gfx/Font.bf index 82fb96ca..2e3f49a8 100644 --- a/BeefLibs/Beefy2D/src/gfx/Font.bf +++ b/BeefLibs/Beefy2D/src/gfx/Font.bf @@ -705,6 +705,33 @@ namespace Beefy.gfx return '\x02'; } + public static void StrRemoveColors(StringView theString, String str) + { + int len = theString.Length; + if (len == 0) + { + return; + } + + for (var c in theString.DecodedChars) + { + int idx = @c.NextIndex; + if (c == (char32)'\x01') + { + @c.NextIndex = idx + 4; + continue; + } + else if (c == (char32)'\x02') + { + continue; + } + str.Append(c); + + if (idx >= len) + break; + } + } + public void Draw(Graphics g, StringView theString, FontMetrics* fontMetrics = null) { if (mFTFont == null)