| 5081 | } |
| 5082 | |
| 5083 | static void |
| 5084 | xo_format_units (xo_handle_t *xop, xo_field_info_t *xfip, |
| 5085 | const char *value, ssize_t vlen) |
| 5086 | { |
| 5087 | const char *fmt = xfip->xfi_format; |
| 5088 | ssize_t flen = xfip->xfi_flen; |
| 5089 | xo_xff_flags_t flags = xfip->xfi_flags; |
| 5090 | |
| 5091 | static char units_start_xml[] = " units=\""; |
| 5092 | static char units_start_html[] = " data-units=\""; |
| 5093 | |
| 5094 | if (!XOIF_ISSET(xop, XOIF_UNITS_PENDING)) { |
| 5095 | xo_format_content(xop, "units", NULL, value, vlen, fmt, flen, flags); |
| 5096 | return; |
| 5097 | } |
| 5098 | |
| 5099 | xo_buffer_t *xbp = &xop->xo_data; |
| 5100 | ssize_t start = xop->xo_units_offset; |
| 5101 | ssize_t stop = xbp->xb_curp - xbp->xb_bufp; |
| 5102 | |
| 5103 | if (xo_style(xop) == XO_STYLE_XML) |
| 5104 | xo_buf_append(xbp, units_start_xml, sizeof(units_start_xml) - 1); |
| 5105 | else if (xo_style(xop) == XO_STYLE_HTML) |
| 5106 | xo_buf_append(xbp, units_start_html, sizeof(units_start_html) - 1); |
| 5107 | else |
| 5108 | return; |
| 5109 | |
| 5110 | if (vlen) |
| 5111 | xo_data_escape(xop, value, vlen); |
| 5112 | else |
| 5113 | xo_do_format_field(xop, NULL, fmt, flen, flags); |
| 5114 | |
| 5115 | xo_buf_append(xbp, "\"", 1); |
| 5116 | |
| 5117 | ssize_t now = xbp->xb_curp - xbp->xb_bufp; |
| 5118 | ssize_t delta = now - stop; |
| 5119 | if (delta <= 0) { /* Strange; no output to move */ |
| 5120 | xbp->xb_curp = xbp->xb_bufp + stop; /* Reset buffer to prior state */ |
| 5121 | return; |
| 5122 | } |
| 5123 | |
| 5124 | /* |
| 5125 | * Now we're in it alright. We've need to insert the unit value |
| 5126 | * we just created into the right spot. We make a local copy, |
| 5127 | * move it and then insert our copy. We know there's room in the |
| 5128 | * buffer, since we're just moving this around. |
| 5129 | */ |
| 5130 | char *buf = alloca(delta); |
| 5131 | |
| 5132 | memcpy(buf, xbp->xb_bufp + stop, delta); |
| 5133 | memmove(xbp->xb_bufp + start + delta, xbp->xb_bufp + start, stop - start); |
| 5134 | memmove(xbp->xb_bufp + start, buf, delta); |
| 5135 | } |
| 5136 | |
| 5137 | static ssize_t |
| 5138 | xo_find_width (xo_handle_t *xop, xo_field_info_t *xfip, |
no test coverage detected