64 } |
64 } |
65 |
65 |
66 return result; |
66 return result; |
67 } |
67 } |
68 |
68 |
69 sstr_t dav_format_string(UcxAllocator *a, sstr_t fstr, va_list *ap, davqlerror_t *error) { |
69 sstr_t dav_format_string(UcxAllocator *a, sstr_t fstr, dav_valist ap, davqlerror_t *error) { |
70 UcxBuffer *buf = ucx_buffer_new(NULL, 128, UCX_BUFFER_AUTOEXTEND); |
70 UcxBuffer *buf = ucx_buffer_new(NULL, 128, UCX_BUFFER_AUTOEXTEND); |
71 |
71 |
72 int placeholder = 0; |
72 int placeholder = 0; |
73 for(int i=0;i<fstr.length;i++) { |
73 for(int i=0;i<fstr.length;i++) { |
74 char c = fstr.ptr[i]; |
74 char c = fstr.ptr[i]; |
79 } else { |
79 } else { |
80 // detect placeholder type and insert arg |
80 // detect placeholder type and insert arg |
81 int err = 0; |
81 int err = 0; |
82 switch(c) { |
82 switch(c) { |
83 case 's': { |
83 case 's': { |
84 char *arg = va_arg(*ap, char*); |
84 char *arg = dav_vaarg(ap, char*); |
85 ucx_buffer_puts(buf, arg); |
85 ucx_buffer_puts(buf, arg); |
86 break; |
86 break; |
87 } |
87 } |
88 case 'd': { |
88 case 'd': { |
89 int arg = va_arg(*ap, int); |
89 int arg = dav_vaarg(ap, int); |
90 ucx_bprintf(buf, "%d", arg); |
90 ucx_bprintf(buf, "%d", arg); |
91 break; |
91 break; |
92 } |
92 } |
93 case 'u': { |
93 case 'u': { |
94 unsigned int arg = va_arg(*ap, unsigned int); |
94 unsigned int arg = dav_vaarg(ap, unsigned int); |
95 ucx_bprintf(buf, "%u", arg); |
95 ucx_bprintf(buf, "%u", arg); |
96 break; |
96 break; |
97 } |
97 } |
98 case 't': { |
98 case 't': { |
99 // time arguments not supported for strings |
99 // time arguments not supported for strings |
638 |
638 |
639 break; |
639 break; |
640 } |
640 } |
641 case DAVQL_STRING: { |
641 case DAVQL_STRING: { |
642 cmd.type = DAVQL_CMD_STRING; |
642 cmd.type = DAVQL_CMD_STRING; |
643 cmd.data.string = dav_format_string(a, src, &ap, &error); |
643 cmd.data.string = dav_fmt_str(a, src, ap, &error); |
644 ucx_buffer_write(&cmd, sizeof(cmd), 1, bcode); |
644 ucx_buffer_write(&cmd, sizeof(cmd), 1, bcode); |
645 break; |
645 break; |
646 } |
646 } |
647 case DAVQL_TIMESTAMP: { |
647 case DAVQL_TIMESTAMP: { |
648 if(src.ptr[0] == '%') { |
648 if(src.ptr[0] == '%') { |