mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 18:22:07 +00:00
Further simplify formatting code
- Remove redundant length checks before `memcpy` - Coerce `sign` and `prefix` to boolean for `numLen`
This commit is contained in:
@@ -166,7 +166,6 @@ void fmt_PrintString(char *buf, size_t bufLen, struct FormatSpec const *fmt, cha
|
|||||||
} else {
|
} else {
|
||||||
for (size_t i = 0; i < padLen; i++)
|
for (size_t i = 0; i < padLen; i++)
|
||||||
buf[i] = ' ';
|
buf[i] = ' ';
|
||||||
if (totalLen > padLen)
|
|
||||||
memcpy(buf + padLen, value, len);
|
memcpy(buf + padLen, value, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -256,13 +255,7 @@ void fmt_PrintNumber(char *buf, size_t bufLen, struct FormatSpec const *fmt, uin
|
|||||||
}
|
}
|
||||||
|
|
||||||
size_t len = strlen(valueBuf);
|
size_t len = strlen(valueBuf);
|
||||||
size_t numLen = len;
|
size_t numLen = !!sign + !!prefix + len;
|
||||||
|
|
||||||
if (sign)
|
|
||||||
numLen++;
|
|
||||||
if (prefix)
|
|
||||||
numLen++;
|
|
||||||
|
|
||||||
size_t totalLen = fmt->width > numLen ? fmt->width : numLen;
|
size_t totalLen = fmt->width > numLen ? fmt->width : numLen;
|
||||||
|
|
||||||
if (totalLen > bufLen - 1) { /* bufLen includes terminator */
|
if (totalLen > bufLen - 1) { /* bufLen includes terminator */
|
||||||
@@ -304,7 +297,6 @@ void fmt_PrintNumber(char *buf, size_t bufLen, struct FormatSpec const *fmt, uin
|
|||||||
if (prefix)
|
if (prefix)
|
||||||
buf[pos++] = prefix;
|
buf[pos++] = prefix;
|
||||||
}
|
}
|
||||||
if (totalLen > pos)
|
|
||||||
memcpy(buf + pos, valueBuf, len);
|
memcpy(buf + pos, valueBuf, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user