mirror of
https://github.com/RGBCube/serenity
synced 2025-05-23 15:45:06 +00:00

GemRB is an open-source implementation of the Infinity engine by Bioware, used in some of their classic role-playing games.
35 lines
1.4 KiB
Diff
35 lines
1.4 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: =?UTF-8?q?Julian=20Offenh=C3=A4user?= <offenhaeuser@protonmail.com>
|
|
Date: Sat, 11 Feb 2023 00:52:51 +0100
|
|
Subject: [PATCH] Get rid of swscanf() usage
|
|
|
|
This function is currently not implemented in our LibC.
|
|
---
|
|
gemrb/core/GUI/TextSystem/GemMarkup.cpp | 14 +++++++++++++-
|
|
1 file changed, 13 insertions(+), 1 deletion(-)
|
|
|
|
diff --git a/gemrb/core/GUI/TextSystem/GemMarkup.cpp b/gemrb/core/GUI/TextSystem/GemMarkup.cpp
|
|
index f0f604ccb0c3d37098976f0e05371fb4a1988a67..2741aa6cd6b27961ac9bcd11992cb6cef4fa2a9f 100644
|
|
--- a/gemrb/core/GUI/TextSystem/GemMarkup.cpp
|
|
+++ b/gemrb/core/GUI/TextSystem/GemMarkup.cpp
|
|
@@ -25,7 +25,19 @@ namespace GemRB {
|
|
static Color ParseColor(const String& colorString)
|
|
{
|
|
Color color = ColorWhite;
|
|
- swscanf(colorString.c_str(), L"%02hhx%02hhx%02hhx%02hhx", &color.r, &color.g, &color.b, &color.a);
|
|
+
|
|
+ auto h2i = [](wchar_t c) -> int {
|
|
+ if (c >= '0' && c <= '9') return c - '0';
|
|
+ else if (c >= 'a' && c <='f') return c - 'a' + 10;
|
|
+ else if (c >= 'A' && c <='F') return c - 'A' + 10;
|
|
+ return 0;
|
|
+ };
|
|
+
|
|
+ color.r = (h2i(colorString[0]) << 4) | h2i(colorString[1]);
|
|
+ color.g = (h2i(colorString[2]) << 4) | h2i(colorString[3]);
|
|
+ color.b = (h2i(colorString[4]) << 4) | h2i(colorString[5]);
|
|
+ color.a = (h2i(colorString[6]) << 4) | h2i(colorString[7]);
|
|
+
|
|
return color;
|
|
}
|
|
|