Batch #13855 by eAthena: 0 byte-identical, 1 confirmed by peer review. - fn_13883 StripColorTokens: logic confirmed by peer review Peer-reviewed-by: Yommy, KWDev, StrawberrysherbetIX Accepted without human review: peers confirmed the logic ("same" ahead by at least 3, with 70% of the votes).
65 lines
2.1 KiB
C++
65 lines
2.1 KiB
C++
#include "Utility/Text/TextTokens.h"
|
|
|
|
#include <cstring>
|
|
|
|
// GLOBAL: gl_24548
|
|
const unsigned char g_colorHexDigit[256] = {
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0,
|
|
0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
|
|
};
|
|
|
|
// GLOBAL: gl_24543
|
|
unsigned char g_inlineCharset = 0xFF;
|
|
|
|
// OFFSET: 0x0054FF10
|
|
// FUNCTION: fn_01963
|
|
bool IsPipeColorToken(const char* text) {
|
|
return g_inlineCharset == 0 && std::strlen(text) >= 3 && *text == '|' &&
|
|
g_colorHexDigit[static_cast<unsigned char>(text[1])] != 0 && g_colorHexDigit[static_cast<unsigned char>(text[2])] != 0;
|
|
}
|
|
|
|
// OFFSET: 0x0054FF60
|
|
// FUNCTION: fn_01964
|
|
bool IsHexColorToken(const char* text, const char* end) {
|
|
if (*text != '^' || end - text <= 6) {
|
|
return false;
|
|
}
|
|
|
|
for (int index = 1; index <= 6; ++index) {
|
|
if (g_colorHexDigit[static_cast<signed char>(text[index])] == 0) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
// OFFSET: 0x009BA740
|
|
// FUNCTION: fn_13883
|
|
std::string __stdcall StripColorTokens(const char* text, std::uint32_t length) {
|
|
std::string result;
|
|
result.reserve(length);
|
|
if (text == nullptr) {
|
|
return result;
|
|
}
|
|
|
|
const char* current = text;
|
|
const char* end = text + length;
|
|
while (current < end) {
|
|
if (IsHexColorToken(current, end)) {
|
|
current += 7;
|
|
} else if (IsPipeColorToken(current)) {
|
|
current += 3;
|
|
} else {
|
|
result.push_back(*current++);
|
|
}
|
|
}
|
|
|
|
return result;
|
|
}
|