spif_str_t spif_str_show(spif_str_t self, spif_charptr_t name, spif_str_t buff, size_t indent) { spif_char_t tmp[4096]; if (SPIF_STR_ISNULL(self)) { SPIF_OBJ_SHOW_NULL(str, name, buff, indent, tmp); return buff; } memset(tmp, ' ', indent); snprintf((char *) tmp + indent, sizeof(tmp) - indent, "(spif_str_t) %s: %10p { \"", name, (spif_ptr_t) self); if (SPIF_STR_ISNULL(buff)) { buff = spif_str_new_from_ptr(tmp); } else { spif_str_append_from_ptr(buff, tmp); } spif_str_append(buff, self); snprintf((char *) tmp, sizeof(tmp), "\", len %lu, size %lu }\n", (unsigned long) self->len, (unsigned long) self->size); spif_str_append_from_ptr(buff, tmp); return buff; }
spif_bool_t spif_url_unparse(spif_url_t self) { ASSERT_RVAL(!SPIF_URL_ISNULL(self), FALSE); spif_str_done(SPIF_STR(self)); spif_str_init_from_ptr(SPIF_STR(self), SPIF_CHARPTR("")); /* First, proto followed by a colon. */ if (!SPIF_STR_ISNULL(self->proto)) { spif_str_append(SPIF_STR(self), self->proto); spif_str_append_char(SPIF_STR(self), ':'); } /* If we have a port but no host, make it localhost. */ if (!SPIF_STR_ISNULL(self->port) && SPIF_STR_ISNULL(self->host)) { self->host = spif_str_new_from_ptr(SPIF_CHARPTR("localhost")); } /* We need the // if we have a hostname. */ if (!SPIF_STR_ISNULL(self->host)) { spif_str_append_from_ptr(SPIF_STR(self), SPIF_CHARPTR("//")); } if (!SPIF_STR_ISNULL(self->user)) { spif_str_append(SPIF_STR(self), self->user); if (!SPIF_STR_ISNULL(self->passwd)) { spif_str_append_char(SPIF_STR(self), ':'); spif_str_append(SPIF_STR(self), self->passwd); } spif_str_append_char(SPIF_STR(self), '@'); } if (!SPIF_STR_ISNULL(self->host)) { spif_str_append(SPIF_STR(self), self->host); if (!SPIF_STR_ISNULL(self->port)) { spif_str_append_char(SPIF_STR(self), ':'); spif_str_append(SPIF_STR(self), self->port); } } if (!SPIF_STR_ISNULL(self->path)) { spif_str_append(SPIF_STR(self), self->path); } if (!SPIF_STR_ISNULL(self->query)) { spif_str_append_char(SPIF_STR(self), '?'); spif_str_append(SPIF_STR(self), self->query); } return TRUE; }