Parse time values in Rust

parent 8a32b4cc
...@@ -670,26 +670,33 @@ st_theme_node_lookup_double (StThemeNode *node, ...@@ -670,26 +670,33 @@ st_theme_node_lookup_double (StThemeNode *node,
static GetFromTermResult static GetFromTermResult
get_time_from_term (CRTerm *term, get_time_from_term (CRTerm *term,
double *value) double *millis)
{ {
int factor = 1; char *stringified;
StylishValueResult_Time result;
if (term->type != TERM_NUMBER) stringified = (char *) cr_term_to_string (term);
result = stylish_parse_time (stringified);
g_free (stringified);
switch (result.kind)
{ {
case STYLISH_VALUE_RESULT_KIND_INHERIT:
return VALUE_INHERIT;
case STYLISH_VALUE_RESULT_KIND_SPECIFIED:
*millis = result.value.millis;
return VALUE_FOUND;
case STYLISH_VALUE_RESULT_KIND_PARSE_ERROR:
/* FIXME: propagate the error */
stylish_parse_error_free (&result.error);
return VALUE_NOT_FOUND; return VALUE_NOT_FOUND;
}
if (term->content.num->type != NUM_TIME_S && default:
term->content.num->type != NUM_TIME_MS) g_assert_not_reached();
{
return VALUE_NOT_FOUND; return VALUE_NOT_FOUND;
} }
if (term->content.num->type == NUM_TIME_S)
factor = 1000;
*value = factor * term->content.num->val;
return VALUE_FOUND;
} }
/** /**
......
Subproject commit 99022c1f9d52d8c6e5de1c131c07c116ff9f0817 Subproject commit e8acafe1b7fa7be00d93eac4236cc7e526127d77
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment