44
55#include "include/buffer.h"
66
7- bool buffer_init (buffer_T * buffer ) {
7+ bool buffer_init (buffer_T * buffer ) {
88 buffer -> capacity = 1024 ;
99 buffer -> length = 0 ;
1010 buffer -> value = malloc (buffer -> capacity * sizeof (char ));
1111
12- if (buffer -> value ) {
12+ if (buffer -> value ) {
1313 buffer -> value [0 ] = '\0' ;
1414 }
1515
1616 return buffer != NULL ;
1717}
1818
19- char * buffer_value (buffer_T * buffer ) { return buffer -> value ; }
19+ char * buffer_value (buffer_T * buffer ) {
20+ return buffer -> value ;
21+ }
2022
21- size_t buffer_length (buffer_T * buffer ) { return buffer -> length ; }
23+ size_t buffer_length (buffer_T * buffer ) {
24+ return buffer -> length ;
25+ }
2226
23- size_t buffer_capacity (buffer_T * buffer ) { return buffer -> capacity ; }
27+ size_t buffer_capacity (buffer_T * buffer ) {
28+ return buffer -> capacity ;
29+ }
2430
25- size_t buffer_sizeof (void ) { return sizeof (buffer_T ); }
31+ size_t buffer_sizeof (void ) {
32+ return sizeof (buffer_T );
33+ }
2634
27- void buffer_append (buffer_T * buffer , const char * text ) {
35+ void buffer_append (buffer_T * buffer , const char * text ) {
2836 size_t text_length = strlen (text );
2937
30- if (buffer -> length + text_length >= buffer -> capacity ) {
38+ if (buffer -> length + text_length >= buffer -> capacity ) {
3139 size_t new_capacity = (buffer -> length + text_length ) * 2 ;
32- char * new_buffer = realloc (buffer -> value , new_capacity );
40+ char * new_buffer = realloc (buffer -> value , new_capacity );
3341
34- if (new_buffer ) {
42+ if (new_buffer ) {
3543 buffer -> value = new_buffer ;
3644 buffer -> capacity = new_capacity ;
3745 } else {
@@ -44,14 +52,13 @@ void buffer_append(buffer_T *buffer, const char *text) {
4452 buffer -> length += text_length ;
4553}
4654
47- void buffer_prepend (buffer_T * buffer , const char * text ) {
48- if (text == NULL || text [0 ] == '\0' )
49- return ;
55+ void buffer_prepend (buffer_T * buffer , const char * text ) {
56+ if (text == NULL || text [0 ] == '\0' ) return ;
5057
5158 size_t text_length = strlen (text );
5259 size_t new_length = buffer -> length + text_length ;
5360
54- if (new_length >= buffer -> capacity ) {
61+ if (new_length >= buffer -> capacity ) {
5562 size_t new_capacity = new_length * 2 ;
5663 buffer -> value = realloc (buffer -> value , new_capacity );
5764 buffer -> capacity = new_capacity ;
@@ -64,13 +71,12 @@ void buffer_prepend(buffer_T *buffer, const char *text) {
6471 buffer -> value [buffer -> length ] = '\0' ;
6572}
6673
67- void buffer_concat (buffer_T * destination , buffer_T * source ) {
68- if (source -> length == 0 )
69- return ;
74+ void buffer_concat (buffer_T * destination , buffer_T * source ) {
75+ if (source -> length == 0 ) return ;
7076
7177 size_t new_length = destination -> length + source -> length ;
7278
73- if (new_length >= destination -> capacity ) {
79+ if (new_length >= destination -> capacity ) {
7480 size_t new_capacity = new_length * 2 ;
7581 destination -> value = realloc (destination -> value , new_capacity );
7682 destination -> capacity = new_capacity ;
@@ -81,7 +87,7 @@ void buffer_concat(buffer_T *destination, buffer_T *source) {
8187 destination -> length = new_length ;
8288}
8389
84- void buffer_free (buffer_T * buffer ) {
90+ void buffer_free (buffer_T * buffer ) {
8591 free (buffer -> value );
8692 buffer -> value = NULL ;
8793 buffer -> length = buffer -> capacity = 0 ;
0 commit comments