Description
This RFC proposes adding support for non-standard specifiers for string formatting. Currently, @stdlib/string/format supports the standard printf specifiers as found in C. Would be convenient to be able to support additional serialization formats, such as
- complex numbers (
Complex128 and Complex64 with precision and exponential notation formatting).
- JSON
- generic objects
- times
- percentages
Based on the current list of supported specifiers, the following could be potential extensions (although, we'd want to confirm that none of these are already present in common (non-standard) printf implementations):
Complex128: Z
Complex64: z
JSON: J
object: O (capital o)
times: D or T
percentage: p
The tricky extension would be times, as would be nice to support something like YYYY-MM-DD HH:MM:SS, but not clear how this would be done, as this extends far beyond the relative complexity of printf specifier modifiers. Perhaps better would be to have a dedicated time formatter similar to C's strptime and strftime.
My recommendation is that support for non-standard specifiers be included as a package separate from @stdlib/string/format which, IMO, should remain a high fidelity analog of C's printf. Such a package can reuse @stdlib/string/base/format-tokenize, but implement/extend @stdlib/string/base/format-interpolate. The name of this extended package is TBD.
Related Issues
None.
Questions
No.
Other
Prior art:
Checklist
Description
This RFC proposes adding support for non-standard specifiers for string formatting. Currently,
@stdlib/string/formatsupports the standardprintfspecifiers as found in C. Would be convenient to be able to support additional serialization formats, such asComplex128andComplex64with precision and exponential notation formatting).Based on the current list of supported specifiers, the following could be potential extensions (although, we'd want to confirm that none of these are already present in common (non-standard)
printfimplementations):Complex128:ZComplex64:zJSON:Jobject:O(capital o)times:DorTpercentage:pThe tricky extension would be times, as would be nice to support something like
YYYY-MM-DD HH:MM:SS, but not clear how this would be done, as this extends far beyond the relative complexity ofprintfspecifier modifiers. Perhaps better would be to have a dedicated time formatter similar to C'sstrptimeandstrftime.My recommendation is that support for non-standard specifiers be included as a package separate from
@stdlib/string/formatwhich, IMO, should remain a high fidelity analog of C'sprintf. Such a package can reuse@stdlib/string/base/format-tokenize, but implement/extend@stdlib/string/base/format-interpolate. The name of this extended package is TBD.Related Issues
None.
Questions
No.
Other
Prior art:
Checklist
RFC:.