From 331b8d44fe96f3a5e5d8a177e0eebda9838ac8d5 Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Wed, 24 May 2017 17:59:03 -0400 Subject: [PATCH] field-path.c: add internal function to stringify a field path MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This is to be used by logging statements. Signed-off-by: Philippe Proulx Signed-off-by: Jérémie Galarneau --- .../babeltrace/ctf-ir/field-path-internal.h | 3 +++ lib/ctf-ir/field-path.c | 27 +++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/include/babeltrace/ctf-ir/field-path-internal.h b/include/babeltrace/ctf-ir/field-path-internal.h index de08a87e9..b270094ba 100644 --- a/include/babeltrace/ctf-ir/field-path-internal.h +++ b/include/babeltrace/ctf-ir/field-path-internal.h @@ -54,4 +54,7 @@ BT_HIDDEN struct bt_ctf_field_path *bt_ctf_field_path_copy( struct bt_ctf_field_path *path); +BT_HIDDEN +GString *bt_ctf_field_path_string(struct bt_ctf_field_path *path); + #endif /* BABELTRACE_CTF_IR_FIELD_PATH_INTERNAL */ diff --git a/lib/ctf-ir/field-path.c b/lib/ctf-ir/field-path.c index 9b991dedc..ac42ef5cc 100644 --- a/lib/ctf-ir/field-path.c +++ b/lib/ctf-ir/field-path.c @@ -29,6 +29,7 @@ #include #include +#include #include #include #include @@ -169,3 +170,29 @@ int bt_ctf_field_path_get_index(const struct bt_ctf_field_path *field_path, end: return ret; } + +BT_HIDDEN +GString *bt_ctf_field_path_string(struct bt_ctf_field_path *path) +{ + GString *str = g_string_new(NULL); + size_t i; + + assert(path); + + if (!str) { + goto end; + } + + g_string_append_printf(str, "[%s", bt_ctf_scope_string(path->root)); + + for (i = 0; i < path->indexes->len; i++) { + int index = g_array_index(path->indexes, int, i); + + g_string_append_printf(str, ", %d", index); + } + + g_string_append(str, "]"); + +end: + return str; +} -- 2.34.1