rework of the color code with & and standard codes (#5416)
* adding build* to gitignore and tags for ctags * Notation Changes * Adding & Parser * Avoid crash when & as first character * Looking for @ in the rest of the project * Formating style * Modifying test to reflect new behaviours * Adding a check for the first part * fixup! Adding & Parser style changes * Update APIDesk.lua * Update src/CompositeChat.cpp Co-authored-by: x12xx12x <44411062+12xx12@users.noreply.github.com> * explaination on the antishlash with ampersand * adding old deprecated formating * Update src/CompositeChat.cpp Co-authored-by: x12xx12x <44411062+12xx12@users.noreply.github.com> * Update src/CompositeChat.cpp * Update src/CompositeChat.cpp Co-authored-by: Debucquoy <debucqquoy.anthony@gmail.com> Co-authored-by: x12xx12x <44411062+12xx12@users.noreply.github.com>
This commit is contained in:
parent
c61dab94bd
commit
16f3355bbb
4
.gitignore
vendored
4
.gitignore
vendored
@ -1,4 +1,5 @@
|
|||||||
build/
|
build/
|
||||||
|
build*/
|
||||||
nbproject/
|
nbproject/
|
||||||
ipch/
|
ipch/
|
||||||
Win32/
|
Win32/
|
||||||
@ -122,3 +123,6 @@ build-cuberite
|
|||||||
# clang-tidy
|
# clang-tidy
|
||||||
tidy-build
|
tidy-build
|
||||||
run-clang-tidy.py
|
run-clang-tidy.py
|
||||||
|
|
||||||
|
# ctags output
|
||||||
|
tags
|
||||||
|
@ -2228,18 +2228,21 @@ end
|
|||||||
Chaining example below for details.</p>
|
Chaining example below for details.</p>
|
||||||
<p>
|
<p>
|
||||||
Each part of the composite chat message takes a "Style" parameter, this is a string that describes
|
Each part of the composite chat message takes a "Style" parameter, this is a string that describes
|
||||||
the formatting. It uses the following strings, concatenated together:
|
the formatting. It uses the "standard" minecraft format code without the '&' symbole, concatenated
|
||||||
|
together:
|
||||||
<table>
|
<table>
|
||||||
<tr><th>String</th><th>Style</th></tr>
|
<tr><th>String</th><th>Style</th></tr>
|
||||||
<tr><td>b</td><td>Bold text</td></tr>
|
<tr><td>l</td><td>Bold text</td></tr>
|
||||||
<tr><td>i</td><td>Italic text</td></tr>
|
<tr><td>o</td><td>Italic text</td></tr>
|
||||||
<tr><td>u</td><td>Underlined text</td></tr>
|
<tr><td>n</td><td>Underlined text</td></tr>
|
||||||
<tr><td>s</td><td>Strikethrough text</td></tr>
|
<tr><td>m</td><td>Strikethrough text</td></tr>
|
||||||
<tr><td>o</td><td>Obfuscated text</td></tr>
|
<tr><td>k</td><td>Obfuscated text</td></tr>
|
||||||
<tr><td>@X</td><td>color [0–9a–f], same as dye meta</td></tr>
|
<tr><td>r</td><td>Reset Style</td></tr>
|
||||||
|
<tr><td>[0-9a-f]</td><td>colors</td></tr>
|
||||||
</table>
|
</table>
|
||||||
|
You can escape the '&' character with an antislash in front of it. as follow: `I love Choco\&chips`
|
||||||
The following picture, taken from the Minecraft Wiki, illustrates the color codes:</p>
|
The following picture, taken from the Minecraft Wiki, illustrates the color codes:</p>
|
||||||
<img src="http://images.wikia.com/minecraft_gamepedia/images/archive/4/4c/20200824112326!Colors.png" />
|
<img src="https://static.wikia.nocookie.net/minecraft_gamepedia/images/7/7e/Minecraft_Formatting.gif/revision/latest/scale-to-width-down/292?cb=20200828001454" />
|
||||||
]],
|
]],
|
||||||
Functions =
|
Functions =
|
||||||
{
|
{
|
||||||
|
@ -3949,7 +3949,7 @@ static int tolua_cCompositeChat_AddRunCommandPart(lua_State * tolua_S)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add the part:
|
// Add the part:
|
||||||
AString Text, Command, Style = "u@a";
|
AString Text, Command, Style = "na";
|
||||||
L.GetStackValue(2, Text);
|
L.GetStackValue(2, Text);
|
||||||
L.GetStackValue(3, Command);
|
L.GetStackValue(3, Command);
|
||||||
L.GetStackValue(4, Style);
|
L.GetStackValue(4, Style);
|
||||||
|
@ -96,50 +96,52 @@ void cCompositeChat::AddShowAchievementPart(const AString & a_PlayerName, const
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse the input message to add colors or link then add it to the object.
|
||||||
|
*
|
||||||
|
* It detects every & of the message and the next character for it to colorize.
|
||||||
|
* It detect : in the text to detect link structures.
|
||||||
|
*
|
||||||
|
* @param a_ParseText The input text to parse
|
||||||
|
*/
|
||||||
void cCompositeChat::ParseText(const AString & a_ParseText)
|
void cCompositeChat::ParseText(const AString & a_ParseText)
|
||||||
{
|
{
|
||||||
size_t len = a_ParseText.length();
|
size_t len = a_ParseText.length();
|
||||||
size_t first = 0; // First character of the currently parsed block
|
size_t cursor = 0;
|
||||||
AString CurrentStyle;
|
AString CurrentStyle;
|
||||||
AString CurrentText;
|
AString CurrentText;
|
||||||
|
|
||||||
for (size_t i = 0; i < len; i++)
|
for (size_t i = 0; i < len; i++)
|
||||||
{
|
{
|
||||||
switch (a_ParseText[i])
|
switch (a_ParseText[i])
|
||||||
{
|
{
|
||||||
case '@':
|
case '&': //< Color code
|
||||||
{
|
{
|
||||||
// Color code
|
if ((i != 0) && (a_ParseText[i-1] == '\\'))
|
||||||
i++;
|
|
||||||
if (i >= len)
|
|
||||||
{
|
{
|
||||||
// Not enough following text
|
CurrentText.append(a_ParseText, cursor, i - cursor - 1).append("&");
|
||||||
break;
|
AddTextPart(CurrentText, CurrentStyle);
|
||||||
}
|
CurrentText.clear();
|
||||||
if (a_ParseText[i] == '@')
|
cursor = ++i;
|
||||||
{
|
|
||||||
// "@@" escape, just put a "@" into the current text and keep parsing as text
|
|
||||||
if (i > first + 1)
|
|
||||||
{
|
|
||||||
CurrentText.append(a_ParseText.c_str() + first, i - first - 1);
|
|
||||||
}
|
|
||||||
first = i + 1;
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (cursor < i)
|
||||||
|
{
|
||||||
|
CurrentText.append(a_ParseText, cursor, i - cursor);
|
||||||
|
AddTextPart(CurrentText, CurrentStyle);
|
||||||
|
CurrentText.clear();
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
cursor = i + 1;
|
||||||
|
|
||||||
|
if (a_ParseText[i] == 'r')
|
||||||
|
{
|
||||||
|
CurrentStyle = "";
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// True color code. Create a part for the CurrentText and start parsing anew:
|
CurrentStyle.push_back(a_ParseText[i]);
|
||||||
if (i >= first)
|
|
||||||
{
|
|
||||||
CurrentText.append(a_ParseText.c_str() + first, i - first - 1);
|
|
||||||
first = i + 1;
|
|
||||||
}
|
|
||||||
if (!CurrentText.empty())
|
|
||||||
{
|
|
||||||
AddTextPart(CurrentText, CurrentStyle);
|
|
||||||
CurrentText.clear();
|
|
||||||
}
|
|
||||||
AddStyle(CurrentStyle, a_ParseText.substr(i - 1, 2));
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -157,15 +159,15 @@ void cCompositeChat::ParseText(const AString & a_ParseText)
|
|||||||
{
|
{
|
||||||
size_t PrefixLen = Prefix.size();
|
size_t PrefixLen = Prefix.size();
|
||||||
if (
|
if (
|
||||||
(i >= first + PrefixLen) && // There is enough space in front of the colon for the prefix
|
(i >= cursor + PrefixLen) && // There is enough space in front of the colon for the prefix
|
||||||
(std::string_view(a_ParseText).substr(i - PrefixLen, PrefixLen) == Prefix) // the prefix matches
|
(std::string_view(a_ParseText).substr(i - PrefixLen, PrefixLen) == Prefix) // the prefix matches
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
// Add everything before this as a text part:
|
// Add everything before this as a text part:
|
||||||
if (i > first + PrefixLen)
|
if (i > cursor+ PrefixLen)
|
||||||
{
|
{
|
||||||
CurrentText.append(a_ParseText.c_str() + first, i - first - PrefixLen);
|
CurrentText.append(a_ParseText.c_str() + cursor, i - cursor - PrefixLen);
|
||||||
first = i - PrefixLen;
|
cursor= i - PrefixLen;
|
||||||
}
|
}
|
||||||
if (!CurrentText.empty())
|
if (!CurrentText.empty())
|
||||||
{
|
{
|
||||||
@ -181,8 +183,8 @@ void cCompositeChat::ParseText(const AString & a_ParseText)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
AddUrlPart(a_ParseText.substr(first, i - first), a_ParseText.substr(first, i - first), CurrentStyle);
|
AddUrlPart(a_ParseText.substr(cursor, i - cursor), a_ParseText.substr(cursor, i - cursor), CurrentStyle);
|
||||||
first = i;
|
cursor = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} // for Prefix - LinkPrefix[]
|
} // for Prefix - LinkPrefix[]
|
||||||
@ -190,9 +192,11 @@ void cCompositeChat::ParseText(const AString & a_ParseText)
|
|||||||
} // case ':'
|
} // case ':'
|
||||||
} // switch (a_ParseText[i])
|
} // switch (a_ParseText[i])
|
||||||
} // for i - a_ParseText[]
|
} // for i - a_ParseText[]
|
||||||
if (first < len)
|
if (cursor < len)
|
||||||
{
|
{
|
||||||
AddTextPart(a_ParseText.substr(first, len - first), CurrentStyle);
|
CurrentText.clear();
|
||||||
|
CurrentText.append(a_ParseText, cursor, len - cursor);
|
||||||
|
AddTextPart(CurrentText, CurrentStyle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -218,7 +222,7 @@ void cCompositeChat::UnderlineUrls(void)
|
|||||||
{
|
{
|
||||||
[](TextPart & a_Part) { },
|
[](TextPart & a_Part) { },
|
||||||
[](ClientTranslatedPart & a_Part) { },
|
[](ClientTranslatedPart & a_Part) { },
|
||||||
[](UrlPart & a_Part) { a_Part.Style += 'u'; },
|
[](UrlPart & a_Part) { a_Part.Style += 'n'; },
|
||||||
[](RunCommandPart & a_Part) { },
|
[](RunCommandPart & a_Part) { },
|
||||||
[](SuggestCommandPart & a_Part) { },
|
[](SuggestCommandPart & a_Part) { },
|
||||||
[](ShowAchievementPart & a_Part) { },
|
[](ShowAchievementPart & a_Part) { },
|
||||||
@ -276,29 +280,6 @@ eLogLevel cCompositeChat::MessageTypeToLogLevel(eMessageType a_MessageType)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
void cCompositeChat::AddStyle(AString & a_Style, const AString & a_AddStyle)
|
|
||||||
{
|
|
||||||
if (a_AddStyle.empty())
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (a_AddStyle[0] == '@')
|
|
||||||
{
|
|
||||||
size_t idx = a_Style.find('@');
|
|
||||||
if ((idx != AString::npos) && (idx != a_Style.length()))
|
|
||||||
{
|
|
||||||
a_Style.erase(idx, 2);
|
|
||||||
}
|
|
||||||
a_Style.append(a_AddStyle);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
a_Style.append(a_AddStyle);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
AString cCompositeChat::CreateJsonString(bool a_ShouldUseChatPrefixes) const
|
AString cCompositeChat::CreateJsonString(bool a_ShouldUseChatPrefixes) const
|
||||||
{
|
{
|
||||||
Json::Value Message;
|
Json::Value Message;
|
||||||
@ -404,70 +385,34 @@ void cCompositeChat::AddChatPartStyle(Json::Value & a_Value, const AString & a_P
|
|||||||
{
|
{
|
||||||
switch (a_PartStyle[i])
|
switch (a_PartStyle[i])
|
||||||
{
|
{
|
||||||
case 'b':
|
case 'k': a_Value["obfuscated"] = Json::Value(true); break;
|
||||||
{
|
case 'l': a_Value["bold"] = Json::Value(true); break;
|
||||||
// bold
|
case 's': // Deprecated
|
||||||
a_Value["bold"] = Json::Value(true);
|
LOGERROR("Value s in AddChatPartStyle() is deprecated");
|
||||||
break;
|
case 'm': a_Value["strikethrough"] = Json::Value(true); break;
|
||||||
}
|
case 'u': // Deprecated
|
||||||
|
LOGERROR("Value u in AddChatPartStyle() is deprecated");
|
||||||
|
case 'n': a_Value["underlined"] = Json::Value(true); break;
|
||||||
|
case 'i': // Deprecated
|
||||||
|
LOGERROR("Value i in AddChatPartStyle() is deprecated");
|
||||||
|
case 'o': a_Value["italic"] = Json::Value(true); break;
|
||||||
|
case '0': a_Value["color"] = Json::Value("black"); break;
|
||||||
|
case '1': a_Value["color"] = Json::Value("dark_blue"); break;
|
||||||
|
case '2': a_Value["color"] = Json::Value("dark_green"); break;
|
||||||
|
case '3': a_Value["color"] = Json::Value("dark_aqua"); break;
|
||||||
|
case '4': a_Value["color"] = Json::Value("dark_red"); break;
|
||||||
|
case '5': a_Value["color"] = Json::Value("dark_purple"); break;
|
||||||
|
case '6': a_Value["color"] = Json::Value("gold"); break;
|
||||||
|
case '7': a_Value["color"] = Json::Value("gray"); break;
|
||||||
|
case '8': a_Value["color"] = Json::Value("dark_gray"); break;
|
||||||
|
case '9': a_Value["color"] = Json::Value("blue"); break;
|
||||||
|
case 'a': a_Value["color"] = Json::Value("green"); break;
|
||||||
|
case 'b': a_Value["color"] = Json::Value("aqua"); break;
|
||||||
|
case 'c': a_Value["color"] = Json::Value("red"); break;
|
||||||
|
case 'd': a_Value["color"] = Json::Value("light_purple"); break;
|
||||||
|
case 'e': a_Value["color"] = Json::Value("yellow"); break;
|
||||||
|
case 'f': a_Value["color"] = Json::Value("white"); break;
|
||||||
|
|
||||||
case 'i':
|
|
||||||
{
|
|
||||||
// italic
|
|
||||||
a_Value["italic"] = Json::Value(true);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case 'u':
|
|
||||||
{
|
|
||||||
// Underlined
|
|
||||||
a_Value["underlined"] = Json::Value(true);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case 's':
|
|
||||||
{
|
|
||||||
// strikethrough
|
|
||||||
a_Value["strikethrough"] = Json::Value(true);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case 'o':
|
|
||||||
{
|
|
||||||
// obfuscated
|
|
||||||
a_Value["obfuscated"] = Json::Value(true);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case '@':
|
|
||||||
{
|
|
||||||
// Color, specified by the next char:
|
|
||||||
i++;
|
|
||||||
if (i >= len)
|
|
||||||
{
|
|
||||||
// String too short, didn't contain a color
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
switch (a_PartStyle[i])
|
|
||||||
{
|
|
||||||
case '0': a_Value["color"] = Json::Value("black"); break;
|
|
||||||
case '1': a_Value["color"] = Json::Value("dark_blue"); break;
|
|
||||||
case '2': a_Value["color"] = Json::Value("dark_green"); break;
|
|
||||||
case '3': a_Value["color"] = Json::Value("dark_aqua"); break;
|
|
||||||
case '4': a_Value["color"] = Json::Value("dark_red"); break;
|
|
||||||
case '5': a_Value["color"] = Json::Value("dark_purple"); break;
|
|
||||||
case '6': a_Value["color"] = Json::Value("gold"); break;
|
|
||||||
case '7': a_Value["color"] = Json::Value("gray"); break;
|
|
||||||
case '8': a_Value["color"] = Json::Value("dark_gray"); break;
|
|
||||||
case '9': a_Value["color"] = Json::Value("blue"); break;
|
|
||||||
case 'a': a_Value["color"] = Json::Value("green"); break;
|
|
||||||
case 'b': a_Value["color"] = Json::Value("aqua"); break;
|
|
||||||
case 'c': a_Value["color"] = Json::Value("red"); break;
|
|
||||||
case 'd': a_Value["color"] = Json::Value("light_purple"); break;
|
|
||||||
case 'e': a_Value["color"] = Json::Value("yellow"); break;
|
|
||||||
case 'f': a_Value["color"] = Json::Value("white"); break;
|
|
||||||
} // switch (color)
|
|
||||||
} // case '@'
|
|
||||||
} // switch (Style[i])
|
} // switch (Style[i])
|
||||||
} // for i - a_PartStyle[]
|
} // for i - a_PartStyle[]
|
||||||
}
|
}
|
||||||
|
@ -21,12 +21,13 @@ Each part corresponds roughly to the behavior supported by the client messaging:
|
|||||||
- clickable commands (suggest)
|
- clickable commands (suggest)
|
||||||
Each part has a text assigned to it that can be styled. The style is specified using a string,
|
Each part has a text assigned to it that can be styled. The style is specified using a string,
|
||||||
each character / character combination in the string specifies the style to use:
|
each character / character combination in the string specifies the style to use:
|
||||||
- b = bold
|
- (char from 0 - 9 or a - f) = color X
|
||||||
- i = italic
|
- k = obfuscated
|
||||||
- u = underlined
|
- l = bold
|
||||||
- s = strikethrough
|
- m = strikethrough
|
||||||
- o = obfuscated
|
- n = underlined
|
||||||
- @X = color X (X is 0 - 9 or a - f, same as dye meta
|
- o = italic
|
||||||
|
- r = reset
|
||||||
If the protocol version doesn't support all the features, it degrades gracefully.
|
If the protocol version doesn't support all the features, it degrades gracefully.
|
||||||
*/
|
*/
|
||||||
class cCompositeChat
|
class cCompositeChat
|
||||||
@ -102,7 +103,7 @@ public:
|
|||||||
cCompositeChat(void);
|
cCompositeChat(void);
|
||||||
|
|
||||||
/** Creates a new chat message and parses the text into parts.
|
/** Creates a new chat message and parses the text into parts.
|
||||||
Recognizes "http:" and "https:" links and @color-codes.
|
Recognizes "http:" and "https:" links and &format-character.
|
||||||
Uses ParseText() for the actual parsing.
|
Uses ParseText() for the actual parsing.
|
||||||
Exported manually due to ToLua++ generating extra output parameter. */
|
Exported manually due to ToLua++ generating extra output parameter. */
|
||||||
cCompositeChat(const AString & a_ParseText, eMessageType a_MessageType = mtCustom);
|
cCompositeChat(const AString & a_ParseText, eMessageType a_MessageType = mtCustom);
|
||||||
@ -121,15 +122,15 @@ public:
|
|||||||
|
|
||||||
/** Adds a part that opens an URL when clicked.
|
/** Adds a part that opens an URL when clicked.
|
||||||
The default style is underlined light blue text. */
|
The default style is underlined light blue text. */
|
||||||
void AddUrlPart(const AString & a_Text, const AString & a_Url, const AString & a_Style = "u@c");
|
void AddUrlPart(const AString & a_Text, const AString & a_Url, const AString & a_Style = "nc");
|
||||||
|
|
||||||
/** Adds a part that runs a command when clicked.
|
/** Adds a part that runs a command when clicked.
|
||||||
The default style is underlined light green text. */
|
The default style is underlined light green text. */
|
||||||
void AddRunCommandPart(const AString & a_Text, const AString & a_Command, const AString & a_Style = "u@a");
|
void AddRunCommandPart(const AString & a_Text, const AString & a_Command, const AString & a_Style = "na");
|
||||||
|
|
||||||
/** Adds a part that suggests a command (enters it into the chat message area, but doesn't send) when clicked.
|
/** Adds a part that suggests a command (enters it into the chat message area, but doesn't send) when clicked.
|
||||||
The default style is underlined yellow text. */
|
The default style is underlined yellow text. */
|
||||||
void AddSuggestCommandPart(const AString & a_Text, const AString & a_SuggestedCommand, const AString & a_Style = "u@b");
|
void AddSuggestCommandPart(const AString & a_Text, const AString & a_SuggestedCommand, const AString & a_Style = "nb");
|
||||||
|
|
||||||
/** Adds a part that fully formats a specified achievement using client translatable strings
|
/** Adds a part that fully formats a specified achievement using client translatable strings
|
||||||
Takes achievement name and player awarded to. Displays as {player} has earned the achievement {achievement_name}.
|
Takes achievement name and player awarded to. Displays as {player} has earned the achievement {achievement_name}.
|
||||||
@ -137,7 +138,7 @@ public:
|
|||||||
void AddShowAchievementPart(const AString & a_PlayerName, const AString & a_Achievement, const AString & a_Style = "");
|
void AddShowAchievementPart(const AString & a_PlayerName, const AString & a_Achievement, const AString & a_Style = "");
|
||||||
|
|
||||||
/** Parses text into various parts, adds those.
|
/** Parses text into various parts, adds those.
|
||||||
Recognizes "http:" and "https:" URLs and @color-codes. */
|
Recognizes "http:" and "https:" URLs and &color-codes. */
|
||||||
void ParseText(const AString & a_ParseText);
|
void ParseText(const AString & a_ParseText);
|
||||||
|
|
||||||
/** Adds the "underline" style to each part that is an URL. */
|
/** Adds the "underline" style to each part that is an URL. */
|
||||||
@ -185,8 +186,4 @@ protected:
|
|||||||
/** Additional data pertaining to message type, for example, the name of a mtPrivateMsg sender */
|
/** Additional data pertaining to message type, for example, the name of a mtPrivateMsg sender */
|
||||||
AString m_AdditionalMessageTypeData;
|
AString m_AdditionalMessageTypeData;
|
||||||
|
|
||||||
|
|
||||||
/** Adds a_AddStyle to a_Style; overwrites the existing style if appropriate.
|
|
||||||
If the style already contains something that a_AddStyle overrides, it is erased first. */
|
|
||||||
void AddStyle(AString & a_Style, const AString & a_AddStyle);
|
|
||||||
} ; // tolua_export
|
} ; // tolua_export
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
static void TestParser1(void)
|
static void TestParser1(void)
|
||||||
{
|
{
|
||||||
cCompositeChat Msg;
|
cCompositeChat Msg;
|
||||||
Msg.ParseText("Testing @2color codes and http://links parser");
|
Msg.ParseText("Testing &2color codes and http://links parser");
|
||||||
const auto & Parts = Msg.GetParts();
|
const auto & Parts = Msg.GetParts();
|
||||||
TEST_EQUAL(Parts.size(), 4);
|
TEST_EQUAL(Parts.size(), 4);
|
||||||
|
|
||||||
@ -22,13 +22,13 @@ static void TestParser1(void)
|
|||||||
TEST_EQUAL(std::get<cCompositeChat::TextPart>(Parts[0]).Style, "");
|
TEST_EQUAL(std::get<cCompositeChat::TextPart>(Parts[0]).Style, "");
|
||||||
|
|
||||||
TEST_TRUE(std::holds_alternative<cCompositeChat::TextPart>(Parts[1]));
|
TEST_TRUE(std::holds_alternative<cCompositeChat::TextPart>(Parts[1]));
|
||||||
TEST_EQUAL(std::get<cCompositeChat::TextPart>(Parts[1]).Style, "@2");
|
TEST_EQUAL(std::get<cCompositeChat::TextPart>(Parts[1]).Style, "2");
|
||||||
|
|
||||||
TEST_TRUE(std::holds_alternative<cCompositeChat::UrlPart>(Parts[2]));
|
TEST_TRUE(std::holds_alternative<cCompositeChat::UrlPart>(Parts[2]));
|
||||||
TEST_EQUAL(std::get<cCompositeChat::UrlPart>(Parts[2]).Style, "@2");
|
TEST_EQUAL(std::get<cCompositeChat::UrlPart>(Parts[2]).Style, "2");
|
||||||
|
|
||||||
TEST_TRUE(std::holds_alternative<cCompositeChat::TextPart>(Parts[3]));
|
TEST_TRUE(std::holds_alternative<cCompositeChat::TextPart>(Parts[3]));
|
||||||
TEST_EQUAL(std::get<cCompositeChat::TextPart>(Parts[3]).Style, "@2");
|
TEST_EQUAL(std::get<cCompositeChat::TextPart>(Parts[3]).Style, "2");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -38,21 +38,21 @@ static void TestParser1(void)
|
|||||||
static void TestParser2(void)
|
static void TestParser2(void)
|
||||||
{
|
{
|
||||||
cCompositeChat Msg;
|
cCompositeChat Msg;
|
||||||
Msg.ParseText("@3Advanced stuff: @5overriding color codes and http://links.with/@4color-in-them handling");
|
Msg.ParseText("&3Advanced stuff: &5overriding color codes and http://links.with/&4color-in-them handling");
|
||||||
const auto & Parts = Msg.GetParts();
|
const auto & Parts = Msg.GetParts();
|
||||||
TEST_EQUAL(Parts.size(), 4);
|
TEST_EQUAL(Parts.size(), 4);
|
||||||
|
|
||||||
TEST_TRUE(std::holds_alternative<cCompositeChat::TextPart>(Parts[0]));
|
TEST_TRUE(std::holds_alternative<cCompositeChat::TextPart>(Parts[0]));
|
||||||
TEST_EQUAL(std::get<cCompositeChat::TextPart>(Parts[0]).Style, "@3");
|
TEST_EQUAL(std::get<cCompositeChat::TextPart>(Parts[0]).Style, "3");
|
||||||
|
|
||||||
TEST_TRUE(std::holds_alternative<cCompositeChat::TextPart>(Parts[1]));
|
TEST_TRUE(std::holds_alternative<cCompositeChat::TextPart>(Parts[1]));
|
||||||
TEST_EQUAL(std::get<cCompositeChat::TextPart>(Parts[1]).Style, "@5");
|
TEST_EQUAL(std::get<cCompositeChat::TextPart>(Parts[1]).Style, "35");
|
||||||
|
|
||||||
TEST_TRUE(std::holds_alternative<cCompositeChat::UrlPart>(Parts[2]));
|
TEST_TRUE(std::holds_alternative<cCompositeChat::UrlPart>(Parts[2]));
|
||||||
TEST_EQUAL(std::get<cCompositeChat::UrlPart>(Parts[2]).Style, "@5");
|
TEST_EQUAL(std::get<cCompositeChat::UrlPart>(Parts[2]).Style, "35");
|
||||||
|
|
||||||
TEST_TRUE(std::holds_alternative<cCompositeChat::TextPart>(Parts[3]));
|
TEST_TRUE(std::holds_alternative<cCompositeChat::TextPart>(Parts[3]));
|
||||||
TEST_EQUAL(std::get<cCompositeChat::TextPart>(Parts[3]).Style, "@5");
|
TEST_EQUAL(std::get<cCompositeChat::TextPart>(Parts[3]).Style, "35");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user