Skip to content

Commit 277dc5d

Browse files
committed
Newsroom: convert pilot names to title case
1 parent 809019c commit 277dc5d

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/game/scenes/newsroom.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,29 @@ void newsroom_fixup_str(newsroom_local *local) {
107107
local->news_str = tmp;
108108
}
109109

110+
static void title_case(str *str) {
111+
bool start = true;
112+
113+
unsigned char c;
114+
// XXX this is not Unicode-aware
115+
for(size_t pos = 0; (c = (unsigned char)str_at(str, pos)); pos++) {
116+
if(c == ' ') {
117+
start = true;
118+
} else {
119+
c = (unsigned char)(start ? toupper(c) : tolower(c));
120+
str_set_at(str, pos, (char)c);
121+
start = false;
122+
}
123+
}
124+
}
125+
110126
void newsroom_set_names(newsroom_local *local, const char *pilot1, const char *pilot2, int har1, int har2, int sex1,
111127
int sex2) {
112128

113-
// XXX TODO: Magnus: put pilot names in title case
114129
str_from_c(&local->pilot1, pilot1);
130+
title_case(&local->pilot1);
115131
str_from_c(&local->pilot2, pilot2);
132+
title_case(&local->pilot2);
116133
local->har1 = har1;
117134
local->har2 = har2;
118135
local->sex1 = sex1;

0 commit comments

Comments
 (0)