From dea37bd32fecf4e09b472956a9adb7ded87baba1 Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Wed, 20 Aug 2025 20:59:54 +0200 Subject: [PATCH] fix(xml): minor fixes in parsers --- .../details/auxiliary-modules/observer/observer.rst | 2 +- src/others/observer/lv_observer.h | 6 +++--- src/others/xml/lv_xml_style.c | 2 ++ src/others/xml/lv_xml_utils.c | 13 +++++++++---- src/others/xml/parsers/lv_xml_tabview_parser.c | 9 +++++---- 5 files changed, 20 insertions(+), 12 deletions(-) diff --git a/docs/src/details/auxiliary-modules/observer/observer.rst b/docs/src/details/auxiliary-modules/observer/observer.rst index 5981d30458..23926bf31d 100644 --- a/docs/src/details/auxiliary-modules/observer/observer.rst +++ b/docs/src/details/auxiliary-modules/observer/observer.rst @@ -372,7 +372,7 @@ integer value: - Drop-Down - Roller - Slider -+ - Scale Section Min/Max values + - Scale Section Min/Max values Any number of Observers can be created for a single Widget, each bound to ONE of the above properties. diff --git a/src/others/observer/lv_observer.h b/src/others/observer/lv_observer.h index e7c7b0c316..f1fc68d32d 100644 --- a/src/others/observer/lv_observer.h +++ b/src/others/observer/lv_observer.h @@ -545,7 +545,7 @@ lv_observer_t * lv_obj_bind_checked(lv_obj_t * obj, lv_subject_t * subject); lv_observer_t * lv_label_bind_text(lv_obj_t * obj, lv_subject_t * subject, const char * fmt); #endif -#if LV_USE_LABEL +#if LV_USE_SPAN /** * Bind an integer, string, or pointer Subject to a Spangroup's Span. @@ -556,8 +556,8 @@ lv_observer_t * lv_label_bind_text(lv_obj_t * obj, lv_subject_t * subject, const * or NULL to bind to the value directly. * @return pointer to newly-created Observer * @note `fmt == NULL` can be used only with string and pointer Subjects. - * @note If Subject is a pointer and `fmt == NULL`, pointer must point - * to a `\0` terminated string. + * @note If `fmt == NULL` strings and pointers (`\0` terminated string) will be shown + * as text as they are, integers as %d, floats as %0.1f */ lv_observer_t * lv_spangroup_bind_span_text(lv_obj_t * obj, lv_span_t * span, lv_subject_t * subject, const char * fmt); diff --git a/src/others/xml/lv_xml_style.c b/src/others/xml/lv_xml_style.c index 0f797eaf5b..c967745775 100644 --- a/src/others/xml/lv_xml_style.c +++ b/src/others/xml/lv_xml_style.c @@ -290,6 +290,8 @@ lv_result_t lv_xml_style_register(lv_xml_component_scope_t * scope, const char * if(value[c] == ' ') item_cnt++; } + /*This not freed automatically as the styles doesn't have any mechanisms to detect + * removal of properties. It's assumed that the styles are created once and never freed. */ int32_t * dsc_array = lv_malloc((item_cnt + 2) * sizeof(int32_t)); /*+2 for LV_GRID_TEMPLATE_LAST*/ char * value_buf = (char *)value; diff --git a/src/others/xml/lv_xml_utils.c b/src/others/xml/lv_xml_utils.c index 459da26ea2..d86ec9e4a6 100644 --- a/src/others/xml/lv_xml_utils.c +++ b/src/others/xml/lv_xml_utils.c @@ -83,8 +83,8 @@ int32_t lv_xml_atoi_split(const char ** str, char delimiter) int32_t result = 0; int sign = 1; - /* Skip leading whitespace */ - while(*s == ' ' || *s == '\t') s++; + /* Skip leading whitespace and repeated delimiters */ + while(*s == delimiter || *s == ' ' || *s == '\t') s++; /* Handle optional sign */ if(*s == '-') { @@ -128,8 +128,8 @@ float lv_xml_atof_split(const char ** str, char delimiter) float result = 0.0f; int sign = 1; - /* Skip leading whitespace */ - while(*s == ' ' || *s == '\t') s++; + /* Skip leading whitespace and repeated delimiters */ + while(*s == delimiter || *s == ' ' || *s == '\t') s++; /* Handle optional sign */ if(*s == '-') { @@ -263,6 +263,11 @@ int32_t lv_xml_strtol(const char * str, char ** endptr, int32_t base) char * lv_xml_split_str(char ** src, char delimiter) { + /*Skip multiple delimiters*/ + while(*src[0] == delimiter) { + src++; + } + if(*src[0] == '\0') return NULL; char * src_first = *src; diff --git a/src/others/xml/parsers/lv_xml_tabview_parser.c b/src/others/xml/parsers/lv_xml_tabview_parser.c index dc93b80570..4a72146c5d 100644 --- a/src/others/xml/parsers/lv_xml_tabview_parser.c +++ b/src/others/xml/parsers/lv_xml_tabview_parser.c @@ -98,13 +98,14 @@ void * lv_xml_tabview_tab_button_create(lv_xml_parser_state_t * state, const cha const char * index_str = lv_xml_get_value_of(attrs, "index"); int32_t index_int = index_str ? lv_xml_atoi(index_str) : 0; - if(LV_ABS(index_int) >= btn_cnt) { - LV_LOG_WARN("tabindex is out of range, using the first tab instead"); - index_int = 0; - } void * item = lv_tabview_get_tab_button(tv, index_int); + if(item == NULL) { + LV_LOG_WARN("tabindex is out of range, using the first tab instead"); + item = lv_tabview_get_tab_button(tv, 0); + } + return item; }