| Elektra 0.11.0

Functions
globbing.c File Reference

Library for performing globbing on keynames. More...

`#include <kdb.h>`
`#include <kdbease.h>`
`#include <kdbglobbing.h>`
`#include <kdbhelper.h>`
`#include <ctype.h>`
`#include <fnmatch.h>`
`#include <stdlib.h>`
`#include <string.h>`

## Functions
int | elektraKeyGlob (const Key *key, const char *pattern)
| checks whether a given Key matches a given globbing pattern
int | elektraKsGlob (KeySet *result, KeySet *input, const char *pattern)
| filters a given KeySet by applying a globbing pattern

## Detailed Description

Library for performing globbing on keynames.

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

## Function Documentation

## ◆ elektraKeyGlob()

int elektraKeyGlob | ( | const Key * | key,
|  | const char * | pattern
| ) |  |

checks whether a given Key matches a given globbing pattern

WARNING: this method will not work correctly, if key parts contain embedded (escaped) slashes.

The globbing patterns for this function are a superset of those from glob(7) used with the FNM_PATHNAME flag:

- '*' matches any series of characters other than '/'
- '?' matches any single character except '/'
- '#', when used as "/#/" (or "/#" at the end of `pattern`), matches a valid array item
- '_', when used as "/_/"(or "/_" at the end of `pattern`), matches a key part that is not a valid array item
- everything between '[' and ']' is treated as a character class, matching exactly one of the given characters (see glob(7) for details)
- if the pattern ends with "/__", matching key names may contain arbitrary suffixes

Note
  '*' cannot match an empty key name part. This also means patterns like "something&#47;*" will not match the key "something". This is because each slash ('/') in the pattern has to correspond to a slash in the canonical key name, which neither end in a slash nor contain multiple slashes in sequence.
  use "[_]", "[#]", "[*]", "[?]" and "[[]" to match the literal characters '_', '#', '*', '?' and '['. Using backslash ('\') for escaping is not supported.

Parameters

  key | the Key to match against the globbing pattern
  pattern | the globbing pattern used

Return values

  0 | if `key` is not NULL, `pattern` is not NULL and `pattern` matches `key`
  ELEKTRA_GLOB_NOMATCH | otherwise

See also
  isArrayName(), for info on valid array items

## ◆ elektraKsGlob()

int elektraKsGlob | ( | KeySet * | result,
|  | KeySet * | input,
|  | const char * | pattern
| ) |  |

filters a given KeySet by applying a globbing pattern

Parameters

  result | the KeySet to which the matching keys should be appended
  input | the KeySet whose keys should be filtered
  pattern | the globbing pattern used

Returns
  the number of Keys appended to result or -1, if `result`, `input` or `pattern` are NULL

See also
  elektraKeyGlob(), for explanation of globbing pattern