Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
Grpc
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
tci-gateway-module
Grpc
Commits
66a1c08e
Commit
66a1c08e
authored
10 years ago
by
Craig Tiller
Browse files
Options
Downloads
Patches
Plain Diff
Utilities for concatenating many strings
parent
d09f8806
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/core/support/string.c
+43
-0
43 additions, 0 deletions
src/core/support/string.c
src/core/support/string.h
+15
-0
15 additions, 0 deletions
src/core/support/string.h
with
58 additions
and
0 deletions
src/core/support/string.c
+
43
−
0
View file @
66a1c08e
...
@@ -152,3 +152,46 @@ int gpr_ltoa(long value, char *string) {
...
@@ -152,3 +152,46 @@ int gpr_ltoa(long value, char *string) {
string
[
i
]
=
0
;
string
[
i
]
=
0
;
return
i
;
return
i
;
}
}
char
*
gpr_strjoin
(
const
char
**
strs
,
size_t
nstrs
)
{
size_t
out_length
=
0
;
size_t
i
;
char
*
out
;
for
(
i
=
0
;
i
<
nstrs
;
i
++
)
{
out_length
+=
strlen
(
strs
[
i
]);
}
out_length
+=
1
;
/* null terminator */
out
=
gpr_malloc
(
out_length
);
out_length
=
0
;
for
(
i
=
0
;
i
<
nstrs
;
i
++
)
{
size_t
slen
=
strlen
(
strs
[
i
]);
memcpy
(
out
+
out_length
,
strs
[
i
],
slen
);
out_length
+=
slen
;
}
out
[
out_length
]
=
0
;
return
out
;
}
void
gpr_strvec_init
(
gpr_strvec
*
sv
)
{
memset
(
sv
,
0
,
sizeof
(
*
sv
));
}
void
gpr_strvec_destroy
(
gpr_strvec
*
sv
)
{
size_t
i
;
for
(
i
=
0
;
i
<
sv
->
count
;
i
++
)
{
gpr_free
(
sv
->
strs
[
i
]);
}
gpr_free
(
sv
->
strs
);
}
void
gpr_strvec_add
(
gpr_strvec
*
sv
,
char
*
str
)
{
if
(
sv
->
count
==
sv
->
capacity
)
{
sv
->
capacity
=
GPR_MAX
(
sv
->
capacity
+
8
,
sv
->
capacity
*
3
/
2
);
sv
->
strs
=
gpr_realloc
(
sv
->
strs
,
sizeof
(
char
*
)
*
sv
->
capacity
);
}
sv
->
strs
[
sv
->
count
++
]
=
str
;
}
char
*
gpr_strvec_flatten
(
gpr_strvec
*
sv
)
{
return
gpr_strjoin
((
const
char
**
)
sv
->
strs
,
sv
->
count
);
}
This diff is collapsed.
Click to expand it.
src/core/support/string.h
+
15
−
0
View file @
66a1c08e
...
@@ -80,6 +80,21 @@ void gpr_reverse_bytes(char *str, int len);
...
@@ -80,6 +80,21 @@ void gpr_reverse_bytes(char *str, int len);
the result is undefined. */
the result is undefined. */
int
gpr_asprintf
(
char
**
strp
,
const
char
*
format
,
...);
int
gpr_asprintf
(
char
**
strp
,
const
char
*
format
,
...);
/* Join a set of strings, returning the resulting string */
char
*
gpr_strjoin
(
const
char
**
strs
,
size_t
nstrs
);
/* A vector of strings... addition takes ownership of strings */
typedef
struct
{
char
**
strs
;
size_t
count
;
size_t
capacity
;
}
gpr_strvec
;
void
gpr_strvec_init
(
gpr_strvec
*
strs
);
void
gpr_strvec_destroy
(
gpr_strvec
*
strs
);
void
gpr_strvec_add
(
gpr_strvec
*
strs
,
char
*
add
);
char
*
gpr_strvec_flatten
(
gpr_strvec
*
strs
);
#ifdef __cplusplus
#ifdef __cplusplus
}
}
#endif
#endif
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment