$darkmode
Elektra 0.11.0
|
Methods to do various tests on Keys. More...
Functions | |
int | keyCmp (const Key *k1, const Key *k2) |
Compare the name of two Keys. More... | |
int | keyIsBelow (const Key *key, const Key *check) |
Check if the Key check is below the Key key or not. More... | |
int | keyIsDirectlyBelow (const Key *key, const Key *check) |
Check whether the Key check is directly below the Key key . More... | |
int | keyIsBinary (const Key *key) |
Check if the value of a key is of binary type. More... | |
int | keyIsString (const Key *key) |
Check if the value of key is of string type. More... | |
Methods to do various tests on Keys.
With exception of the parameters of keyCmp(), the following contract holds for all parameters of type Key:
To use them:
int keyCmp | ( | const Key * | k1, |
const Key * | k2 | ||
) |
Compare the name of two Keys.
The comparison is based on a memcmp of the Key's names. If the names match, the Keys are found to be exactly the same and 0 is returned. These two keys can't be used in the same KeySet.
keyCmp() defines the sorting order for a KeySet.
The following 3 points are the rules for NULL values:
If the name is equal then:
Given any Keys k1 and k2 constructed with keyNew(), following equation hold true:
Here are some more examples:
Do not strcmp the keyName() yourself, because the result differs from simple ascii comparison.
k1
and k2
have been properly initialized via keyNew() or are NULL k1
and k2
cannot be used in the same KeySetk1 | the first Key to be compared |
k2 | the second Key to be compared |
<0 | if k1 < k2 |
0 | if k1 == k2 |
>0 | if k1 > k2 |
int keyIsBelow | ( | const Key * | key, |
const Key * | check | ||
) |
Check if the Key check
is below the Key key
or not.
Example:
key user:/sw/app check user:/sw/app/key
returns true because check
is below key
Example:
key user:/sw/app check user:/sw/app/folder/key
returns also true because check
is indirectly below key
Obviously, there is no Key above a namespace (e.g. user, system, /):
key * check user
key | the Key object to check against |
check | the Key object for which it should be checked whether it is below key |
1 | if check is below key |
0 | if it is not below or if it is the same key |
-1 | if key or check is null |
int keyIsBinary | ( | const Key * | key | ) |
Check if the value of a key
is of binary type.
The function checks if the value of key
is binary. Contrary to string values binary values can have '\0' inside the value and may not be terminated by a null character. Their disadvantage is that you need to pass their size.
Make sure to use this function and don't test the binary type another way to ensure compatibility and to write less error prone programs.
key | the Key to check |
1 | if the value of key is binary |
0 | if the value of key is not binary |
-1 | on NULL pointer |
int keyIsDirectlyBelow | ( | const Key * | key, |
const Key * | check | ||
) |
Check whether the Key check
is directly below the Key key
.
Example: key user:/sw/app check user:/sw/app/key
returns true because check is directly below key
Example: key user:/sw/app check user:/sw/app/folder/key
does not return true, because it is only indirectly below
key | the Key object to check against |
check | the Key object for which it should be checked whether it is directly below key |
1 | if check is directly below key |
0 | if check is not directly below key or if it is the same |
-1 | on null pointer |
int keyIsString | ( | const Key * | key | ) |
Check if the value of key
is of string type.
String values are null terminated and are not allowed to have any '\0' characters inside the string.
Make sure to use this function and don't test the string type another way to ensure compatibility and to write less error prone programs.
key | the Key to check |
1 | if the value of key is string |
0 | if the value of key is not string |
-1 | on NULL pointer |