atom: add xkb_atom_lookup
authorRan Benita <ran234@gmail.com>
Fri, 31 Aug 2012 15:52:26 +0000 (18:52 +0300)
committerRan Benita <ran234@gmail.com>
Mon, 3 Sep 2012 07:31:13 +0000 (10:31 +0300)
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>
src/atom.c
src/atom.h
src/context.c
src/xkb-priv.h

index b5521ab..66cf2cf 100644 (file)
@@ -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
index f55a6ec..f50d980 100644 (file)
@@ -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);
 
index b16b803..6a0c35a 100644 (file)
@@ -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);
index 3e7fb16..e482ad1 100644 (file)
@@ -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);