diff options
author | Susan LoVerso <sue@wiredtiger.com> | 2014-05-22 12:05:55 -0400 |
---|---|---|
committer | Susan LoVerso <sue@wiredtiger.com> | 2014-05-22 12:05:55 -0400 |
commit | d898f2c92ee73873eb18fe17790a83b497e8cf31 (patch) | |
tree | 7a0f31b46cf22254687682601e5c0f368fb09444 /src/cursor/cur_json.c | |
parent | 4ff00925ce37a974e8063d61538a2fafa91b9fe6 (diff) | |
download | mongo-d898f2c92ee73873eb18fe17790a83b497e8cf31.tar.gz |
Consolidate the column init functions.
Diffstat (limited to 'src/cursor/cur_json.c')
-rw-r--r-- | src/cursor/cur_json.c | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/src/cursor/cur_json.c b/src/cursor/cur_json.c index a8048e431f6..299f45c6472 100644 --- a/src/cursor/cur_json.c +++ b/src/cursor/cur_json.c @@ -320,3 +320,51 @@ __wt_json_unpack_char(char ch, char *buf, size_t bufsz, int force_unicode) } return (6); } + +/* + * __wt_json_column_init -- + * set json_key_names, json_value_names to comma separated lists + * of column names. + */ +int +__wt_json_column_init(WT_CURSOR *cursor, const char *keyformat, + const WT_CONFIG_ITEM *idxconf, const WT_CONFIG_ITEM *colconf) +{ + WT_CURSOR_JSON *json; + const char *p, *end, *beginkey; + uint32_t keycnt, nkeys; + + json = (WT_CURSOR_JSON *)cursor->json_private; + beginkey = colconf->str; + end = beginkey + colconf->len; + + if (idxconf != NULL) { + json->key_names.str = idxconf->str; + json->key_names.len = idxconf->len; + } else if (colconf->len > 0 && *beginkey == '(') { + beginkey++; + if (end[-1] == ')') + end--; + } + + for (nkeys = 0; *keyformat; keyformat++) + if (!isdigit(*keyformat)) + nkeys++; + + p = beginkey; + keycnt = 0; + while (p < end && keycnt < nkeys) { + if (*p == ',') + keycnt++; + p++; + } + json->value_names.str = p; + json->value_names.len = WT_PTRDIFF(end, p); + if (idxconf == NULL) { + if (p > beginkey) + p--; + json->key_names.str = beginkey; + json->key_names.len = WT_PTRDIFF(p, beginkey); + } + return (0); +} |