comparison gui/skin/skin.c @ 32979:4905f5a87357

Replace some awkward and unnecessary usages of strlen(). 1. A string length of zero or greater than zero can be determined by checking the first byte. 2. Leave it to strdup() to determine the length and to do allocation for a string that is to be copied. 3. If neither the string length nor the index variable is altered in a loop, string[index] (!= 0) is the condition to go with.
author ib
date Thu, 10 Mar 2011 14:20:36 +0000
parents 80087dd00035
children 2bfd000bb789
comparison
equal deleted inserted replaced
32978:b68d209b6f28 32979:4905f5a87357
177 177
178 (void)in; 178 (void)in;
179 179
180 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[skin] %send (%s)\n", space, name); 180 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[skin] %send (%s)\n", space, name);
181 181
182 if (strlen(window_name)) { 182 if (window_name[0]) {
183 window_name[0] = 0; 183 window_name[0] = 0;
184 currSection = NULL; 184 currSection = NULL;
185 currSubItem = NULL; 185 currSubItem = NULL;
186 currSubItems = NULL; 186 currSubItems = NULL;
187 } else 187 } else
709 item->fontid = id; 709 item->fontid = id;
710 item->x = x; 710 item->x = x;
711 item->y = y; 711 item->y = y;
712 item->width = -1; 712 item->width = -1;
713 item->height = -1; 713 item->height = -1;
714 714 item->label = strdup(tmp);
715 if ((item->label = malloc(strlen(tmp) + 1)) == NULL) { 715
716 if (!item->label) {
716 ERRORMESSAGE(MSGTR_SKIN_FONT_NotEnoughtMemory); 717 ERRORMESSAGE(MSGTR_SKIN_FONT_NotEnoughtMemory);
717 return 1; 718 return 1;
718 } 719 }
719
720 strcpy(item->label, tmp);
721 720
722 return 0; 721 return 0;
723 } 722 }
724 723
725 // dlabel=x,y,width,align,fontfile,"text" 724 // dlabel=x,y,width,align,fontfile,"text"
764 item->align = a; 763 item->align = a;
765 item->x = x; 764 item->x = x;
766 item->y = y; 765 item->y = y;
767 item->width = sx; 766 item->width = sx;
768 item->height = -1; 767 item->height = -1;
769 768 item->label = strdup(tmp);
770 if ((item->label = malloc(strlen(tmp) + 1)) == NULL) { 769
770 if (!item->label) {
771 ERRORMESSAGE(MSGTR_SKIN_FONT_NotEnoughtMemory); 771 ERRORMESSAGE(MSGTR_SKIN_FONT_NotEnoughtMemory);
772 return 1; 772 return 1;
773 } 773 }
774
775 strcpy(item->label, tmp);
776 774
777 return 0; 775 return 0;
778 } 776 }
779 777
780 // decoration=enable|disable 778 // decoration=enable|disable
827 825
828 char *strswap(char *in, char what, char whereof) 826 char *strswap(char *in, char what, char whereof)
829 { 827 {
830 int i; 828 int i;
831 829
832 if (strlen(in) == 0) 830 if (!*in)
833 return NULL; 831 return NULL;
834 832
835 for (i = 0; i < (int)strlen(in); i++) 833 for (i = 0; in[i]; i++)
836 if (in[i] == what) 834 if (in[i] == what)
837 in[i] = whereof; 835 in[i] = whereof;
838 836
839 return in; 837 return in;
840 } 838 }
841 839
842 char *trim(char *in) 840 char *trim(char *in)
843 { 841 {
844 int c = 0, id = 0, i; 842 int c = 0, id = 0, i;
845 843
846 if (strlen(in) == 0) 844 if (!*in)
847 return NULL; 845 return NULL;
848 846
849 while (c != (int)strlen(in)) { 847 while (c != (int)strlen(in)) {
850 if (in[c] == '"') 848 if (in[c] == '"')
851 id = !id; 849 id = !id;