(irc) Support formatting with implicit end

This commit is contained in:
Jaidyn Ann 2021-08-13 13:00:32 -05:00
parent 29a94bcf65
commit 6258b2f2f3

View File

@ -641,13 +641,22 @@ IrcProtocol::_IsChannelName(BString name)
} }
#define disable_all_faces(current) { \
if (bold > -1) _ToggleAndAdd(msg, B_BOLD_FACE, &bold, current); \
if (italics > -1) _ToggleAndAdd(msg, B_ITALIC_FACE, &italics, current); \
if (strike > -1) _ToggleAndAdd(msg, B_STRIKEOUT_FACE, &strike, current); \
if (underline > -1) _ToggleAndAdd(msg, B_UNDERSCORE_FACE, &underline, current); \
};
void void
IrcProtocol::_AddFormatted(BMessage* msg, const char* name, BString text) IrcProtocol::_AddFormatted(BMessage* msg, const char* name, BString text)
{ {
BString newText; BString newText;
int32 italics = -1, bold = -1, underline = -1, strike = -1, mono = -1; int32 italics = -1, bold = -1, underline = -1, strike = -1, mono = -1;
for (int32 j=0, i=0; j < text.CountBytes(0, text.CountChars()); j++) { int32 length = text.CountBytes(0, text.CountChars());
for (int32 j=0, i=0; j < length; j++) {
char c = text.ByteAt(j); char c = text.ByteAt(j);
switch (c) { switch (c) {
@ -664,16 +673,14 @@ IrcProtocol::_AddFormatted(BMessage* msg, const char* name, BString text)
_ToggleAndAdd(msg, B_STRIKEOUT_FACE, &strike, i); _ToggleAndAdd(msg, B_STRIKEOUT_FACE, &strike, i);
break; break;
case 0x0f: case 0x0f:
if (bold > -1) _ToggleAndAdd(msg, B_BOLD_FACE, &bold, i); disable_all_faces(i);
if (italics > -1) _ToggleAndAdd(msg, B_ITALIC_FACE, &italics, i);
if (strike > -1) _ToggleAndAdd(msg, B_STRIKEOUT_FACE, &strike, i);
if (underline > -1) _ToggleAndAdd(msg, B_UNDERSCORE_FACE, &underline, i);
break; break;
default: default:
newText << c; newText << c;
i++; i++;
} }
} }
disable_all_faces(length);
msg->AddString(name, newText); msg->AddString(name, newText);
} }
@ -687,7 +694,7 @@ IrcProtocol::_ToggleAndAdd(BMessage* msg, uint16 face, int32* start,
else { else {
msg->AddInt32("face_start", *start); msg->AddInt32("face_start", *start);
msg->AddInt32("face_length", current - *start); msg->AddInt32("face_length", current - *start);
msg->AddInt16("face", face); msg->AddUInt16("face", face);
*start = -1; *start = -1;
} }
} }