atom: add xkb_atom_lookup
This will only lookup the string and return the atom if found; it will not intern it if not. This is useful when e.g. getting a string from the user (which may be arbitrary) and comparing against atoms. Signed-off-by: Ran Benita <ran234@gmail.com>master
parent
651e1dab04
commit
7aa31097bf
15
src/atom.c
15
src/atom.c
|
@ -185,6 +185,21 @@ find_node_pointer(struct atom_table *table, const char *string,
|
|||
return found;
|
||||
}
|
||||
|
||||
xkb_atom_t
|
||||
atom_lookup(struct atom_table *table, const char *string)
|
||||
{
|
||||
struct atom_node **np;
|
||||
unsigned int fp;
|
||||
|
||||
if (!string)
|
||||
return XKB_ATOM_NONE;
|
||||
|
||||
if (!find_node_pointer(table, string, &np, &fp))
|
||||
return XKB_ATOM_NONE;
|
||||
|
||||
return (*np)->atom;
|
||||
}
|
||||
|
||||
/*
|
||||
* If steal is true, we do not strdup @string; therefore it must be
|
||||
* dynamically allocated, not be free'd by the caller and not be used
|
||||
|
|
|
@ -37,6 +37,9 @@ atom_table_new(void);
|
|||
void
|
||||
atom_table_free(struct atom_table *table);
|
||||
|
||||
xkb_atom_t
|
||||
atom_lookup(struct atom_table *table, const char *string);
|
||||
|
||||
xkb_atom_t
|
||||
atom_intern(struct atom_table *table, const char *string,
|
||||
bool steal);
|
||||
|
|
|
@ -284,6 +284,12 @@ xkb_context_new(enum xkb_context_flags flags)
|
|||
return ctx;
|
||||
}
|
||||
|
||||
xkb_atom_t
|
||||
xkb_atom_lookup(struct xkb_context *ctx, const char *string)
|
||||
{
|
||||
return atom_lookup(ctx->atom_table, string);
|
||||
}
|
||||
|
||||
xkb_atom_t
|
||||
xkb_atom_intern(struct xkb_context *ctx, const char *string)
|
||||
{
|
||||
|
|
|
@ -422,6 +422,13 @@ XkbKeycodeInRange(struct xkb_keymap *keymap, xkb_keycode_t kc)
|
|||
struct xkb_keymap *
|
||||
xkb_map_new(struct xkb_context *ctx);
|
||||
|
||||
/*
|
||||
* Returns XKB_ATOM_NONE if @string was not previously interned,
|
||||
* otherwise returns the atom.
|
||||
*/
|
||||
xkb_atom_t
|
||||
xkb_atom_lookup(struct xkb_context *ctx, const char *string);
|
||||
|
||||
xkb_atom_t
|
||||
xkb_atom_intern(struct xkb_context *ctx, const char *string);
|
||||
|
||||
|
|
Loading…
Reference in New Issue