LemonBoy
3da6b1218a
std: Implement named arguments & runtime width/precision
2020-11-20 08:36:47 +01:00
LemonBoy
6b39167fdc
std: Rewrite the fmt parser
...
Turn the FSM parser into a linear one so that's easier to implement new
features and/or more error checking without adding more and more states.
Functionally-speaking the two parsers are at feature parity.
2020-11-20 08:36:10 +01:00
Andrew Kelley
473cb1fd74
Merge pull request #6390 from LemonBoy/reboot-3970
...
std.fmt meets UTF-8
2020-11-19 14:58:11 -08:00
LemonBoy
60638f0c82
Nicer code for the error code path
2020-11-19 18:16:23 +01:00
Tadeo Kondrak
25ec2dbc1e
Add builtin.Signedness, use it instead of is_signed
2020-11-19 18:59:21 +02:00
LemonBoy
3a1f515e09
Address review comments
2020-11-05 16:10:34 +01:00
LemonBoy
1982e0c18a
Fix typo in documentation
2020-11-05 16:10:34 +01:00
LemonBoy
0316ac959c
Make std.formatBuf UTF-8 aware
2020-11-05 16:10:34 +01:00
LemonBoy
675de8d6b7
Clean up the unicode codepoint formatter a bit
2020-11-05 16:10:34 +01:00
LemonBoy
2cce23062b
Update the API and add add error-recovery path
2020-11-05 16:10:33 +01:00
data-man
678ecc94ca
Add 'u' specifier to std.format
2020-11-05 16:10:33 +01:00
LemonBoy
35a8d90e55
std: Make parseInt/parseUnsigned detect the radix
2020-11-02 14:13:06 -05:00
Isaac Freund
50ba018223
std/ascii: add spaces array
...
This may be combined with std.mem.trim to form a proper replacement for
the now deprecated std.fmt.trimWhitespace().
2020-11-02 13:20:58 -05:00
Andrew Kelley
af60931a48
Merge pull request #6888 from jcmoyer/issues/6874
...
Update std.fmt docs and add test for null terminated slices with embedded null bytes
2020-11-01 18:30:09 -05:00
Jakub Konka
d530e7f9c7
Make std.fmt.bufPrintIntToSlice public
...
Deprecate `std.fmt.trim` and `std.fmt.isWhiteSpace` in favour of
`std.mem` alternatives.
Signed-off-by: Jakub Konka <kubkon@jakubkonka.com>
2020-11-01 15:48:50 -05:00
J.C. Moyer
788900c35c
Add test for null terminated slices with embedded null bytes
2020-10-30 23:58:23 -04:00
J.C. Moyer
b38dea37c7
Update doc comments to reflect current behavior
2020-10-30 23:58:23 -04:00
data-man
194e29adfc
Format null type in std.fmt
2020-10-26 15:40:48 -04:00
Andrew Kelley
e51bc19e4a
Merge pull request #6394 from Vexu/fmt
...
std.fmt add specifier for printing Zig identifiers
2020-10-17 21:06:54 -04:00
Vexu
e8ca1b254d
std: remove renderStringLiteral in favor of std.fmt specifier
2020-10-17 23:20:38 +03:00
Jan Prudil
aadccc4206
Make std.meta.Int accept a signedness parameter
2020-10-17 14:09:59 +02:00
Vexu
8d38a91ca8
std.fmt: add specifier for Zig identifiers
2020-10-17 10:26:59 +03:00
Isaac Freund
d52035f401
std/fmt: add bufPrintZ()
2020-10-15 12:21:19 +02:00
Isaac Freund
b259696cfb
std/fmt: rename allocPrint0() to allocPrintZ()
...
This is consistent with other standard library functions working with
null terminated pointers/slices.
2020-10-15 12:21:14 +02:00
Rocknest
548fd6e87b
force comptime on comptimePrint
2020-10-14 01:03:01 -04:00
Tadeo Kondrak
e9bca9de3c
std.fmt.comptimePrint: Properly null-terminate result and add test
2020-10-07 11:43:23 -06:00
Tadeo Kondrak
49e68bdcf3
std.fmt.comptimePrint: Return null terminated string
2020-10-06 22:21:06 -06:00
Alexandros Naskos
a4fe438d39
std.fmt.comptimePrint: bufPrint cannot return an error
2020-10-02 00:39:19 +03:00
Tadeo Kondrak
236af776fd
std.fmt: add comptimePrint
2020-09-25 12:53:35 -06:00
LemonBoy
27adb82fda
std: Respect user-specified alignment when formatting ints
...
This implementation tries to do the right thing (TM) by treating the
sign as part of the number itself, therefore the alignment parameter
applies to both the sign and the digits.
In other words the format string `{:>4}` with -1 as input will not
output `- 1` but ` -1`.
And let's default to right alignment for everything as that's what users
want, especially when printing numbers. Many implementations use
different defaults for numeric vs non-numeric types, let's strive for a
consistent behaviour here.
2020-09-17 00:53:08 +02:00
LemonBoy
bb9a4ad6e9
std: Fix {*} printing of non-pointer types
...
Fixes a regression introduced in #6246 .
Adds a test to make sure this won't happen again.
2020-09-16 13:45:54 +02:00
Tadeo Kondrak
771f35c593
Use less inefficient method of replacing TypeInfo.UnionField.enum_field
2020-09-07 06:23:27 -06:00
Tadeo Kondrak
ac19ccf595
Update standard library for removal of TypeInfo.UnionField.enum_field
2020-09-07 06:23:26 -06:00
Veikka Tuominen
41bbadbb9a
Merge pull request #6246 from Vexu/field
...
Remove deprecated fields on `type`
2020-09-05 13:58:02 +03:00
yettinmoor
0c43b6ef5c
document how to escape curly braces in fmt.format
2020-09-04 22:11:09 +03:00
Vexu
1df0f3ac24
update uses of deprecated type field access
2020-09-03 18:10:40 +03:00
daurnimator
fb3c5b84ed
std: add fmt option to escape non-printable characters
2020-09-02 19:18:36 -04:00
Andrew Kelley
4a69b11e74
add license header to all std lib files
...
add SPDX license identifier
copyright ownership is zig contributors
2020-08-20 16:07:04 -04:00
Felix Queißner
6701046cdd
Uses getWritten instead of .pos + slicing
...
Co-authored-by: Joachim Schmidt <joachim.schmidt557@outlook.com>
2020-08-09 17:40:58 +02:00
Felix (xq) Queißner
ada06e2996
Makes formatFloatValue not return error.NoSpaceLeft anymore.
2020-08-09 14:09:02 +02:00
Felix (xq) Queißner
06a1184c92
Fixes double alignment
2020-08-09 12:48:26 +02:00
Andrew Kelley
a2bb246db4
Revert "std.fmt.format: small optimization to avoid runtime bloat"
...
This reverts commit 11d38a7e52
.
The benefits of this commit are not enough to justify the compromise
that it made.
closes #5977
2020-08-05 13:30:43 -07:00
Andrew Kelley
11d38a7e52
std.fmt.format: small optimization to avoid runtime bloat
...
When there are no format parameters, it simply calls `writeAll`. This
has the effect of no longer emitting a compile error for using `{}` and
not having any parameters, however, at this point in the development
process of Zig I think that tradeoff is worthwhile.
On the other hand, it might be OK to simply define formatting to work
this way. It's a common pattern to use the formatting function's format
string `"like this", .{}` instead of `"{}", .{"like this"}`, which can
lead to accidentally putting control characters in the formatting
string, however, with this change that works just fine.
2020-07-29 02:29:36 -07:00
~nue
03f14c3102
Added octal formatting fo `fmt` functions. ( #5867 )
...
* Added octal formatting (specifier "o") to `formatIntValue` function.
* Added octal specifier test case in `fmt.zig` (under the "int.specifier" case)
2020-07-14 02:27:58 -04:00
Vexu
be1507a7af
update compile error tests and some doc comments
2020-07-12 00:54:07 +03:00
Vexu
e85fe13e44
run zig fmt on std lib and self hosted
2020-07-11 20:41:19 +03:00
Alluet
a0a93f2091
Rewrite std.fmt.parseInt
2020-07-05 22:56:06 +00:00
Jonathan Marler
27c1e0b453
Fix issue 5757: increase branch quota for formatting enums
2020-07-05 22:27:50 +00:00
data-man
5229f6ec68
Use writer in std.fmt
2020-06-20 18:23:57 +00:00
Alexandros Naskos
1bc92b1fde
Fix formatting of floating point values with the B and Bi specifiers
2020-06-12 13:38:12 -04:00