Skip to content

Commit

Permalink
Don't panic on percent signs.
Browse files Browse the repository at this point in the history
  • Loading branch information
veelo committed Aug 1, 2022
1 parent f28e3d7 commit 1861c75
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
4 changes: 4 additions & 0 deletions runtests.d
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ int main()
if (result != 0)
return result;

result = runCommand(["dub", "test", "--config=xgettext"]);
if (result != 0)
return result;

foreach (test; dirEntries("tests", SpanMode.shallow))
{
if (!test.isDir)
Expand Down
4 changes: 3 additions & 1 deletion source/gettext.d
Original file line number Diff line number Diff line change
Expand Up @@ -286,16 +286,18 @@ version (xgettext) // String extraction mode.
private bool hasFormatSpecifiers(string fmt) pure @safe
{
import std.format : FormatSpec;
import std.exception : ifThrown;

static void ns(const(char)[] arr) {} // the simplest output range
auto nullSink = &ns;
return FormatSpec!char(fmt).writeUpToNextSpec(nullSink);
return FormatSpec!char(fmt).writeUpToNextSpec(nullSink).ifThrown!FormatException(false);
}
unittest
{
assert ("On %2$s I eat %3$s and walk for %1$d hours.".hasFormatSpecifiers);
assert ("On %%2$s I eat %%3$s and walk for %1$d hours.".hasFormatSpecifiers);
assert (!"On %%2$s I eat %%3$s and walk for hours.".hasFormatSpecifiers);
assert (!"98%".hasFormatSpecifiers);
}
}
else // Translation mode.
Expand Down

0 comments on commit 1861c75

Please sign in to comment.