From: Ran Benita Date: Fri, 31 Aug 2012 15:52:26 +0000 (+0300) Subject: atom: add xkb_atom_lookup X-Git-Tag: xkbcommon-0.2.0~201 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7aa31097bf1386238efdf200a9328580850590af;p=platform%2Fupstream%2Flibxkbcommon.git 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 --- diff --git a/src/atom.c b/src/atom.c index b5521ab..66cf2cf 100644 --- a/src/atom.c +++ b/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 diff --git a/src/atom.h b/src/atom.h index f55a6ec..f50d980 100644 --- a/src/atom.h +++ b/src/atom.h @@ -38,6 +38,9 @@ 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); diff --git a/src/context.c b/src/context.c index b16b803..6a0c35a 100644 --- a/src/context.c +++ b/src/context.c @@ -285,6 +285,12 @@ xkb_context_new(enum xkb_context_flags flags) } 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) { return atom_intern(ctx->atom_table, string, false); diff --git a/src/xkb-priv.h b/src/xkb-priv.h index 3e7fb16..e482ad1 100644 --- a/src/xkb-priv.h +++ b/src/xkb-priv.h @@ -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);