Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
git2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
git2
Commits
0181b4cb
Commit
0181b4cb
authored
Apr 22, 2023
by
Edward Thomson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Introduce `git_strlist` to manage string lists
parent
da265cdf
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
86 additions
and
0 deletions
+86
-0
src/util/strlist.c
+66
-0
src/util/strlist.h
+20
-0
No files found.
src/util/strlist.c
View file @
0181b4cb
...
@@ -28,6 +28,59 @@ int git_strlist_copy(char ***out, const char **in, size_t len)
...
@@ -28,6 +28,59 @@ int git_strlist_copy(char ***out, const char **in, size_t len)
return
0
;
return
0
;
}
}
int
git_strlist_copy_with_null
(
char
***
out
,
const
char
**
in
,
size_t
len
)
{
char
**
dup
;
size_t
new_len
,
i
;
GIT_ERROR_CHECK_ALLOC_ADD
(
&
new_len
,
len
,
1
);
dup
=
git__calloc
(
new_len
,
sizeof
(
char
*
));
GIT_ERROR_CHECK_ALLOC
(
dup
);
for
(
i
=
0
;
i
<
len
;
i
++
)
{
dup
[
i
]
=
git__strdup
(
in
[
i
]);
GIT_ERROR_CHECK_ALLOC
(
dup
[
i
]);
}
*
out
=
dup
;
return
0
;
}
bool
git_strlist_contains_prefix
(
const
char
**
strings
,
size_t
len
,
const
char
*
str
,
size_t
n
)
{
size_t
i
;
for
(
i
=
0
;
i
<
len
;
i
++
)
{
if
(
strncmp
(
strings
[
i
],
str
,
n
)
==
0
)
return
true
;
}
return
false
;
}
bool
git_strlist_contains_key
(
const
char
**
strings
,
size_t
len
,
const
char
*
key
,
char
delimiter
)
{
const
char
*
c
;
for
(
c
=
key
;
*
c
;
c
++
)
{
if
(
*
c
==
delimiter
)
break
;
}
return
*
c
?
git_strlist_contains_prefix
(
strings
,
len
,
key
,
(
c
-
key
))
:
false
;
}
void
git_strlist_free
(
char
**
strings
,
size_t
len
)
void
git_strlist_free
(
char
**
strings
,
size_t
len
)
{
{
size_t
i
;
size_t
i
;
...
@@ -40,3 +93,16 @@ void git_strlist_free(char **strings, size_t len)
...
@@ -40,3 +93,16 @@ void git_strlist_free(char **strings, size_t len)
git__free
(
strings
);
git__free
(
strings
);
}
}
void
git_strlist_free_with_null
(
char
**
strings
)
{
char
**
s
;
if
(
!
strings
)
return
;
for
(
s
=
strings
;
*
s
;
s
++
)
git__free
(
*
s
);
git__free
(
strings
);
}
src/util/strlist.h
View file @
0181b4cb
...
@@ -11,6 +11,26 @@
...
@@ -11,6 +11,26 @@
#include "git2_util.h"
#include "git2_util.h"
extern
int
git_strlist_copy
(
char
***
out
,
const
char
**
in
,
size_t
len
);
extern
int
git_strlist_copy
(
char
***
out
,
const
char
**
in
,
size_t
len
);
extern
int
git_strlist_copy_with_null
(
char
***
out
,
const
char
**
in
,
size_t
len
);
extern
bool
git_strlist_contains_prefix
(
const
char
**
strings
,
size_t
len
,
const
char
*
str
,
size_t
n
);
extern
bool
git_strlist_contains_key
(
const
char
**
strings
,
size_t
len
,
const
char
*
key
,
char
delimiter
);
extern
void
git_strlist_free
(
char
**
strings
,
size_t
len
);
extern
void
git_strlist_free
(
char
**
strings
,
size_t
len
);
extern
void
git_strlist_free_with_null
(
char
**
strings
);
#endif
#endif
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