struct spec
{
unsigned int directives;
+ /* We consider a directive as "likely intentional" if it does not contain a
+ space. This prevents xgettext from flagging strings like "100% complete"
+ as 'boost-format' if they don't occur in a context that requires a format
+ string. */
+ unsigned int likely_intentional_directives;
unsigned int numbered_arg_count;
struct numbered_arg *numbered;
};
struct spec *result;
spec.directives = 0;
+ spec.likely_intentional_directives = 0;
spec.numbered_arg_count = 0;
spec.numbered = NULL;
numbered_allocated = 0;
if (*format++ == '%')
{
/* A directive. */
+ bool likely_intentional = true;
+
FDI_SET (format - 1, FMTDIR_START);
spec.directives++;
|| *format == '#' || *format == '0' || *format == '\''
|| *format == '_' || *format == '=' || *format == 'h'
|| *format == 'l')
- format++;
+ {
+ if (*format == ' ')
+ likely_intentional = false;
+ format++;
+ }
else
break;
}
}
}
+ if (likely_intentional)
+ spec.likely_intentional_directives++;
FDI_SET (format - 1, FMTDIR_END);
}
return spec->directives;
}
+static bool
+format_is_unlikely_intentional (void *descr)
+{
+ struct spec *spec = (struct spec *) descr;
+
+ return spec->likely_intentional_directives == 0;
+}
+
static bool
format_check (void *msgid_descr, void *msgstr_descr, bool equality,
formatstring_error_logger_t error_logger, void *error_logger_data,
format_parse,
format_free,
format_get_number_of_directives,
- NULL,
+ format_is_unlikely_intentional,
format_check
};
xgettext-ycp-stackovfl-1 xgettext-ycp-stackovfl-2 \
xgettext-ycp-stackovfl-3 xgettext-ycp-stackovfl-4 \
format-awk-1 format-awk-2 format-awk-3 \
- format-boost-1 format-boost-2 \
+ format-boost-1 format-boost-2 format-boost-3 \
format-c-1 format-c-2 format-c-3 format-c-4 format-c-5 format-c-6 \
format-c++-brace-1 format-c++-brace-2 \
format-csharp-1 format-csharp-2 \
--- /dev/null
+#! /bin/sh
+. "${srcdir=.}/init.sh"; path_prepend_ . ../src
+
+# Test heuristic recognition of Boost format strings like "100% complete".
+
+cat <<\EOF > f-bo-3.cc
+gettext("Test 1a is 100% complete");
+format(gettext("Test 1b is 100% complete"), 120);
+gettext("Test 2a from 0% complete to 100% complete");
+format(gettext("Test 2b from 0% complete to 100% complete"), 120, 121);
+gettext("Test 3a of %s is 100% complete");
+format(gettext("Test 3b of %s is 100% complete"), "foo", 120);
+EOF
+
+: ${XGETTEXT=xgettext}
+${XGETTEXT} --boost --omit-header --no-location -d f-bo-3.tmp f-bo-3.cc || Exit 1
+LC_ALL=C tr -d '\r' < f-bo-3.tmp.po > f-bo-3.po || Exit 1
+
+cat <<\EOF > f-bo-3.ok
+msgid "Test 1a is 100% complete"
+msgstr ""
+
+#, boost-format
+msgid "Test 1b is 100% complete"
+msgstr ""
+
+msgid "Test 2a from 0% complete to 100% complete"
+msgstr ""
+
+#, boost-format
+msgid "Test 2b from 0% complete to 100% complete"
+msgstr ""
+
+#, c-format, boost-format
+msgid "Test 3a of %s is 100% complete"
+msgstr ""
+
+#, boost-format
+msgid "Test 3b of %s is 100% complete"
+msgstr ""
+EOF
+
+: ${DIFF=diff}
+${DIFF} f-bo-3.ok f-bo-3.po
+result=$?
+
+exit $result