mirror of
https://github.com/libretro/RetroArch
synced 2025-02-28 12:40:23 +00:00
Fix label sanitization (#14428)
This simplify and trim whitespaces left. ie, starting, trailing and multiple consecutive whitespaces are now removed.
This commit is contained in:
parent
e8f4425eed
commit
c10a4d632f
@ -81,13 +81,23 @@ void label_sanitize(char *label, bool (*left)(char*), bool (*right)(char*))
|
|||||||
if ((*left)(&label[lindex]))
|
if ((*left)(&label[lindex]))
|
||||||
copy = false;
|
copy = false;
|
||||||
else
|
else
|
||||||
new_label[rindex++] = label[lindex];
|
{
|
||||||
|
const bool whitespace = label[lindex] == ' ' && (rindex == 0 || new_label[rindex - 1] == ' ');
|
||||||
|
|
||||||
|
/* Simplify consecutive whitespaces */
|
||||||
|
if (!whitespace)
|
||||||
|
new_label[rindex++] = label[lindex];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if ((*right)(&label[lindex]))
|
else if ((*right)(&label[lindex]))
|
||||||
copy = true;
|
copy = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
new_label[rindex] = '\0';
|
/* Trim trailing whitespace */
|
||||||
|
if (rindex > 0 && new_label[rindex - 1] == ' ')
|
||||||
|
new_label[rindex - 1] = '\0';
|
||||||
|
else
|
||||||
|
new_label[rindex] = '\0';
|
||||||
|
|
||||||
strlcpy(label, new_label, PATH_MAX_LENGTH);
|
strlcpy(label, new_label, PATH_MAX_LENGTH);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user