Skip to content

Commit 8b7e358

Browse files
committed
feat: Add sentry_value_get_key()
1 parent 03143a8 commit 8b7e358

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

include/sentry.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,12 @@ SENTRY_API sentry_value_t sentry_value_get_by_key_owned(
290290
SENTRY_API sentry_value_t sentry_value_get_by_key_owned_n(
291291
sentry_value_t value, const char *k, size_t k_len);
292292

293+
/**
294+
* Returns a key in a map by index. If missing or value is not a map,
295+
* an empty string is returned.
296+
*/
297+
SENTRY_API const char *sentry_value_get_key(sentry_value_t value, size_t index);
298+
293299
/**
294300
* Looks up a value in a list by index. If missing a null value is returned.
295301
* The returned value is borrowed.

src/sentry_value.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -778,6 +778,18 @@ sentry_value_get_by_key_owned(sentry_value_t value, const char *k)
778778
return rv;
779779
}
780780

781+
const char *
782+
sentry_value_get_key(sentry_value_t value, size_t index) {
783+
const thing_t *thing = value_as_thing(value);
784+
if (thing && thing_get_type(thing) == THING_TYPE_OBJECT) {
785+
obj_t *o = thing->payload._ptr;
786+
if (index < o->len) {
787+
return o->pairs[index].k;
788+
}
789+
}
790+
return "";
791+
}
792+
781793
sentry_value_t
782794
sentry_value_get_by_index(sentry_value_t value, size_t index)
783795
{

0 commit comments

Comments
 (0)