MCPcopy Create free account
hub / github.com/F-Stack/f-stack / xo_gettext_simplify_format

Function xo_gettext_simplify_format

tools/libxo/libxo/libxo.c:5892–5958  ·  view source on GitHub ↗

* We are passed a pointer to a format string just past the "{G:}" * field. We build a simplified version of the format string. */

Source from the content-addressed store, hash-verified

5890 * field. We build a simplified version of the format string.
5891 */
5892static int
5893xo_gettext_simplify_format (xo_handle_t *xop UNUSED,
5894 xo_buffer_t *xbp,
5895 xo_field_info_t *fields,
5896 int this_field,
5897 const char *fmt UNUSED,
5898 xo_simplify_field_func_t field_cb)
5899{
5900 unsigned ftype;
5901 xo_xff_flags_t flags;
5902 int field = this_field + 1;
5903 xo_field_info_t *xfip;
5904 char ch;
5905
5906 for (xfip = &fields[field]; xfip->xfi_ftype; xfip++, field++) {
5907 ftype = xfip->xfi_ftype;
5908 flags = xfip->xfi_flags;
5909
5910 if ((flags & XFF_GT_FIELD) && xfip->xfi_content && ftype != 'V') {
5911 if (field_cb)
5912 field_cb(xfip->xfi_content, xfip->xfi_clen,
5913 (flags & XFF_GT_PLURAL) ? 1 : 0);
5914 }
5915
5916 switch (ftype) {
5917 case 'G':
5918 /* Ignore gettext roles */
5919 break;
5920
5921 case XO_ROLE_NEWLINE:
5922 xo_buf_append(xbp, "\n", 1);
5923 break;
5924
5925 case XO_ROLE_EBRACE:
5926 xo_buf_append(xbp, "{", 1);
5927 xo_buf_append(xbp, xfip->xfi_content, xfip->xfi_clen);
5928 xo_buf_append(xbp, "}", 1);
5929 break;
5930
5931 case XO_ROLE_TEXT:
5932 xo_buf_append(xbp, xfip->xfi_content, xfip->xfi_clen);
5933 break;
5934
5935 default:
5936 xo_buf_append(xbp, "{", 1);
5937 if (ftype != 'V') {
5938 ch = ftype;
5939 xo_buf_append(xbp, &ch, 1);
5940 }
5941
5942 unsigned fnum = xfip->xfi_fnum ?: 0;
5943 if (fnum) {
5944 char num[12];
5945 /* Field numbers are origin 1, not 0, following printf(3) */
5946 snprintf(num, sizeof(num), "%u", fnum);
5947 xo_buf_append(xbp, num, strlen(num));
5948 }
5949

Callers 2

xo_gettext_build_formatFunction · 0.85
xo_simplify_formatFunction · 0.85

Calls 2

xo_buf_appendFunction · 0.85
snprintfFunction · 0.85

Tested by

no test coverage detected