From aaefbcddbbc2fb8c71e0a2ea40f76fce3c18c0aa Mon Sep 17 00:00:00 2001 From: P. J. McDermott Date: Fri, 24 Dec 2021 01:18:33 -0500 Subject: tk/text: strchr() allowed_chars for validation --- (limited to 'src/tk') diff --git a/src/tk/text.c b/src/tk/text.c index 644200b..9ba9faa 100644 --- a/src/tk/text.c +++ b/src/tk/text.c @@ -41,7 +41,6 @@ struct mftk_text { int ascent; SDL_Texture *texture; int editable; - int (*allowed)(void *, char); int (*action)(void *, const char *); int (*submit)(void *); void *user_data; @@ -150,9 +149,8 @@ _mftk_text_key_event(struct mftk_widget *w, SDL_Event *e) for (i = 0, j = 0; i < newlen && e->text.text[j] != '\0'; ++j) { - if (t->allowed != NULL && - t->allowed(t->user_data, - e->text.text[j]) <= 0) { + if (strchr(t->allowed_chars, e->text.text[j]) + == NULL) { continue; } t->val[t->cur + i] = e->text.text[j]; @@ -307,7 +305,7 @@ _mftk_text_destroy(struct mftk_widget *w) struct mftk_widget * mftk_text_new(const char *allowed_chars, int len, const char *val, - TTF_Font *font, int editable, int (*allowed)(void *, char), + TTF_Font *font, int editable, int (*action)(void *, const char *), int (*submit)(void *), void *user_data) { @@ -329,7 +327,6 @@ mftk_text_new(const char *allowed_chars, int len, const char *val, t->ascent = TTF_FontAscent (font); t->texture = NULL; t->editable = editable; - t->allowed = allowed; t->action = action; t->submit = submit; t->user_data = user_data; -- cgit v0.9.1