[ADD/WIP] Add ParserRecomposeCommonID

This commit is contained in:
lda 2023-11-30 08:35:20 +01:00
parent 8e177baef7
commit 288ab5da54
2 changed files with 34 additions and 0 deletions

View file

@ -343,3 +343,30 @@ ValidCommonID(char *str, char sigil)
CommonIDFree(id); CommonIDFree(id);
return ret; return ret;
} }
char *
ParserRecomposeCommonID(CommonID id)
{
char *ret = Malloc(2);
ret[0] = id.sigil;
ret[1] = '\0';
if (id.local)
{
char *tmp = StrConcat(2, ret, id.local);
Free(ret);
ret = tmp;
}
if (id.server.hostname)
{
char *tmp = StrConcat(3, ret, ":", id.server.hostname);
Free(ret);
ret = tmp;
}
if (id.server.port)
{
char *tmp = StrConcat(3, ret, ":", id.server.port);
Free(ret);
ret = tmp;
}
return ret;
}

View file

@ -68,5 +68,12 @@ extern int ValidCommonID(char *, char);
*/ */
extern void CommonIDFree(CommonID id); extern void CommonIDFree(CommonID id);
/**
* Recompose a Common ID into a string which lives in the heap, and must
* therefore be freed with
* .Fn Free .
*/
extern char * ParserRecomposeCommonID(CommonID);
#endif /* TELODENDRIA_PARSER_H */ #endif /* TELODENDRIA_PARSER_H */