Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Main
Synchronet
Commits
2b2762b8
Commit
2b2762b8
authored
May 27, 2004
by
rswindell
Browse files
Created strListInsert() and strListInsertList().
parent
93c17909
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
55 additions
and
10 deletions
+55
-10
src/xpdev/str_list.c
src/xpdev/str_list.c
+47
-8
src/xpdev/str_list.h
src/xpdev/str_list.h
+8
-2
No files found.
src/xpdev/str_list.c
View file @
2b2762b8
...
...
@@ -64,16 +64,34 @@ size_t strListCount(const str_list_t list)
return
(
i
);
}
static
str_list_t
str_list_a
dd_at
(
str_list_t
*
list
,
char
*
str
,
size_t
count
)
static
str_list_t
str_list_a
ppend
(
str_list_t
*
list
,
char
*
str
,
size_t
index
)
{
str_list_t
lp
;
if
((
lp
=
(
str_list_t
)
realloc
(
*
list
,
sizeof
(
char
*
)
*
(
count
+
2
)))
==
NULL
)
if
((
lp
=
(
str_list_t
)
realloc
(
*
list
,
sizeof
(
char
*
)
*
(
index
+
2
)))
==
NULL
)
return
(
NULL
);
*
list
=
lp
;
lp
[
count
++
]
=
str
;
lp
[
count
]
=
NULL
;
/* terminate list */
lp
[
index
++
]
=
str
;
lp
[
index
]
=
NULL
;
/* terminate list */
return
(
lp
);
}
static
str_list_t
str_list_insert
(
str_list_t
*
list
,
char
*
str
,
size_t
index
)
{
size_t
i
;
size_t
count
;
str_list_t
lp
;
count
=
strListCount
(
*
list
);
if
((
lp
=
(
str_list_t
)
realloc
(
*
list
,
sizeof
(
char
*
)
*
(
count
+
1
)))
==
NULL
)
return
(
NULL
);
*
list
=
lp
;
for
(
i
=
index
;
i
<=
count
;
i
++
)
lp
[
i
+
1
]
=
lp
[
i
];
lp
[
index
]
=
str
;
return
(
lp
);
}
...
...
@@ -87,16 +105,15 @@ str_list_t strListAddAt(str_list_t* list, const char* str, size_t count)
strcpy
(
buf
,
str
);
return
(
str_list_a
dd_at
(
list
,
buf
,
count
));
return
(
str_list_a
ppend
(
list
,
buf
,
count
));
}
str_list_t
strListAdd
(
str_list_t
*
list
,
const
char
*
str
)
{
return
strListAddAt
(
list
,
str
,
strListCount
(
*
list
));
}
str_list_t
strListAddList
(
str_list_t
*
list
,
str_list_t
add_list
)
str_list_t
strListAddList
(
str_list_t
*
list
,
const
str_list_t
add_list
)
{
size_t
i
,
j
;
...
...
@@ -107,6 +124,28 @@ str_list_t strListAddList(str_list_t* list, str_list_t add_list)
return
(
*
list
);
}
str_list_t
strListInsert
(
str_list_t
*
list
,
const
char
*
str
,
size_t
index
)
{
char
*
buf
;
if
((
buf
=
(
char
*
)
malloc
(
strlen
(
str
)
+
1
))
==
NULL
)
return
(
NULL
);
strcpy
(
buf
,
str
);
return
(
str_list_insert
(
list
,
buf
,
index
));
}
str_list_t
strListInsertList
(
str_list_t
*
list
,
const
str_list_t
add_list
,
size_t
index
)
{
size_t
i
;
for
(
i
=
0
;
add_list
[
i
];
i
++
)
strListInsert
(
list
,
add_list
[
i
],
index
++
);
return
(
*
list
);
}
str_list_t
strListSplit
(
str_list_t
*
list
,
char
*
str
,
const
char
*
delimit
)
{
char
*
token
;
...
...
@@ -144,7 +183,7 @@ str_list_t strListMerge(str_list_t* list, str_list_t add_list)
j
=
strListCount
(
*
list
);
for
(
i
=
0
;
add_list
[
i
];
i
++
)
str_list_a
dd_at
(
list
,
add_list
[
i
],
j
++
);
str_list_a
ppend
(
list
,
add_list
[
i
],
j
++
);
return
(
*
list
);
}
...
...
src/xpdev/str_list.h
View file @
2b2762b8
...
...
@@ -62,8 +62,14 @@ str_list_t strListAdd(str_list_t* list, const char* str);
/* Adds a string into the list at a specific index */
str_list_t
strListAddAt
(
str_list_t
*
list
,
const
char
*
str
,
size_t
index
);
/* Append a string list onto an another string */
str_list_t
strListAddList
(
str_list_t
*
list
,
str_list_t
append_list
);
/* Append a string list onto an another string list */
str_list_t
strListAddList
(
str_list_t
*
list
,
const
str_list_t
append_list
);
/* Inserts a string into the list at a specific index */
str_list_t
strListInsert
(
str_list_t
*
list
,
const
char
*
str
,
size_t
index
);
/* Insert a string list onto an another string list */
str_list_t
strListInsertList
(
str_list_t
*
list
,
const
str_list_t
append_list
,
size_t
index
);
/* Add to an exiting or new string list by splitting specified string (str) */
/* into multiple strings, separated by one of the delimit characters */
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment