summaryrefslogtreecommitdiffstats
path: root/ListItem.c
diff options
context:
space:
mode:
authorChristian Göttsche <cgzones@googlemail.com>2020-10-18 19:22:30 +0200
committercgzones <cgzones@googlemail.com>2020-10-28 20:49:11 +0100
commit03b773b701e8d2502449396214751131abd0dda5 (patch)
tree395f2a9102b5d782a0387b87b2ac3e4bfe3065f4 /ListItem.c
parent6375df49c9ceabc87066bd53eadf1ababb11c902 (diff)
Small ListItem update
Diffstat (limited to 'ListItem.c')
-rw-r--r--ListItem.c32
1 files changed, 12 insertions, 20 deletions
diff --git a/ListItem.c b/ListItem.c
index 866f20ff..031c4f72 100644
--- a/ListItem.c
+++ b/ListItem.c
@@ -27,11 +27,7 @@ static void ListItem_delete(Object* cast) {
static void ListItem_display(const Object* cast, RichString* out) {
const ListItem* const this = (const ListItem*)cast;
assert (this != NULL);
- /*
- int len = strlen(this->value)+1;
- char buffer[len+1];
- xSnprintf(buffer, len, "%s", this->value);
- */
+
if (this->moving) {
RichString_write(out, CRT_colors[DEFAULT_COLOR],
#ifdef HAVE_LIBNCURSESW
@@ -41,15 +37,9 @@ static void ListItem_display(const Object* cast, RichString* out) {
} else {
RichString_prune(out);
}
- RichString_append(out, CRT_colors[DEFAULT_COLOR], this->value/*buffer*/);
+ RichString_append(out, CRT_colors[DEFAULT_COLOR], this->value);
}
-const ObjectClass ListItem_class = {
- .display = ListItem_display,
- .delete = ListItem_delete,
- .compare = ListItem_compare
-};
-
ListItem* ListItem_new(const char* value, int key) {
ListItem* this = AllocThis(ListItem);
this->value = xStrdup(value);
@@ -59,20 +49,22 @@ ListItem* ListItem_new(const char* value, int key) {
}
void ListItem_append(ListItem* this, const char* text) {
- int oldLen = strlen(this->value);
- int textLen = strlen(text);
- int newLen = strlen(this->value) + textLen;
+ size_t oldLen = strlen(this->value);
+ size_t textLen = strlen(text);
+ size_t newLen = oldLen + textLen;
this->value = xRealloc(this->value, newLen + 1);
memcpy(this->value + oldLen, text, textLen);
this->value[newLen] = '\0';
}
-const char* ListItem_getRef(ListItem* this) {
- return this->value;
-}
-
-long ListItem_compare(const void* cast1, const void* cast2) {
+static long ListItem_compare(const void* cast1, const void* cast2) {
const ListItem* obj1 = (const ListItem*) cast1;
const ListItem* obj2 = (const ListItem*) cast2;
return strcmp(obj1->value, obj2->value);
}
+
+const ObjectClass ListItem_class = {
+ .display = ListItem_display,
+ .delete = ListItem_delete,
+ .compare = ListItem_compare
+};

© 2014-2024 Faster IT GmbH | imprint | privacy policy