summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRan Benita <ran234@gmail.com>2012-08-31 18:52:26 +0300
committerRan Benita <ran234@gmail.com>2012-09-03 10:31:13 +0300
commit7aa31097bf1386238efdf200a9328580850590af (patch)
tree359f9d7501ac81268c075b6023506b453f3ac544 /src
parent651e1dab04cc4ecb67b9e7c83d634fd34c0723b6 (diff)
downloadlibxkbcommon-7aa31097bf1386238efdf200a9328580850590af.tar.gz
libxkbcommon-7aa31097bf1386238efdf200a9328580850590af.tar.bz2
libxkbcommon-7aa31097bf1386238efdf200a9328580850590af.zip
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>
Diffstat (limited to 'src')
-rw-r--r--src/atom.c15
-rw-r--r--src/atom.h3
-rw-r--r--src/context.c6
-rw-r--r--src/xkb-priv.h7
4 files changed, 31 insertions, 0 deletions
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);