On 31.03.2009, at 01:25, Duncan Gibson wrote: > I've just been looking through fl_utf8.cxx and came across: > > /* > * return 0 if the strings are equal; > * return 1 if s1 is greater than s2 > * return -1 if s1 is less than s2 > */ > int fl_utf_strcasecmp(const char *s1, const char *s2) > { > int s1_l = strlen(s1); > int s2_l = strlen(s2); > > if (s1_l < s2_l) { > return -1; > } else if (s1_l > s2_l) { > return 1; > } > return fl_utf_strncasecmp(s1, s2, s1_l); > }
Um, that is very wrong in many respects: strlen() does return the size of the array in bytes, not the length of the string in characters. It can not be used in this case. Now if we do have s1_l and s2_l, we must do a strncasecmp with the len set to the minimum of both. If s1_l equals s2_l we can simply return the result of strncasecmp. The same is true if the result is not zero. If strncasecmp returns zero and s1 is longer than s2, we must return 1, and if s2 is longer than s1, we return -1, because "abcd" comes before "abcde", just like "Miller" is before "Millers" in the phone book. Matthias ---- http://robowerk.com/ _______________________________________________ fltk-dev mailing list fltk-dev@easysw.com http://lists.easysw.com/mailman/listinfo/fltk-dev