tagion_document_get_string

Get an element string value

extern (C)
int
tagion_document_get_string
(,
char** value
,
size_t* str_len
)

Parameters

element Document.Element*

element to get

value char**

pointer to the string

str_len size_t*

length of string

Return Value

Type: int

ErrorCode

Examples

auto h = new HiBON;
string key_string = "string";
h[key_string] = "wowo";
const doc = Document(h);
Document.Element elm_string;

int rt = tagion_document_element_by_key(&doc.data[0], doc.data.length, &key_string[0], key_string.length, &elm_string);
assert(rt == ErrorCode.none, "Get document element string returned error");

char* str_value;
size_t str_len;

rt = tagion_document_get_string(&elm_string, &str_value, &str_len);
assert(rt == ErrorCode.none, "get string returned error");

auto str = str_value[0..str_len];
assert(str == "wowo", "read string was different"); 
auto h = new HiBON;
h = ["hey0", "hey1", "hey2"];
const doc = Document(h);
Document.Element elm_string;
int rt = tagion_document_element_by_index(&doc.data[0], doc.data.length, 0, &elm_string);
assert(rt == ErrorCode.none, "get array index returned error");
char* str_value;
size_t str_len;

rt = tagion_document_get_string(&elm_string, &str_value, &str_len);
assert(rt == ErrorCode.none, "get string returned error");
auto str = str_value[0..str_len];
assert(str == "hey0", "read string was different"); 

// read index to trigger range error
rt = tagion_document_element_by_index(&doc.data[0], doc.data.length, 5, &elm_string);
assert(rt == ErrorCode.exception, "should throw error on undefined index");