Weird code in ChangeSet 4c1b78
Roland Illig
roland.illig at gmx.de
Tue Jan 6 22:45:20 UTC 2009
Hi,
http://www.midnight-commander.org/changeset/4c1b78
I don't get why there has to be a variable k in the functions. Its
completely unnecessary. A much simpler, faster, and more reliable way is
the following (untested):
char *
unescape_string(const char *in) {
GString *str;
const char * src;
char *result;
str = g_string_new("");
for (src = in; *src != '\0'; src++) {
if (src[0] == '\\' && strchr(" \t*|;<>~#()?[]{}&", src[1])) {
g_string_append_c(str, src[1]);
src++;
} else {
g_string_append_c(str, src[0]);
}
}
result = str->str;
g_string_free(str, FALSE);
return result;
}
It's much simpler that way. It doesn't call strlen() unnecessarily. It
doesn't have unneeded variables. And it doesn't crash if in[-1] is an
illegal address.
Roland
More information about the mc-devel
mailing list