2 stringlist.c - MaLa stringlists
4 Copyright (C) 2004, 2005, Christian Thaeter <chth@gmx.net>
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License version 2 as
8 published by the Free Software Foundation.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, contact me.
21 #include "stringlist.h"
24 mala_stringlist_new ()
27 self
= malloc (sizeof(mala_stringlist
));
36 mala_stringlist_new_cstrs (char **cstrs
,
38 MalaStringBucket bucket
)
41 MalaStringListNode node
;
43 self
= mala_stringlist_new ();
47 for (; nelem
!= 0 && *cstrs
; --nelem
, ++cstrs
)
49 node
= malloc (sizeof(mala_stringlistnode
));
53 node
->string
= mala_string_new (*cstrs
, bucket
);
57 CIRCLEQ_INSERT_TAIL(self
, node
, node
);
65 mala_stringlist_free (self
);
71 mala_stringlist_head_new (MalaStringList head
, MalaString str
)
78 n
= malloc(sizeof(mala_stringlistnode
));
82 n
->string
= mala_string_copy (str
);
84 CIRCLEQ_INSERT_HEAD (head
, n
, node
);
89 mala_stringlist_tail_new (MalaStringList head
, MalaString str
)
96 n
= malloc(sizeof(mala_stringlistnode
));
100 n
->string
= mala_string_copy (str
);
102 CIRCLEQ_INSERT_TAIL (head
, n
, node
);
107 mala_stringlist_head_new_cstr (MalaStringList head
, const char * cstr
, MalaStringBucket bucket
)
110 MalaStringListNode n
;
112 str
= mala_string_new (cstr
, bucket
);
116 n
= mala_stringlist_head_new (head
, str
);
118 mala_string_free (str
);
123 mala_stringlist_tail_new_cstr (MalaStringList head
, const char * cstr
, MalaStringBucket bucket
)
126 MalaStringListNode n
;
128 str
= mala_string_new (cstr
, bucket
);
132 n
= mala_stringlist_tail_new (head
, str
);
134 mala_string_free (str
);
140 mala_stringlist_after_new (MalaStringList head
, MalaStringListNode pred
, MalaString str
)
142 MalaStringListNode n
= malloc(sizeof(mala_stringlistnode
));
146 n
->string
= mala_string_copy (str
);
148 CIRCLEQ_INSERT_AFTER (head
, pred
, n
, node
);
154 mala_stringlist_before_new (MalaStringList head
, MalaStringListNode succ
, MalaString str
)
156 MalaStringListNode n
= malloc(sizeof(mala_stringlistnode
));
160 n
->string
= mala_string_copy (str
);
162 CIRCLEQ_INSERT_BEFORE (head
, succ
, n
, node
);
168 mala_stringlist_elem_remove (MalaStringList head
, MalaStringListNode elem
)
170 CIRCLEQ_REMOVE (head
, elem
, node
);
175 mala_stringlist_elem_delete (MalaStringList head
, MalaStringListNode elem
)
177 mala_stringlist_elem_remove (head
, elem
);
178 mala_string_free (elem
->string
);
183 mala_stringlist_erase (MalaStringList head
)
185 while (head
->cqh_first
!= (void *) head
)
187 MalaStringListNode n
= head
->cqh_first
;
188 CIRCLEQ_REMOVE(head
, n
, node
);
189 mala_string_free (n
->string
);
195 mala_stringlist_free (MalaStringList head
)
200 mala_stringlist_erase (head
);
205 mala_stringlist_factory (MalaStringList_ref dest
, char** src
, MalaStringBucket bucket
)
209 return *dest
= mala_stringlist_new_cstrs (src
, -1, bucket
);
213 mala_stringlist_free (*dest
);
219 mala_stringlist_char_exists (MalaStringList head
, const char c
)
221 MalaStringListNode itr
;
222 for (itr
= head
->cqh_first
; itr
!= (void *)head
; itr
= itr
->node
.cqe_next
)
223 if (SIZE_MAX
!= mala_string_char_find (itr
->string
, c
))
232 // c-file-style: "gnu"
234 // arch-tag: 75b1fbb2-0328-450d-8708-daf943e7bbf6