docs/Writerside/topics/buffer.h.md

changeset 1576
7e19168d49d1
parent 1575
dde0c67a449b
equal deleted inserted replaced
1575:dde0c67a449b 1576:7e19168d49d1
163 size_t cxBufferWrite(const void *ptr, size_t size, size_t nitems, 163 size_t cxBufferWrite(const void *ptr, size_t size, size_t nitems,
164 CxBuffer *buffer); 164 CxBuffer *buffer);
165 165
166 int cxBufferPut(CxBuffer *buffer, int c); 166 int cxBufferPut(CxBuffer *buffer, int c);
167 167
168 size_t cxBufferPutString(CxBuffer *buffer, const char *str); 168 size_t cxBufferPutString(CxBuffer *buffer, AnyStr str);
169 169
170 int cxBufferTerminate(CxBuffer *buffer); 170 int cxBufferTerminate(CxBuffer *buffer);
171 171
172 size_t cxBufferAppend(const void *ptr, size_t size, size_t nitems, 172 size_t cxBufferAppend(const void *ptr, size_t size, size_t nitems,
173 CxBuffer *buffer); 173 CxBuffer *buffer);
174
175 size_t cxBufferAppendString(CxBuffer *buffer, AnyStr str);
174 ``` 176 ```
175 177
176 The primary function for writing to a buffer is `cxBufferWrite()` 178 The primary function for writing to a buffer is `cxBufferWrite()`
177 which writes up to `nitems` with `size` bytes each from the memory pointed to by `ptr` to the buffer. 179 which writes up to `nitems` with `size` bytes each from the memory pointed to by `ptr` to the buffer.
178 180
187 The function `cxBufferPut()` is a `putc()`-like wrapper for `cxBufferWrite()` which writes the character `c`, 189 The function `cxBufferPut()` is a `putc()`-like wrapper for `cxBufferWrite()` which writes the character `c`,
188 converted to an `unsigned char` to the buffer. 190 converted to an `unsigned char` to the buffer.
189 Just like `putc()` this function returns the written character on success, and `EOF` on failure, 191 Just like `putc()` this function returns the written character on success, and `EOF` on failure,
190 but it does _not_ set `errno` on failure. 192 but it does _not_ set `errno` on failure.
191 193
192 The function `cxBufferPutString()` is a convenience function, 194 The function `cxBufferPutString()` is a convenience function that uses `cx_strcast()` to convert any supported string type to a `cxstring` and then invokes `cxBufferWrite()`.
193 that uses stdlib `strlen()` to compute the length of `str` and then invokes `cxBufferWrite()`. 195 Similarly, `cxBufferAppendString()` performs the same operation with `cxBufferAppend()`.
194 196
195 All the above functions advance the buffer position by the number of bytes written 197 All the above functions advance the buffer position by the number of bytes written
196 and cause the _size_ of the buffer to grow, if necessary, to contain all written bytes. 198 and cause the _size_ of the buffer to grow, if necessary, to contain all written bytes.
197 On the other hand, `cxBufferTerminate()` writes a zero-byte at the current position and shrinks the buffer, 199 On the other hand, `cxBufferTerminate()` writes a zero-byte at the current position and shrinks the buffer,
198 effectively creating a zero-terminated string whose size equals the buffer size. 200 effectively creating a zero-terminated string whose size equals the buffer size.

mercurial