[value] add some functions to handle liValue

personal/stbuehler/wip
Stefan Bühler 11 years ago
parent 3f12becf59
commit 9e215e397f
  1. 8
      include/lighttpd/value.h
  2. 21
      src/main/value.c

@ -35,6 +35,11 @@ LI_API liValue* li_value_new_hash();
LI_API liValue* li_value_new_action(liServer *srv, liAction *a);
LI_API liValue* li_value_new_condition(liServer *srv, liCondition *c);
LI_API void li_value_list_append(liValue *list, liValue *item); /* list MUST be of type LIST */
/* wraps current content in a list with 1 entry */
LI_API void li_value_wrap_in_list(liValue *val);
LI_API liValue* li_value_copy(liValue* val);
LI_API void li_value_free(liValue* val);
@ -55,4 +60,7 @@ LI_API GHashTable* li_value_extract_hash(liValue *val);
LI_API liAction* li_value_extract_action(liValue *val);
LI_API liCondition* li_value_extract_condition(liValue *val);
/* move the value content to a new value, set the old type to none */
LI_API liValue* li_value_extract(liValue *val);
#endif

@ -67,11 +67,23 @@ liValue* li_value_new_condition(liServer *srv, liCondition *c) {
return v;
}
void li_value_list_append(liValue *list, liValue *item) {
assert(LI_VALUE_LIST == list->type);
g_array_append_val(list->data.list, item);
}
void li_value_wrap_in_list(liValue *val) {
liValue *item = li_value_extract(val);
val->type = LI_VALUE_LIST;
val->data.list = g_array_new(FALSE, TRUE, sizeof(liValue*));
g_array_append_val(val->data.list, item);
}
liValue* li_value_copy(liValue* val) {
liValue *n;
switch (val->type) {
case LI_VALUE_NONE: n = li_value_new_bool(FALSE); n->type = LI_VALUE_NONE; return n; /* hack */
case LI_VALUE_NONE: return li_value_new_none();
case LI_VALUE_BOOLEAN: return li_value_new_bool(val->data.boolean);
case LI_VALUE_NUMBER: return li_value_new_number(val->data.number);
case LI_VALUE_STRING: return li_value_new_string(g_string_new_len(GSTR_LEN(val->data.string)));
@ -298,3 +310,10 @@ liCondition* li_value_extract_condition(liValue *val) {
val->type = LI_VALUE_NONE;
return val->data.val_cond.cond;
}
liValue* li_value_extract(liValue *val) {
liValue *v = li_value_new_none();
*v = *val;
val->type = LI_VALUE_NONE;
return v;
}

Loading…
Cancel
Save