1 /* Qt plural format strings.
2 Copyright (C) 2003-2004, 2006-2007, 2009, 2015 Free Software
4 Written by Bruno Haible <bruno@clisp.org>, 2009.
6 This program is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
30 #define _(str) gettext (str)
32 /* Qt plural format strings are processed by QObject::tr and are documented in
33 qt-x11-opensource-src-4.3.1/doc/html/qobject.html#tr.
36 - is optionally followed by 'L' (a no-op),
38 Every directive is replaced by the numeric argument N passed to QObject::tr.
43 /* Number of format directives. */
44 unsigned int directives;
49 format_parse (const char *format, bool translated, char *fdi,
50 char **invalid_reason)
52 const char *const format_start = format;
58 for (; *format != '\0';)
61 const char *dir_start = format - 1;
68 FDI_SET (dir_start, FMTDIR_START);
70 FDI_SET (format, FMTDIR_END);
76 result = XMALLOC (struct spec);
82 format_free (void *descr)
84 struct spec *spec = (struct spec *) descr;
90 format_get_number_of_directives (void *descr)
92 struct spec *spec = (struct spec *) descr;
94 return spec->directives;
98 format_check (void *msgid_descr, void *msgstr_descr, bool equality,
99 formatstring_error_logger_t error_logger,
100 const char *pretty_msgid, const char *pretty_msgstr)
102 struct spec *spec1 = (struct spec *) msgid_descr;
103 struct spec *spec2 = (struct spec *) msgstr_descr;
106 /* Check the argument is used. */
107 if ((spec1->directives == 0 && spec2->directives > 0)
108 || (equality && spec1->directives > 0 && spec2->directives == 0))
111 error_logger (_("number of format specifications in '%s' and '%s' does not match"),
112 pretty_msgid, pretty_msgstr);
120 struct formatstring_parser formatstring_qt_plural =
124 format_get_number_of_directives,
132 /* Test program: Print the argument list specification returned by
133 format_parse for strings read from standard input. */
138 format_print (void *descr)
140 struct spec *spec = (struct spec *) descr;
149 if (spec->directives > 0)
162 size_t line_size = 0;
164 char *invalid_reason;
167 line_len = getline (&line, &line_size, stdin);
170 if (line_len > 0 && line[line_len - 1] == '\n')
171 line[--line_len] = '\0';
173 invalid_reason = NULL;
174 descr = format_parse (line, false, NULL, &invalid_reason);
176 format_print (descr);
179 printf ("%s\n", invalid_reason);
181 free (invalid_reason);
189 * For Emacs M-x compile
191 * compile-command: "/bin/sh ../libtool --tag=CC --mode=link gcc -o a.out -static -O -g -Wall -I.. -I../gnulib-lib -I../intl -DHAVE_CONFIG_H -DTEST format-qt-plural.c ../gnulib-lib/libgettextlib.la"