Fixed gm_string_skip_till, removed commented stringlist functions
This commit is contained in:
parent
31c733b972
commit
81dfcf27fb
|
@ -5,110 +5,7 @@
|
|||
#include "gm-string.h"
|
||||
#include "gm-debug.h"
|
||||
|
||||
/*
|
||||
void
|
||||
stringlist_add(stringlist * strl, char *data) {
|
||||
stringlist_item *newStringlistItem =
|
||||
(stringlist_item *) malloc(sizeof(stringlist_item));
|
||||
newStringlistItem->data = strdup(data);
|
||||
|
||||
if (strl->firstItem == NULL) {
|
||||
strl->firstItem = newStringlistItem;
|
||||
} else {
|
||||
newStringlistItem->prev = strl->lastItem;
|
||||
|
||||
if (strl->lastItem != NULL)
|
||||
strl->lastItem->next = newStringlistItem;
|
||||
}
|
||||
|
||||
strl->lastItem = newStringlistItem;
|
||||
newStringlistItem->next = NULL;
|
||||
|
||||
strl->count++;
|
||||
}
|
||||
|
||||
void
|
||||
stringlist_remove(stringlist * strl, stringlist_item * removed) {
|
||||
if (removed == strl->firstItem) {
|
||||
strl->firstItem = removed->next;
|
||||
} else {
|
||||
removed->prev->next = removed->next;
|
||||
}
|
||||
|
||||
if (removed == strl->lastItem) {
|
||||
strl->lastItem = removed->prev;
|
||||
} else {
|
||||
removed->next->prev = removed->next;
|
||||
}
|
||||
|
||||
free(removed->data);
|
||||
free(removed);
|
||||
strl->count--;
|
||||
}
|
||||
|
||||
stringlist *
|
||||
stringlist_create(char *argstr, char *delim) {
|
||||
stringlist *newStringlist = (stringlist *) malloc(sizeof(stringlist));
|
||||
char *data, *work, *working, *strPos;
|
||||
|
||||
newStringlist->firstItem = NULL;
|
||||
newStringlist->lastItem = NULL;
|
||||
newStringlist->count = 0;
|
||||
|
||||
if (delim == NULL) {
|
||||
stringlist_add(newStringlist, argstr);
|
||||
return newStringlist;
|
||||
}
|
||||
|
||||
working = strdup(argstr);
|
||||
working = mystring_cat(working, delim);
|
||||
work = working;
|
||||
|
||||
while (strlen(work) != 0) {
|
||||
|
||||
if ((strPos = strstr(work, delim)) != NULL && strPos > work) {
|
||||
data = NULL;
|
||||
data = mystring_catn(data, work, (strPos - work));
|
||||
stringlist_add(newStringlist, data);
|
||||
free(data);
|
||||
}
|
||||
work = strPos + strlen(delim);
|
||||
|
||||
}
|
||||
|
||||
free(working);
|
||||
return newStringlist;
|
||||
}
|
||||
|
||||
void
|
||||
stringlist_destroy(stringlist * strl) {
|
||||
stringlist_item *curItem = strl->firstItem;
|
||||
|
||||
while (curItem != NULL) {
|
||||
stringlist_remove(strl, curItem);
|
||||
curItem = strl->firstItem;
|
||||
}
|
||||
|
||||
free(strl);
|
||||
}
|
||||
|
||||
char *
|
||||
stringlist_glue_it(stringlist * strl, char *glue) {
|
||||
char *result = NULL;
|
||||
stringlist_item *curItem = strl->firstItem;
|
||||
|
||||
while (curItem != NULL) {
|
||||
if (curItem != strl->firstItem) {
|
||||
result = mystring_cat(result, glue);
|
||||
result = mystring_cat(result, curItem->data);
|
||||
} else {
|
||||
result = strdup(curItem->data);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
*/
|
||||
gboolean
|
||||
gm_string_to_int(const gchar *str, int *result) {
|
||||
*result = 0;
|
||||
|
@ -233,16 +130,20 @@ gm_string_skip_nonspace(gchar const **ptr) {
|
|||
void
|
||||
gm_string_skip_till(gchar const **ptr, gchar const *find) {
|
||||
gchar const *fptr;
|
||||
gunichar check;
|
||||
gunichar check, c;
|
||||
|
||||
while (**ptr != '\0') {
|
||||
check = g_utf8_get_char(*ptr);
|
||||
fptr = find;
|
||||
|
||||
for (fptr = find; *fptr; ++fptr) {
|
||||
// CHECK: find should also be treated as utf8!
|
||||
if (check == (gunichar)(*fptr)) {
|
||||
while (*fptr != '\0') {
|
||||
c = g_utf8_get_char(fptr);
|
||||
|
||||
if (check == c) {
|
||||
return;
|
||||
}
|
||||
|
||||
fptr = g_utf8_next_char(fptr);
|
||||
}
|
||||
|
||||
*ptr = g_utf8_next_char(*ptr);
|
||||
|
|
Reference in New Issue