Reimplement ical_unformat_line() using dynamic strings
Use the new dynamic string utility functions instead of relying on a fixed-size buffer. Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
This commit is contained in:
parent
5f344e177f
commit
56f615ffe2
32
src/ical.c
32
src/ical.c
@ -387,55 +387,43 @@ ical_store_apoint(char *mesg, char *note, long start, long dur,
|
|||||||
/*
|
/*
|
||||||
* Returns an allocated string representing the string given in argument once
|
* Returns an allocated string representing the string given in argument once
|
||||||
* unformatted.
|
* unformatted.
|
||||||
*
|
|
||||||
* Note:
|
|
||||||
* Even if the RFC2445 recommends not to have more than 75 octets on one line of
|
|
||||||
* text, I prefer not to restrict the parsing to this size, thus I use a buffer
|
|
||||||
* of size BUFSIZ.
|
|
||||||
*
|
|
||||||
* Extract from RFC2445:
|
|
||||||
* Lines of text SHOULD NOT be longer than 75 octets, excluding the line
|
|
||||||
* break.
|
|
||||||
*/
|
*/
|
||||||
static char *ical_unformat_line(char *line)
|
static char *ical_unformat_line(char *line)
|
||||||
{
|
{
|
||||||
char *p, uline[BUFSIZ];
|
struct string s;
|
||||||
int len;
|
char *p;
|
||||||
|
|
||||||
if (strlen(line) >= BUFSIZ)
|
string_init(&s);
|
||||||
return NULL;
|
for (p = line; *p; p++) {
|
||||||
|
|
||||||
memset(uline, 0, BUFSIZ);
|
|
||||||
for (len = 0, p = line; *p; p++) {
|
|
||||||
switch (*p) {
|
switch (*p) {
|
||||||
case '\\':
|
case '\\':
|
||||||
switch (*(p + 1)) {
|
switch (*(p + 1)) {
|
||||||
case 'n':
|
case 'n':
|
||||||
uline[len++] = '\n';
|
string_catf(&s, "%c", '\n');
|
||||||
p++;
|
p++;
|
||||||
break;
|
break;
|
||||||
case 't':
|
case 't':
|
||||||
uline[len++] = '\t';
|
string_catf(&s, "%c", '\t');
|
||||||
p++;
|
p++;
|
||||||
break;
|
break;
|
||||||
case ';':
|
case ';':
|
||||||
case ':':
|
case ':':
|
||||||
case ',':
|
case ',':
|
||||||
uline[len++] = *(p + 1);
|
string_catf(&s, "%c", *(p + 1));
|
||||||
p++;
|
p++;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
uline[len++] = *p;
|
string_catf(&s, "%c", *p);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
uline[len++] = *p;
|
string_catf(&s, "%c", *p);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return mem_strdup(uline);
|
return string_buf(&s);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
Loading…
x
Reference in New Issue
Block a user