All,

A few weeks back I landed
<http://bugzilla.mozilla.org/show_bug.cgi?id=1717448> a patches series to
be able to format strings using the well known {fmt}
<https://github.com/fmtlib/fmt> library, that allows formatting strings in
a way that is much more modern and as fast or faster (according to the
developer) that our current facilities, be it printf-style format string or
iostreams.

The documentation is at
https://firefox-source-docs.mozilla.org/xpcom/fmt-in-gecko.html. As noted,
integration with our beloved nsString is supported (both wide and narrow).
MOZ_LOG also got taught {fmt} format string, and the API to work directly
with character buffers is otherwise available. Until we compile with a more
modern C++ version, we'll have to wrap the format string in the FMT_STRING
(..) macro, to get static checks like printf. Compilation will fail with a
clear message if the format string has an error, or if this macro is
missing, allowing developers to catch errors early.

In a few words, the format syntax goes like this:
- 99% of the time, just write {} when you want to print a variable, like in
rust or python, no PRId64 or whatever, it will do the right thing. This is
especially nice if you define custom formatters for classes, it makes for
compact code. This open opportunity for nice logging in heavily
metaprogrammed code, since all types are infered.
- format specifiers are intentionally very similar to printf,
https://searchfox.org/mozilla-central/source/mozglue/tests/gtest/TestFmt.cpp#24-45
serves as a very easy guide to convert from one to the other.

Thanks to glandium and nika for the reviews, and again to nika for
providing an old patch for the nsString integration, that is certainly much
better than the thing I had written initially.

I'm happy to take any request for features (profiler markers formatting is
planed already), it's likely fast to implement.

Best,
Paul.

-- 
You received this message because you are subscribed to the Google Groups 
"[email protected]" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/a/mozilla.org/d/msgid/dev-platform/CANWt0WpG4mvHCkeX8LDBnCQDsRV9b1yBQYgYUfLn4mbZ3VYPYw%40mail.gmail.com.

Reply via email to