mirror of
git://git.psyc.eu/libpsyc
synced 2024-08-15 03:19:02 +00:00
psyc_text params
This commit is contained in:
parent
aad05d8483
commit
5fc5c5079a
4 changed files with 11 additions and 11 deletions
|
@ -62,8 +62,8 @@ typedef struct {
|
|||
* PSYC_TEXT_VALUE_NOT_FOUND if no match found in which case psyc_text
|
||||
* leaves the original template text as is.
|
||||
*/
|
||||
typedef PsycTextValueRC (*PsycTextCB) (const char *name, size_t len,
|
||||
PsycString *value, void *extra);
|
||||
typedef PsycTextValueRC (*PsycTextCB) (void *cls, const char *name, size_t namelen,
|
||||
PsycString *value);
|
||||
|
||||
/**
|
||||
* Initializes the PSYC text state struct.
|
||||
|
@ -156,7 +156,7 @@ psyc_text_bytes_written (PsycTextState *state)
|
|||
* @see http://about.psyc.eu/psyctext
|
||||
**/
|
||||
PsycTextRC
|
||||
psyc_text (PsycTextState *state, PsycTextCB getValue, void *extra);
|
||||
psyc_text (PsycTextState *state, PsycTextCB get_value, void *get_value_cls);
|
||||
|
||||
extern const PsycTemplates psyc_templates;
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ const PsycTemplates psyc_templates = { .s = {
|
|||
}};
|
||||
|
||||
PsycTextRC
|
||||
psyc_text (PsycTextState *state, PsycTextCB get_value, void *extra)
|
||||
psyc_text (PsycTextState *state, PsycTextCB get_value, void *get_value_cls)
|
||||
{
|
||||
const char *start = state->tmpl.data, *end; // start & end of variable name
|
||||
const char *prev = state->tmpl.data + state->cursor;
|
||||
|
@ -38,8 +38,8 @@ psyc_text (PsycTextState *state, PsycTextCB get_value, void *extra)
|
|||
continue; // [] is invalid, name can't be empty
|
||||
}
|
||||
|
||||
ret = get_value(start + state->open.length,
|
||||
end - start - state->open.length, &value, extra);
|
||||
ret = get_value(get_value_cls, start + state->open.length,
|
||||
end - start - state->open.length, &value);
|
||||
|
||||
if (ret < 0)
|
||||
continue; // value not found, no substitution
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
uint8_t verbose;
|
||||
|
||||
PsycTextValueRC
|
||||
getValueFooBar (const char *name, size_t len, PsycString *value, void *extra)
|
||||
getValueFooBar (void *cls, const char *name, size_t len, PsycString *value)
|
||||
{
|
||||
if (verbose)
|
||||
printf("> getValue: %.*s\n", (int)len, name);
|
||||
|
@ -18,7 +18,7 @@ getValueFooBar (const char *name, size_t len, PsycString *value, void *extra)
|
|||
}
|
||||
|
||||
PsycTextValueRC
|
||||
getValueEmpty (const char *name, size_t len, PsycString *value, void *extra)
|
||||
getValueEmpty (void *cls, const char *name, size_t len, PsycString *value)
|
||||
{
|
||||
if (verbose)
|
||||
printf("> getValue: %.*s\n", (int)len, name);
|
||||
|
@ -28,7 +28,7 @@ getValueEmpty (const char *name, size_t len, PsycString *value, void *extra)
|
|||
}
|
||||
|
||||
PsycTextValueRC
|
||||
getValueNotFound (const char *name, size_t len, PsycString *value, void *extra)
|
||||
getValueNotFound (void *cls, const char *name, size_t len, PsycString *value)
|
||||
{
|
||||
if (verbose)
|
||||
printf("> getValue: %.*s\n", (int)len, name);
|
||||
|
|
Loading…
Reference in a new issue