Skip to content

Commit

Permalink
Tidied up unescape_quoted_strings() a little
Browse files Browse the repository at this point in the history
  • Loading branch information
rxi committed Sep 18, 2015
1 parent 32848d7 commit 0fe747f
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/ini.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,29 +120,27 @@ static void unescape_quoted_strings(ini_t *ini) {
* as escape sequences are always larger than their resultant data */
char *q = p;
p++;
while (*q) {
while (*p && *p != '"') {
if (*p == '\\') {
/* Handle escaped char */
p++;
switch (*p) {
case 'r' : *q = '\r'; break;
case 'n' : *q = '\n'; break;
case 't' : *q = '\t'; break;
case '\0' : goto end_string;
default : *q = *p; break;
}

} else if (*p == '"') {
/* Handle end of string */
*q = '\0';
break;

} else {
/* Handle normal char */
*q = *p;
}
q++, p++;
}
/* Fill gap between read-head and write-head's position with '\0' */
end_string:
/* Move the read-head to the start of the next string and fill the space
* between it and the write-head with '\0' */
p = next(ini, p);
memset(q, '\0', p - q);
} else {
Expand Down

0 comments on commit 0fe747f

Please sign in to comment.