diff options
author | Frank Gevaerts <frank@gevaerts.be> | 2011-09-11 15:54:56 +0000 |
---|---|---|
committer | Frank Gevaerts <frank@gevaerts.be> | 2011-09-11 15:54:56 +0000 |
commit | 78a0d49bdb4dcabb53e381e841493e893d3095bf (patch) | |
tree | b7e6b7ec37a57bcb70a079168470ea5361ad4493 | |
parent | bce46a755d65194d71992572e293daa781977818 (diff) | |
download | rockbox-78a0d49bdb4dcabb53e381e841493e893d3095bf.tar.gz rockbox-78a0d49bdb4dcabb53e381e841493e893d3095bf.zip |
Second attempt at making %ss utf8-clean
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30509 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r-- | apps/gui/skin_engine/skin_tokens.c | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/apps/gui/skin_engine/skin_tokens.c b/apps/gui/skin_engine/skin_tokens.c index 51da8c1c18..fa697b18e9 100644 --- a/apps/gui/skin_engine/skin_tokens.c +++ b/apps/gui/skin_engine/skin_tokens.c | |||
@@ -874,24 +874,29 @@ const char *get_token_value(struct gui_wps *gwps, | |||
874 | struct substring *ss = token->value.data; | 874 | struct substring *ss = token->value.data; |
875 | const char *token_val = get_token_value(gwps, ss->token, offset, | 875 | const char *token_val = get_token_value(gwps, ss->token, offset, |
876 | buf, buf_size, intval); | 876 | buf, buf_size, intval); |
877 | int ret_len = ss->length; | ||
878 | if (token_val) | 877 | if (token_val) |
879 | { | 878 | { |
880 | int len = utf8length(token_val); | 879 | int start_byte, end_byte, byte_len; |
881 | if (len < ss->start) | 880 | int utf8_len = utf8length(token_val); |
881 | |||
882 | if (utf8_len < ss->start) | ||
882 | return NULL; | 883 | return NULL; |
883 | int realstart = utf8seek(token_val, ss->start); | 884 | |
884 | if (ret_len < 0) | 885 | start_byte = utf8seek(token_val, ss->start); |
885 | ret_len = strlen(token_val) - realstart; | 886 | |
887 | if (ss->length < 0 || (ss->start + ss->length) > utf8_len) | ||
888 | end_byte = strlen(token_val); | ||
889 | else | ||
890 | end_byte = utf8seek(token_val, ss->start + ss->length); | ||
891 | |||
892 | byte_len = end_byte - start_byte; | ||
893 | |||
886 | if (token_val != buf) | 894 | if (token_val != buf) |
887 | { | 895 | memcpy(buf, &token_val[start_byte], byte_len); |
888 | memcpy(buf, &token_val[realstart], ret_len); | ||
889 | } | ||
890 | else | 896 | else |
891 | { | 897 | buf = &buf[start_byte]; |
892 | buf = &buf[realstart]; | 898 | |
893 | } | 899 | buf[byte_len] = '\0'; |
894 | buf[ret_len] = '\0'; | ||
895 | return buf; | 900 | return buf; |
896 | } | 901 | } |
897 | return NULL; | 902 | return NULL; |