ref: 63ab1619dbd1d7b3aefb05a04b0ce65a85f8f8e7
parent: f4a258fdbe0f2b82de6de38f491e31a4bb1a4c3f
author: sirjofri <[email protected]>
date: Sat Oct 19 12:05:31 EDT 2024
fixes uppercase on export
--- a/libvcard/vcard.c
+++ b/libvcard/vcard.c
@@ -6,6 +6,15 @@
extern char *vcparsestr;
extern int yyparse(void);
+static char*
+estrdup(char *s)
+{
+ char *t = strdup(s);
+ if (!t)
+ sysfatal("%r");
+ return t;
+}
+
static Vcard*
parse(char *s)
{
@@ -64,6 +73,16 @@
return parse(s);
}
+static void
+iltoupper(char *s)
+{
+ while (*s) {
+ if (*s >= 'a' && *s <= 'z')
+ *s = *s - 'a' + 'A';
+ s++;
+ }
+}
+
Vcard*
vcparsefile(char *file)
{
@@ -97,6 +116,7 @@
{
Vparam *p;
char *s, *ns, *ps;
+ char *upper;
if (!param)
return strdup("");
@@ -104,7 +124,10 @@
s = nil;
for (p = param; p; p = p->next) {
// TODO: only quote if needed
- ps = smprint(";%s=\"%s\"", p->name, p->value);
+ upper = estrdup(p->name);
+ iltoupper(upper);
+ ps = smprint(";%s=\"%s\"", upper, p->value);
+ free(upper);
if (!ps)
return nil;
@@ -125,6 +148,7 @@
{
Vline *l;
char *s, *ns, *ls, *ps;
+ char *upper;
s = nil;
for (l = line; l; l = l->next) {
@@ -133,12 +157,15 @@
if (s) free(s);
return nil;
}
+ upper = estrdup(l->name);
+ iltoupper(upper);
ls = smprint(
"%s%s" /* group string */
"%s%s:%s\r\n", /* name, param, value */
(l->group ? l->group : ""), /* group string */
(l->group ? "." : ""), /* group dot */
- l->name, ps, l->value);
+ upper, ps, l->value);
+ free(upper);
if (!ls) {
if (s) free(s);
return nil;