feat: add player Names Throughout the Game UI
This commit is contained in:
@@ -14,11 +14,16 @@ static bool valid_utf8_scalar(const unsigned char *text, size_t remaining, size_
|
||||
static bool sanitize_name(const char *name, char output[kDisplayNameBytes + 1]) {
|
||||
if (name == NULL) return false;
|
||||
size_t input = 0;
|
||||
while (name[input] == ' ') ++input;
|
||||
const size_t start = input;
|
||||
size_t end = start;
|
||||
while (name[end] != '\0') ++end;
|
||||
while (end > start && name[end - 1U] == ' ') --end;
|
||||
size_t written = 0;
|
||||
uint8_t scalars = 0;
|
||||
while (name[input] != '\0') {
|
||||
while (input < end) {
|
||||
size_t bytes = 0;
|
||||
if (!valid_utf8_scalar((const unsigned char *)&name[input], strlen(&name[input]), &bytes)) return false;
|
||||
if (!valid_utf8_scalar((const unsigned char *)&name[input], end - input, &bytes) || name[input] == '"' || name[input] == '\\') return false;
|
||||
if (written + bytes > kDisplayNameBytes || ++scalars > 20U) return false;
|
||||
memcpy(&output[written], &name[input], bytes);
|
||||
input += bytes;
|
||||
|
||||
Reference in New Issue
Block a user