From 31a05953e142b1ffff631cfb8b817880db7e4c27 Mon Sep 17 00:00:00 2001 From: Jonathan Gordon Date: Sun, 26 Feb 2012 00:42:53 +1100 Subject: [PATCH] FS#12586 - Modify %ss to be able to use numbers for conditionals i.e %?ss(1,1,%cM)<|one|two|three|...|> or %xd(numbers, %ss(1,1%cM) Change-Id: I74ecb3f253f3be1fd270f75c0ef79addd364a7de --- apps/gui/skin_engine/skin_parser.c | 4 ++++ apps/gui/skin_engine/skin_tokens.c | 4 ++++ apps/gui/skin_engine/wps_internals.h | 1 + lib/skin_parser/tag_table.c | 2 +- manual/appendix/wps_tags.tex | 14 ++++++++++++++ 5 files changed, 24 insertions(+), 1 deletion(-) diff --git a/apps/gui/skin_engine/skin_parser.c b/apps/gui/skin_engine/skin_parser.c index 3899f605f3..340cbbdb01 100644 --- a/apps/gui/skin_engine/skin_parser.c +++ b/apps/gui/skin_engine/skin_parser.c @@ -824,6 +824,10 @@ static int parse_substring_tag(struct skin_element* element, else ss->length = get_param(element, 1)->data.number; ss->token = get_param_code(element, 2)->data; + if (element->params_count > 3) + ss->expect_number = !strcmp(get_param_text(element, 3), "number"); + else + ss->expect_number = false; token->value.data = PTRTOSKINOFFSET(skin_buffer, ss); return 0; } diff --git a/apps/gui/skin_engine/skin_tokens.c b/apps/gui/skin_engine/skin_tokens.c index 82d96f6993..765102513a 100644 --- a/apps/gui/skin_engine/skin_tokens.c +++ b/apps/gui/skin_engine/skin_tokens.c @@ -942,6 +942,10 @@ const char *get_token_value(struct gui_wps *gwps, buf = &buf[start_byte]; buf[byte_len] = '\0'; + if (ss->expect_number && + intval && (buf[0] >= '0' && buf[0] <= '9')) + *intval = atoi(buf) + 1; /* so 0 is the first item */ + return buf; } return NULL; diff --git a/apps/gui/skin_engine/wps_internals.h b/apps/gui/skin_engine/wps_internals.h index 9c3fa1b5bc..c55c8d2515 100644 --- a/apps/gui/skin_engine/wps_internals.h +++ b/apps/gui/skin_engine/wps_internals.h @@ -286,6 +286,7 @@ struct logical_if { struct substring { int start; int length; + bool expect_number; OFFSETTYPE(struct wps_token *) token; }; diff --git a/lib/skin_parser/tag_table.c b/lib/skin_parser/tag_table.c index d10b319dcf..14876d11c4 100644 --- a/lib/skin_parser/tag_table.c +++ b/lib/skin_parser/tag_table.c @@ -240,7 +240,7 @@ static const struct tag_info legal_tags[] = { SKIN_TOKEN_VAR_GETVAL, "vg", "S", SKIN_REFRESH_DYNAMIC }, { SKIN_TOKEN_VAR_TIMEOUT, "vl", "S|D", SKIN_REFRESH_DYNAMIC }, - { SKIN_TOKEN_SUBSTRING, "ss", "IiT", SKIN_REFRESH_DYNAMIC }, + { SKIN_TOKEN_SUBSTRING, "ss", "IiT|s", SKIN_REFRESH_DYNAMIC }, { SKIN_TOKEN_UNKNOWN, "" , "", 0 } /* Keep this here to mark the end of the table */ }; diff --git a/manual/appendix/wps_tags.tex b/manual/appendix/wps_tags.tex index 0096075695..ba4cbd16ee 100644 --- a/manual/appendix/wps_tags.tex +++ b/manual/appendix/wps_tags.tex @@ -740,6 +740,20 @@ a horizontal progressbar which doesn't fill and draws the image fits inside the specified width and height.} \section{Other Tags} + +\begin{tagmap} + \config{\%ss(start, length, tag [,number]} & Get a substring from another tag.\\ +\end{tagmap} + Use this tag to get a substring from another tag. +\begin{description} + \item[start] -- first character to take (0 being the start of the string) + \item[length] -- length of the substring to return (- for the rest of the string) + \item[tag] -- tag to get + \item[number] -- OPTIONAL. if this is present it will assume the + substring is a number so it can be used with conditionals. (i.e \config{\%cM}). + 0 is the first conditional option +\end{description} + \begin{tagmap} \config{\%(} & The character `('\\ \config{\%)} & The character `)'\\ -- 2.11.4.GIT