Array: Simplify `elektraArrayValidateName`
*/
int elektraArrayValidateName (const Key * key)
{
- if (!key)
- {
- return -1;
- }
-
- const char * current = keyBaseName (key);
-
- if (!current)
- {
- return -1;
- }
-
- if (!strcmp (current, "#"))
- {
- return 0;
- }
+ const char * current;
+ if (!key || !(current = keyBaseName (key)) || *current != '#') return -1;
+ if (!strcmp (current, "#")) return 0;
- if (*current == '#')
- {
current++;
int underscores = 0;
int digits = 0;
- for (; *current == '_'; current++)
+ while (*current == '_')
{
+ current++;
underscores++;
}
- for (; isdigit ((unsigned char)*current); current++)
+ while (isdigit ((unsigned char)*current))
{
+ current++;
digits++;
}
@@ -70,11 +57,6 @@ int elektraArrayValidateName (const Key * key)
{
return -1;
}
- }
- else
- {
- return -1;
- }
return 1;
}
