Skip to content

Commit 465dbac

Browse files
committed
New string_buffer_append_binary function
1 parent bbac639 commit 465dbac

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
## CHANGELOG
22

3-
### v0.1.6
3+
### v0.1.6 (2021-09-24)
44

5+
* New string_buffer_append_binary function.
56
* Added void to no arg functions
67
* Removed internal release flag
78
* Added cargo-make makefile for simpler sharing of optional development build instructions.

include/string_buffer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ char *string_buffer_to_string(struct StringBuffer *);
3030
bool string_buffer_append(struct StringBuffer *, char);
3131
bool string_buffer_append_string(struct StringBuffer *, char *);
3232
bool string_buffer_append_string_with_options(struct StringBuffer *, char *, const size_t /* offset */, const size_t /* length */);
33+
bool string_buffer_append_binary(struct StringBuffer *, char *, const size_t /* offset */, const size_t /* length */);
3334
bool string_buffer_append_bool(struct StringBuffer *, bool);
3435
bool string_buffer_append_short(struct StringBuffer *, short);
3536
bool string_buffer_append_int(struct StringBuffer *, int);

src/string_buffer.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,22 @@ bool string_buffer_append_string_with_options(struct StringBuffer *buffer, char
224224
return(false);
225225
}
226226

227+
return(string_buffer_append_binary(buffer, string, offset, length));
228+
} /* string_buffer_append_string_with_options */
229+
230+
231+
bool string_buffer_append_binary(struct StringBuffer *buffer, char *content, const size_t offset, const size_t length)
232+
{
233+
if (buffer == NULL)
234+
{
235+
return(false);
236+
}
237+
238+
if (content == NULL)
239+
{
240+
return(true);
241+
}
242+
227243
const size_t loop_end = length + offset;
228244

229245
const size_t size_left = buffer->max_size - buffer->content_size;
@@ -244,14 +260,14 @@ bool string_buffer_append_string_with_options(struct StringBuffer *buffer, char
244260

245261
for (size_t index = offset, content_index = 0; index < loop_end; index++, content_index++)
246262
{
247-
buffer->value[buffer->content_size] = string[index];
263+
buffer->value[buffer->content_size] = content[index];
248264
buffer->content_size++;
249265
}
250266

251267
buffer->value[buffer->content_size] = 0;
252268

253269
return(true);
254-
} /* string_buffer_append_string_with_options */
270+
}
255271

256272

257273
char *string_buffer_to_string(struct StringBuffer *buffer)

0 commit comments

Comments
 (0)