$darkmode
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>
Include dependency graph for globbing.c:

Functions

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

Detailed Description

Library for performing globbing on keynames.

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
keythe Key to match against the globbing pattern
patternthe globbing pattern used
Return values
0if key is not NULL, pattern is not NULL and pattern matches key
ELEKTRA_GLOB_NOMATCHotherwise
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
resultthe KeySet to which the matching keys should be appended
inputthe KeySet whose keys should be filtered
patternthe 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