static bson_bool_t bson_isnumstr(const char *str, int len);
static void bson_append_fpath_from_iterator(const char *fpath, const bson_iterator *from, bson *into);
+static const char *bson_iterator_value2(const bson_iterator *i, int *klen);
/* ----------------------------
READING
}
bson_type bson_iterator_next(bson_iterator *i) {
- int ds;
-
+ int ds, out, klen = 0;
if (i->first) {
i->first = 0;
return (bson_type) (*i->cur);
}
-
switch (bson_iterator_type(i)) {
case BSON_EOO:
return BSON_EOO; /* don't advance */
case BSON_STRING:
case BSON_SYMBOL:
case BSON_CODE:
- ds = 4 + bson_iterator_int_raw(i);
+ bson_little_endian32(&out, bson_iterator_value2(i, &klen));
+ ds = 4 + out;
break;
case BSON_BINDATA:
- ds = 5 + bson_iterator_int_raw(i);
+ bson_little_endian32(&out, bson_iterator_value2(i, &klen));
+ ds = 5 + out;
break;
case BSON_OBJECT:
case BSON_ARRAY:
case BSON_CODEWSCOPE:
- ds = bson_iterator_int_raw(i);
+ bson_little_endian32(&out, bson_iterator_value2(i, &klen));
+ ds = out;
break;
case BSON_DBREF:
- ds = 4 + 12 + bson_iterator_int_raw(i);
+ bson_little_endian32(&out, bson_iterator_value2(i, &klen));
+ ds = 4 + 12 + out;
break;
case BSON_REGEX:
{
- const char *s = bson_iterator_value(i);
+ const char *s = bson_iterator_value2(i, &klen);
const char *p = s;
p += strlen(p) + 1;
p += strlen(p) + 1;
return 0;
}
}
-
- i->cur += 1 + strlen(i->cur + 1) + 1 + ds;
-
+ if (klen == 0) {
+ for (; *(i->cur + 1 + klen) != '\0'; ++klen);
+ }
+ i->cur += (1 + klen + 1 + ds);
return (bson_type) (*i->cur);
}
out[3] = in[0];
}
+static const char *bson_iterator_value2(const bson_iterator *i, int *klen) {
+ const char *t = i->cur + 1;
+ *klen = strlen(t);
+ t += (*klen + 1);
+ return t;
+}
+
int bson_append_array_from_iterator(const char *key, bson_iterator *from, bson *into) {
assert(key && from && into);
bson_type bt;
- /*************************************************************************************************
- * basic utilities
- *************************************************************************************************/
+/*************************************************************************************************
+ * basic utilities
+ *************************************************************************************************/
- /* String containing the version information. */
- extern EJDB_EXPORT const char *tcversion;
+/* String containing the version information. */
+extern EJDB_EXPORT const char *tcversion;
/* Pointer to the call back function for handling a fatal error.