Be explicit on the possibility of failure

This commit is contained in:
iota97 2022-07-08 09:56:50 +02:00
parent 319fb59ac0
commit 992f1fb8ba
2 changed files with 4 additions and 4 deletions

View file

@ -63,7 +63,7 @@ bool ParseMacAddress(std::string str, uint8_t macAddr[6]) {
return true;
}
static bool ParseUnsigned32(const std::string &str, uint32_t *const output) {
static bool TryParseUnsigned32(const std::string &str, uint32_t *const output) {
char *endptr = NULL;
// Holy crap this is ugly.
@ -95,11 +95,11 @@ static bool ParseUnsigned32(const std::string &str, uint32_t *const output) {
bool TryParse(const std::string &str, uint32_t *const output) {
if (str[0] != '#') {
return ParseUnsigned32(str, output);
return TryParseUnsigned32(str, output);
} else {
// Parse it as "#RGBA" and convert to a ABGR interger
std::string s = ReplaceAll(str, "#", "0x");
if (ParseUnsigned32(s, output)) {
if (TryParseUnsigned32(s, output)) {
int a = (*output >> 24) & 0xff;
int b = (*output >> 16) & 0xff;
int g = (*output >> 8) & 0xff;

View file

@ -17,6 +17,6 @@ PopupStyleBg = \#303030FF
BackgroundColor = \#244D75FF
UIAtlas = ../ui_atlas
# Colors are either in the format \#RGB or 0xABGR (e.g. green is \#00FF00FF or 0xFF00FF00)
# Colors are either in the format \#RGBA or 0xABGR (e.g. green is \#00FF00FF or 0xFF00FF00)
# Atlas should be in the format path/to/filename where both filename.zim and filename.meta are
# Unprovided entry will use the default value