commit - e681c648985bad74ff7037fd06d4c65ae580e696
commit + 7bcbb606cd3fc34596f76643e2dd808c0dea09e6
blob - 046848e626273d061952da0aa96cc7a0545ee61a
blob + e1abd1178b318b6b8551e322e4de6592db152603
--- iri.c
+++ iri.c
}
static const char *
-parse_query(const char *s, struct iri *iri)
+parse_qf(const char *s, int flag, struct iri *iri, char *buf, size_t bufsize)
{
const char *n, *t = s;
break;
}
- if (cpstr(s, t, iri->iri_query, sizeof(iri->iri_query)) == -1)
+ if (cpstr(s, t, buf, bufsize) == -1)
return (NULL);
- iri->iri_flags |= IH_QUERY;
- return (t);
-}
-
-static const char *
-parse_fragment(const char *s, struct iri *iri)
-{
- const char *n, *t = s;
-
- for (;;) {
- if ((n = advance_pchar(t)) != NULL)
- t = n;
- else if (*t == '/' || *t == '?')
- t++;
- else
- break;
- }
-
- if (cpstr(s, t, iri->iri_fragment, sizeof(iri->iri_fragment)) == -1)
- return (NULL);
- iri->iri_flags |= IH_FRAGMENT;
+ iri->iri_flags |= flag;
return (t);
}
if ((s = parse_hier(s + 1, iri)) == NULL)
return (-1);
- if (*s == '?' && (s = parse_query(s + 1, iri)) == NULL)
- return (-1);
+ if (*s == '?') {
+ s = parse_qf(s + 1, IH_QUERY, iri, iri->iri_query,
+ sizeof(iri->iri_query));
+ if (s == NULL)
+ return (-1);
+ }
- if (*s == '#' && (s = parse_fragment(s + 1, iri)) == NULL)
- return (-1);
+ if (*s == '#') {
+ s = parse_qf(s + 1, IH_FRAGMENT, iri, iri->iri_fragment,
+ sizeof(iri->iri_fragment));
+ if (s == NULL)
+ return (-1);
+ }
if (*s == '\0')
return (0);
if ((s = parse_relative(s, iri)) == NULL)
return (-1);
- if (*s == '?' && (s = parse_query(s + 1, iri)) == NULL)
- return (-1);
+ if (*s == '?') {
+ s = parse_qf(s + 1, IH_QUERY, iri, iri->iri_query,
+ sizeof(iri->iri_query));
+ if (s == NULL)
+ return (-1);
+ }
- if (*s == '#' && (s = parse_fragment(s + 1, iri)) == NULL)
- return (-1);
+ if (*s == '#') {
+ s = parse_qf(s + 1, IH_FRAGMENT, iri, iri->iri_fragment,
+ sizeof(iri->iri_fragment));
+ if (s == NULL)
+ return (-1);
+ }
if (*s == '\0')
return (0);