#include #include #include #include #include #include struct ivy_ident *ivy_ident_create(void) { struct ivy_ident *id = malloc(sizeof *id); if (!id) { return NULL; } memset(id, 0x0, sizeof *id); return id; } void ivy_ident_destroy(struct ivy_ident *ident) { b_queue_entry *entry = b_queue_first(&ident->id_parts); while (entry) { struct ivy_ident_part *part = b_unbox(struct ivy_ident_part, entry, p_entry); b_queue_entry *next = b_queue_next(entry); b_queue_delete(&ident->id_parts, entry); free(part->p_str); free(part); entry = next; } free(ident); } void ivy_ident_add_part(struct ivy_ident *ident, const char *s) { struct ivy_ident_part *part = malloc(sizeof *part); if (!part) { return; } memset(part, 0x0, sizeof *part); part->p_str = b_strdup(s); b_queue_push_back(&ident->id_parts, &part->p_entry); } size_t ivy_ident_to_string(const struct ivy_ident *ident, char *out, size_t max) { b_stringstream *strv = b_stringstream_create_with_buffer(out, max); int i = 0; b_queue_entry *entry = b_queue_first(&ident->id_parts); while (entry) { if (i > 0) { b_stream_write_char(strv, '.'); } struct ivy_ident_part *part = b_unbox(struct ivy_ident_part, entry, p_entry); b_stream_write_string(strv, part->p_str, NULL); i++; } /* TODO return string length. */ return 0; }