glib-aux: make code in nm_uuid_is_valid_nm() clearer
Setting `NM_SET_OUT(out_normalized, !is_normalized)` is correct, but looks odd and required a long code comment. Try to write the same code differently, I think it is easier to read and requires less comment to explain.
This commit is contained in:
@@ -202,28 +202,25 @@ nm_uuid_is_valid_nm(const char *str,
|
|||||||
|
|
||||||
/* @out_normalized_str is only set, if normalization was necessary
|
/* @out_normalized_str is only set, if normalization was necessary
|
||||||
* and possible. The caller cannot request @out_normalized_str, without
|
* and possible. The caller cannot request @out_normalized_str, without
|
||||||
* also getting @out_normalized. */
|
* also requesting @out_normalized. Otherwise, they couldn't know whether
|
||||||
|
* a normalized string was returned. */
|
||||||
nm_assert(!out_normalized_str || out_normalized);
|
nm_assert(!out_normalized_str || out_normalized);
|
||||||
|
|
||||||
if (!str)
|
if (!str)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
if (nm_uuid_parse_full(str, &uuid, &is_normalized)) {
|
if (nm_uuid_parse_full(str, &uuid, &is_normalized)) {
|
||||||
/* Note that:
|
if (is_normalized) {
|
||||||
* @is_normalized means that "str" contains a normalized UUID
|
/* @str is already normalized. No need to normalize again, so
|
||||||
* @out_normalized: indicates whether str requires normalization
|
* @out_normalized is FALSE. */
|
||||||
* and whether @out_normalized_str was set to contain the normalized
|
NM_SET_OUT(out_normalized, FALSE);
|
||||||
* UUID.
|
} else {
|
||||||
* With this, we get the slightly odd assignment: */
|
NM_SET_OUT(out_normalized, TRUE);
|
||||||
NM_SET_OUT(out_normalized, !is_normalized);
|
if (out_normalized_str) {
|
||||||
|
|
||||||
if (!is_normalized && out_normalized_str) {
|
|
||||||
/* we need to normalize the UUID */
|
/* we need to normalize the UUID */
|
||||||
nm_uuid_unparse(&uuid, out_normalized_str);
|
nm_uuid_unparse(&uuid, out_normalized_str);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
/* regardless whether normalization was necessary, the UUID is
|
|
||||||
* essentially valid. */
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user