UPSCLI_STR_ADD_UNIQU(3) | NUT Manual | UPSCLI_STR_ADD_UNIQU(3) |
NAME
upscli_str_add_unique_token - Add a unique token into a string buffer, with optional callbacks as needed by implementation
SYNOPSIS
#include <upsclient.h> int upscli_str_add_unique_token(char *tgt, size_t tgtsize, const char *token, int (*callback_always)(char *, size_t, const char *), int (*callback_unique)(char *, size_t, const char *) );
DESCRIPTION
The upscli_str_add_unique_token() function takes the pointer tgt to a caller-provided char * buffer of size tgtsize, and the pointer token to a contiguous token that should be added to the end of tgt buffer, if it is not there yet.
The token contents are stripped of surrounding space characters, and the method recurses to independently process each space-separated token inside (if there are any spaces left).
The resulting tgt buffer would eventually collect a string comprised of unique token values in order of first mention, separated by single space characters (ASCII 0x20).
Optionally calls callback_always (if not NULL) after checking the input for spaces (and maybe recursing) and before checking if the token is already there, and/or callback_unique (if not NULL) after checking for uniqueness and just before going to add a newly seen token.
It is up to the caller to dynamically or statically allocate the tgt buffer and free() it if needed. As far as this method is concerned, the buffer may be recycled (in data processing loops) by setting the initial character to '\0', making it an empty string again.
RETURN VALUE
The upscli_str_add_unique_token() function returns a numeric code:
SEE ALSO
05/29/2025 | Network UPS Tools 2.8.3 |