Browse Source

Remove word handling from formatParse

June 2 months ago
parent
commit
6aa42b852b
Signed by: Curtis McEnroe <june@causal.agency> GPG Key ID: CEA2F97ADCFCD77C
2 changed files with 10 additions and 11 deletions
  1. 4
    9
      format.c
  2. 6
    2
      ui.c

+ 4
- 9
format.c View File

@@ -79,10 +79,8 @@ static void parseColor(struct Format *format) {
79 79
 	format->str = &format->str[1 + len];
80 80
 }
81 81
 
82
-static const wchar_t Stops[] = {
83
-	L' ',
84
-	IRCBold, IRCColor, IRCReverse, IRCReset, IRCItalic, IRCUnderline,
85
-	L'\0',
82
+static const wchar_t Codes[] = {
83
+	IRCBold, IRCColor, IRCReverse, IRCReset, IRCItalic, IRCUnderline, L'\0',
86 84
 };
87 85
 
88 86
 bool formatParse(struct Format *format, const wchar_t *split) {
@@ -110,11 +108,7 @@ bool formatParse(struct Format *format, const wchar_t *split) {
110 108
 	}
111 109
 	format->split = (split >= init && split <= format->str);
112 110
 
113
-	if (format->str[0] == L' ') {
114
-		format->len = 1 + wcscspn(&format->str[1], Stops);
115
-	} else {
116
-		format->len = wcscspn(format->str, Stops);
117
-	}
111
+	format->len = wcscspn(format->str, Codes);
118 112
 	if (split > format->str && split < &format->str[format->len]) {
119 113
 		format->len = split - format->str;
120 114
 	}
@@ -172,6 +166,7 @@ int main() {
172 166
 	assert(testColor(L"\00316,16a", IRCDefault, IRCDefault, 6));
173 167
 	assert(testColor(L"\00399,99a", IRCDefault, IRCDefault, 6));
174 168
 
169
+	assert(testSplits(L""));
175 170
 	assert(testSplits(L"ab"));
176 171
 	assert(testSplits(L"\002"));
177 172
 	assert(testSplits(L"\002ab"));

+ 6
- 2
ui.c View File

@@ -194,11 +194,14 @@ static void addFormat(WINDOW *win, const struct Format *format) {
194 194
 }
195 195
 
196 196
 static int addWrap(WINDOW *win, const wchar_t *str) {
197
+	int lines = 0;
198
+
197 199
 	struct Format format = { .str = str };
198 200
 	formatReset(&format);
199
-
200
-	int lines = 0;
201 201
 	while (formatParse(&format, NULL)) {
202
+		size_t word = 1 + wcscspn(&format.str[1], L" ");
203
+		if (word < format.len) format.len = word;
204
+
202 205
 		int _, x, xMax;
203 206
 		getyx(win, _, x);
204 207
 		getmaxyx(win, _, xMax);
@@ -210,6 +213,7 @@ static int addWrap(WINDOW *win, const wchar_t *str) {
210 213
 			waddch(win, '\n');
211 214
 			lines++;
212 215
 		}
216
+
213 217
 		addFormat(win, &format);
214 218
 	}
215 219
 	return lines;

Loading…
Cancel
Save