diff options
author | Ben Pfaff <blp@nicira.com> | 2011-06-06 09:02:01 -0700 |
---|---|---|
committer | Ben Pfaff <blp@nicira.com> | 2011-06-06 09:02:01 -0700 |
commit | 25d4983554f6cf8ce5e169f7c5bb5a08c981d27e (patch) | |
tree | ff6fc1082d1ea60a022c0b564d7d4666c14f44b6 /ovsdb/column.c | |
parent | 44b4d050d4a2c966ed6f4aef2e523f70b6463648 (diff) | |
download | openvswitch-25d4983554f6cf8ce5e169f7c5bb5a08c981d27e.tar.gz |
ovsdb: Add functions for formatting column sets and data in columns sets.
These will be used for formatting error messages in an upcoming commit.
Diffstat (limited to 'ovsdb/column.c')
-rw-r--r-- | ovsdb/column.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/ovsdb/column.c b/ovsdb/column.c index be346e4d6..576e46387 100644 --- a/ovsdb/column.c +++ b/ovsdb/column.c @@ -20,6 +20,7 @@ #include <stdlib.h> #include "column.h" +#include "dynamic-string.h" #include "json.h" #include "ovsdb-error.h" #include "ovsdb-parser.h" @@ -203,6 +204,27 @@ ovsdb_column_set_to_json(const struct ovsdb_column_set *set) return json; } +/* Returns an English string listing the contents of 'set', e.g. "columns + * \"a\", \"b\", and \"c\"". The caller must free the string. */ +char * +ovsdb_column_set_to_string(const struct ovsdb_column_set *set) +{ + if (!set->n_columns) { + return xstrdup("no columns"); + } else { + struct ds s; + size_t i; + + ds_init(&s); + ds_put_format(&s, "column%s ", set->n_columns > 1 ? "s" : ""); + for (i = 0; i < set->n_columns; i++) { + const char *delimiter = english_list_delimiter(i, set->n_columns); + ds_put_format(&s, "%s\"%s\"", delimiter, set->columns[i]->name); + } + return ds_steal_cstr(&s); + } +} + void ovsdb_column_set_add(struct ovsdb_column_set *set, const struct ovsdb_column *column) |