about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2018-09-14 15:31:16 -0400
committerJune McEnroe <june@causal.agency>2018-09-14 15:31:16 -0400
commitb22e008d68e36719f3c6a808f8d8adc905da7250 (patch)
treef36ee332b83c3463a45a34affbeec5cae0420857
parentAdd tests for formatParse (diff)
downloadcatgirl-b22e008d68e36719f3c6a808f8d8adc905da7250.tar.gz
catgirl-b22e008d68e36719f3c6a808f8d8adc905da7250.zip
Apply consecutive formatting codes at once
Fixes the failing splits test.
-rw-r--r--format.c19
1 files changed, 12 insertions, 7 deletions
diff --git a/format.c b/format.c
index 8120165..a2aaf4b 100644
--- a/format.c
+++ b/format.c
@@ -97,13 +97,16 @@ bool formatParse(struct Format *format, const wchar_t *split) {
 	}
 
 	const wchar_t *init = format->str;
-	switch (format->str[0]) {
-		break; case IRCBold:      format->str++; format->bold ^= true;
-		break; case IRCItalic:    format->str++; format->italic ^= true;
-		break; case IRCUnderline: format->str++; format->underline ^= true;
-		break; case IRCReverse:   format->str++; format->reverse ^= true;
-		break; case IRCColor:     format->str++; parseColor(format);
-		break; case IRCReset:     format->str++; formatReset(format);
+	for (bool done = false; !done;) {
+		switch (format->str[0]) {
+			break; case IRCBold:      format->str++; format->bold ^= true;
+			break; case IRCItalic:    format->str++; format->italic ^= true;
+			break; case IRCUnderline: format->str++; format->underline ^= true;
+			break; case IRCReverse:   format->str++; format->reverse ^= true;
+			break; case IRCColor:     format->str++; parseColor(format);
+			break; case IRCReset:     format->str++; formatReset(format);
+			break; default:           done = true;
+		}
 	}
 	format->split = (split >= init && split <= format->str);
 
@@ -170,8 +173,10 @@ int main() {
 	assert(testColor(L"\00399,99a", IRCDefault, IRCDefault, 6));
 
 	assert(testSplits(L"ab"));
+	assert(testSplits(L"\002"));
 	assert(testSplits(L"\002ab"));
 	assert(testSplits(L"a\002b"));
+	assert(testSplits(L"\002\003"));
 	assert(testSplits(L"a\002\003b"));
 	assert(testSplits(L"a\0031b"));
 	assert(testSplits(L"a\00312b"));