$darkmode
Elektra 0.11.0
Iterating Keyname Parts

Problem

While iterating over the parts of a keyname is easy for an experienced developer (just jump from \0 to \0 until you hit the name size), there is no good API that newcomers can use.

Constraints

No changes to the underlying APIs, while maintaining reasonable performance.

Assumptions

Considered Alternatives

  • Put the new function into libelektra-core.

Decision

Add this new function to a separate library (name TBD):

```c /**

  • Iterate over the key name parts of key.
  • Precondition
    currentPart, must be NULL or point anywhere into the unescaped name of key
  • This function defines the "next part" after currentPart as:
  • - the first part of key (after namespace), if currentPart == NULL
  • - NULL, if currentPart is the last part of key, i.e. currentPart == keyBaseName (key)
  • - the next part within key after the location currentPart points to
  • To iterate over the parts of a key you can use:
  • * Key * k;
    * for (const char * part = keyGetNextPart (k, NULL); part != NULL; part = keyGetNextPart (k, part))
    * {
    * // use part
    * }
    *
  • Returns
    the "next" (see above) key name part after currentPart. */ const char * keyGetNextPart (Key * key, const char * currentPart); ```

Rationale

The function is not required for a minimal API, but it is useful for people who don't know everything about the internals of Elektra.

Implications

Related Decisions

Notes