* POSSIBILITY OF SUCH DAMAGE.
*/
-#include "ucx/properties.h"
+#include "properties.h"
#include <stdio.h>
#include <stdlib.h>
parser->tmplen += len;
}
-int ucx_properties_next(UcxProperties *parser, sstr_t *name, sstr_t *value) {
+int ucx_properties_next(UcxProperties *parser, cxstring *name, cxstring *value) {
if(parser->tmplen > 0) {
char *buf = parser->buffer + parser->pos;
size_t len = parser->buflen - parser->pos;
- sstr_t str = sstrn(buf, len);
- sstr_t nl = sstrchr(str, '\n');
+ cxstring str = cx_strn(buf, len);
+ cxstring nl = cx_strchr(str, '\n');
if(nl.ptr) {
size_t newlen = (size_t)(nl.ptr - buf) + 1;
parser_tmp_append(parser, buf, newlen);
return 0;
}
- sstr_t line = has_comment ? sstrn(buf, comment_index) : sstrn(buf, i);
+ cxstring line = has_comment ? cx_strn(buf, comment_index) : cx_strn(buf, i);
// check line
if(delimiter_index == 0) {
- line = sstrtrim(line);
+ line = cx_strtrim(line);
if(line.length != 0) {
parser->error = 1;
}
} else {
- sstr_t n = sstrn(buf, delimiter_index);
- sstr_t v = sstrn(
+ cxstring n = cx_strn(buf, delimiter_index);
+ cxstring v = cx_strn(
buf + delimiter_index + 1,
line.length - delimiter_index - 1);
- n = sstrtrim(n);
- v = sstrtrim(v);
+ n = cx_strtrim(n);
+ v = cx_strtrim(v);
if(n.length != 0 || v.length != 0) {
*name = n;
*value = v;
return 0;
}
-int ucx_properties2map(UcxProperties *parser, UcxMap *map) {
- sstr_t name;
- sstr_t value;
+int ucx_properties2map(UcxProperties *parser, CxMap *map) {
+ cxstring name;
+ cxstring value;
while(ucx_properties_next(parser, &name, &value)) {
- value = sstrdup_a(map->allocator, value);
- if(!value.ptr) {
+ cxmutstr mutvalue = cx_strdup_a(map->allocator, value);
+ if(!mutvalue.ptr) {
return 1;
}
- if(ucx_map_sstr_put(map, name, value.ptr)) {
- alfree(map->allocator, value.ptr);
+ if(cxMapPut(map, cx_hash_key_cxstr(name), mutvalue.ptr)) {
+ cxFree(map->allocator, mutvalue.ptr);
return 1;
}
}
// buffer size is documented - change doc, when you change bufsize!
#define UCX_PROPLOAD_BUFSIZE 1024
-int ucx_properties_load(UcxMap *map, FILE *file) {
+int ucx_properties_load(CxMap *map, FILE *file) {
UcxProperties *parser = ucx_properties_new();
if(!(parser && map && file)) {
return 1;
return error;
}
-int ucx_properties_store(UcxMap *map, FILE *file) {
- UcxMapIterator iter = ucx_map_iterator(map);
- void *v;
- sstr_t value;
+int ucx_properties_store(CxMap *map, FILE *file) {
+ CxIterator iter = cxMapIterator(map);
+ cxstring value;
size_t written;
- UCX_MAP_FOREACH(k, v, iter) {
- value = sstr((char*)v);
+ cx_foreach(CxMapEntry *, v, iter) {
+ value = cx_str(v->value);
written = 0;
- written += fwrite(k.data, 1, k.len, file);
+ written += fwrite(v->key->data.bytes, 1, v->key->len, file);
written += fwrite(" = ", 1, 3, file);
written += fwrite(value.ptr, 1, value.length, file);
written += fwrite("\n", 1, 1, file);
- if (written != k.len + value.length + 4) {
+ if (written != v->key->len + value.length + 4) {
return 1;
}
}