Weird code in ChangeSet 4c1b78
- From: Roland Illig <roland illig gmx de>
- To: midnight commander devel <mc-devel gnome org>
- Subject: Weird code in ChangeSet 4c1b78
- Date: Tue, 06 Jan 2009 23:45:20 +0100
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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]