Directory Value: Simplify array checking code
@@ -168,20 +168,10 @@ CppKey convertToDirectChild (CppKey const & parent, CppKey const & child)
bool inline isArrayElementOf (CppKey const & parent, CppKey const & child)
{
char const * relative = elektraKeyGetRelativeName (*child, *parent);
- if (relative[0] != '#') return false;
- relative++; // Skip leading `#`
- size_t underscores = 0;
- while (relative[underscores] == '_')
- {
- underscores++;
- }
- relative = &relative[underscores]; // Skip underscores
- // Check index
- for (size_t digit = 0; digit <= underscores; digit++)
- {
- if (relative[digit] < '0' || relative[digit] > '9') return false;
- }
- relative = &relative[underscores + 1]; // Skip index
+ auto offsetIndex = elektraArrayValidateBaseNameString (relative);
+ if (offsetIndex <= 0) return false;
+ // Skip `#`, underscores and digits
+ relative += 2 * offsetIndex;
// The next character has to be the separation char (`/`) or end of string
if (relative[0] != '\0' && relative[0] != '/') return false;
