| Elektra 0.11.0

Functions
array.c File Reference

Array methods. More...

`#include <kdb.h>`
`#include <kdbease.h>`
`#include <kdbhelper.h>`
`#include <kdbprivate.h>`
`#include <kdbtypes.h>`
`#include <ctype.h>`
`#include <errno.h>`
`#include <limits.h>`
`#include <stdio.h>`
`#include <stdlib.h>`
`#include <string.h>`

## Functions
int | elektraArrayValidateName (const Key *key)
| validate array syntax
int | elektraArrayValidateBaseNameString (const char *baseName)
| validate array syntax
char * | elektraArrayGetPrefix (Key *key)
| Get the base name of the passed array.
int | elektraArrayIncName (Key *key)
| Increment the name of the key by one.
int | elektraArrayDecName (Key *key)
| Decrement the name of an array key by one.
KeySet * | elektraArrayGet (const Key *arrayParent, KeySet *keys)
| Return all the array keys below the given array parent.
Key * | elektraArrayGetNextKey (KeySet *arrayKeys)
| Return the next key in the given array.

## Detailed Description

Array methods.

Copyright
  BSD License (see LICENSE.md or https://www.libelektra.org)

## Function Documentation

## ◆ elektraArrayDecName()

int elektraArrayDecName | ( | Key * | key | ) |

Decrement the name of an array key by one.

The alphabetical order will remain intact. For example, `user:/abc/\#_10` will be changed to `user:/abc/\#9`.

Parameters

  This | parameter determines the key name this function decrements.

Return values

  -1 | on error (e.g. new array index too small, non-valid array)
  0 | on success

## ◆ elektraArrayGet()

KeySet * elektraArrayGet | ( | const Key * | arrayParent,
|  | KeySet * | keys
| ) |  |

Return all the array keys below the given array parent.

The array parent itself is not returned. For example, if `user:/config/#` is an array, `user:/config` is the array parent. Only the direct array keys will be returned. This means that for example `user:/config/#1/key` will not be included, but only `user:/config/#1`.

A new keyset will be allocated for the resulting keys. This means that the caller must `ksDel` the resulting keyset.

Parameters

  arrayParent | the parent of the array to be returned
  keys | the keyset containing the array keys

Returns
  a keyset containing the array keys (if any)

Return values

  NULL | on `NULL` pointers

## ◆ elektraArrayGetNextKey()

Key * elektraArrayGetNextKey | ( | KeySet * | arrayKeys | ) |

Return the next key in the given array.

The function will automatically allocate memory for a new key and name it accordingly.

Precondition
  The supplied keyset must contain only valid array keys.

The caller has to keyDel the resulting key.

Parameters

  arrayKeys | the array where the new key will belong to

Returns
  the new array key on success

Return values

  NULL | if the passed array is empty
  NULL | on NULL pointers or if an error occurs

## ◆ elektraArrayGetPrefix()

char * elektraArrayGetPrefix | ( | Key * | key | ) |

Get the base name of the passed array.

The returned value must be freed (if not null)

e.g. user:/abc/#9/foo#1 wil return user:/abc

Parameters

  key |

Return values

p NULL if key is not array

Return values

  new | allocated memory (free with elektraFree)

## ◆ elektraArrayIncName()

int elektraArrayIncName | ( | Key * | key | ) |

Increment the name of the key by one.

Alphabetical order will remain

e.g. user:/abc/#9 will be changed to user:/abc/#_10

For the start: user:/abc/# will be changed to user:/abc/#0

Parameters

  key | which base name will be incremented

Return values

  -1 | on error (e.g. array too large, non-valid array)
  0 | on success

## ◆ elektraArrayValidateBaseNameString()

int elektraArrayValidateBaseNameString | ( | const char * | baseName | ) |

validate array syntax

Parameters

  baseName | the supposed array element basename

Return values

  -1 | if no array element/syntax error/no key
  0 | if start
  offsetIndex | otherwise, where `offsetIndex` stores the offset to the first digit of the array index of `baseName`

## ◆ elektraArrayValidateName()

int elektraArrayValidateName | ( | const Key * | key | ) |

validate array syntax

Parameters

  key | an element of an array

Return values

  -1 | if no array element/syntax error/no key
  0 | if start
  1 | if array element