ucx/properties.c

changeset 31
287484519844
parent 30
d33eaaec15da
equal deleted inserted replaced
30:d33eaaec15da 31:287484519844
66 size_t len 66 size_t len
67 ) { 67 ) {
68 if (cxBufferEof(&prop->input)) { 68 if (cxBufferEof(&prop->input)) {
69 // destroy a possible previously initialized buffer 69 // destroy a possible previously initialized buffer
70 cxBufferDestroy(&prop->input); 70 cxBufferDestroy(&prop->input);
71 cxBufferInit(&prop->input, (void*) buf, len, 71 cxBufferInit(&prop->input, NULL, (void*) buf,
72 NULL, CX_BUFFER_COPY_ON_WRITE | CX_BUFFER_AUTO_EXTEND); 72 len, CX_BUFFER_COPY_ON_WRITE | CX_BUFFER_AUTO_EXTEND);
73 prop->input.size = len; 73 prop->input.size = len;
74 } else { 74 } else {
75 if (cxBufferAppend(buf, 1, len, &prop->input) < len) return -1; 75 if (cxBufferAppend(buf, 1, len, &prop->input) < len) return -1;
76 } 76 }
77 return 0; 77 return 0;
80 void cxPropertiesUseStack( 80 void cxPropertiesUseStack(
81 CxProperties *prop, 81 CxProperties *prop,
82 char *buf, 82 char *buf,
83 size_t capacity 83 size_t capacity
84 ) { 84 ) {
85 cxBufferInit(&prop->buffer, buf, capacity, NULL, CX_BUFFER_COPY_ON_EXTEND); 85 cxBufferInit(&prop->buffer, NULL, buf, capacity, CX_BUFFER_COPY_ON_EXTEND);
86 } 86 }
87 87
88 CxPropertiesStatus cxPropertiesNext( 88 CxPropertiesStatus cxPropertiesNext(
89 CxProperties *prop, 89 CxProperties *prop,
90 cxstring *key, 90 cxstring *key,
188 assert(current_buffer != &prop->buffer); 188 assert(current_buffer != &prop->buffer);
189 // make sure that the rescue buffer does not already contain something 189 // make sure that the rescue buffer does not already contain something
190 assert(cxBufferEof(&prop->buffer)); 190 assert(cxBufferEof(&prop->buffer));
191 if (prop->buffer.space == NULL) { 191 if (prop->buffer.space == NULL) {
192 // initialize a rescue buffer, if the user did not provide one 192 // initialize a rescue buffer, if the user did not provide one
193 cxBufferInit(&prop->buffer, NULL, 256, NULL, CX_BUFFER_AUTO_EXTEND); 193 cxBufferInit(&prop->buffer, NULL, NULL, 256, CX_BUFFER_AUTO_EXTEND);
194 } else { 194 } else {
195 // from a previous rescue there might be already read data 195 // from a previous rescue there might be already read data
196 // reset the buffer to avoid unnecessary buffer extension 196 // reset the buffer to avoid unnecessary buffer extension
197 cxBufferReset(&prop->buffer); 197 cxBufferReset(&prop->buffer);
198 } 198 }
249 if (has_continuation) { 249 if (has_continuation) {
250 char *ptr = (char*)val.ptr; 250 char *ptr = (char*)val.ptr;
251 if (current_buffer != &prop->buffer) { 251 if (current_buffer != &prop->buffer) {
252 // move value to the rescue buffer 252 // move value to the rescue buffer
253 if (prop->buffer.space == NULL) { 253 if (prop->buffer.space == NULL) {
254 cxBufferInit(&prop->buffer, NULL, 256, NULL, CX_BUFFER_AUTO_EXTEND); 254 cxBufferInit(&prop->buffer, NULL, NULL, 256, CX_BUFFER_AUTO_EXTEND);
255 } 255 }
256 prop->buffer.size = 0; 256 prop->buffer.size = 0;
257 prop->buffer.pos = 0; 257 prop->buffer.pos = 0;
258 if (cxBufferWrite(val.ptr, 1, val.length, &prop->buffer) != val.length) { 258 if (cxBufferWrite(val.ptr, 1, val.length, &prop->buffer) != val.length) {
259 return CX_PROPERTIES_BUFFER_ALLOC_FAILED; 259 return CX_PROPERTIES_BUFFER_ALLOC_FAILED;
310 #ifndef CX_PROPERTIES_LOAD_BUF_SIZE 310 #ifndef CX_PROPERTIES_LOAD_BUF_SIZE
311 #define CX_PROPERTIES_LOAD_BUF_SIZE 256 311 #define CX_PROPERTIES_LOAD_BUF_SIZE 256
312 #endif 312 #endif
313 const unsigned cx_properties_load_buf_size = CX_PROPERTIES_LOAD_BUF_SIZE; 313 const unsigned cx_properties_load_buf_size = CX_PROPERTIES_LOAD_BUF_SIZE;
314 314
315 CxPropertiesStatus cx_properties_load(CxPropertiesConfig config, 315 CxPropertiesStatus cx_properties_load(const CxAllocator *allocator,
316 const CxAllocator *allocator, cxstring filename, CxMap *target) { 316 cxstring filename, CxMap *target, CxPropertiesConfig config) {
317 if (allocator == NULL) { 317 if (allocator == NULL) {
318 allocator = cxDefaultAllocator; 318 allocator = cxDefaultAllocator;
319 } 319 }
320 320
321 // sanity check for the map 321 // sanity check for the map

mercurial