diff --git a/src/element.c b/src/element.c index a10971878..ae1f50edc 100644 --- a/src/element.c +++ b/src/element.c @@ -218,7 +218,7 @@ stumpless_element_to_string( const struct stumpless_element *element ) { if( param_count != 0 ) { // extra param list chars and commas - format_len += 6 + param_count - 1; + format_len += 4 + param_count ; } else { // no params, just name format_len += 3; @@ -229,10 +229,10 @@ stumpless_element_to_string( const struct stumpless_element *element ) { goto fail; } - memcpy( format + 1, name, name_len ); + memcpy( format, name, name_len ); // build params list "param_1_to_string,param_2_to_string, ..." - size_t pos_offset = name_len + 4; + size_t pos_offset = name_len + 2; for( size_t i = 0; i < param_count; i++) { // replace '\0' with ',' at the end of each string memcpy( format + pos_offset, params_format[i], strlen(params_format[i])); @@ -246,17 +246,14 @@ stumpless_element_to_string( const struct stumpless_element *element ) { unlock_element( element ); - format[0] = '<'; - format[name_len + 1] = '>'; - if (param_count != 0 ) { - // :[param_1_to_string,param_2_to_string,etc.] (with params) - format[name_len + 2] = ':'; - format[name_len + 3] = '['; + // name=[param_1_to_string,param_2_to_string,etc.] (with params) + format[name_len ] = '='; + format[name_len + 1] = '['; format[pos_offset] = ']'; } else { - // (no params) - // pos_offset is name_len + 4 here + // name (no params) + // pos_offset is name_len + 2 here pos_offset -= 3; } diff --git a/test/function/element.cpp b/test/function/element.cpp index 9d81caa87..b8b44df68 100644 --- a/test/function/element.cpp +++ b/test/function/element.cpp @@ -808,7 +808,7 @@ namespace { format = stumpless_element_to_string( element_with_params ); ASSERT_NOT_NULL( format ); - EXPECT_STREQ( format, ":[param-1=\"value-1\",param-2=\"value-2\"]" ); + EXPECT_STREQ( format, "element-with-params=[param-1=\"value-1\",param-2=\"value-2\"]" ); EXPECT_NO_ERROR; free( ( void * ) format ); @@ -820,7 +820,7 @@ namespace { format = stumpless_element_to_string( basic_element ); ASSERT_NOT_NULL( format ); - EXPECT_STREQ( format, "" ); + EXPECT_STREQ( format, "basic-element" ); EXPECT_NO_ERROR; free( ( void * ) format );