Commit graph

750 commits

Author SHA1 Message Date
Aditya Chincholkar
fd4979ab99
Fix issue #9829 std.conv.parse!(int, string) counts when doCount is false (#10674) 2025-03-17 22:15:40 +08:00
Elias Batek
13279b8594
Add additional tests to std.conv (#10673) 2025-03-15 16:28:45 +08:00
Paul Backus
6722d0a50b
Add std.conv.bitCast (#10651)
* Add std.conv.bitCast

This helper function is a more readable alternative to the traditional
pointer-cast-based syntax for reinterpreting casts.

The name bitCast is used for this operation in several other languages,
including C++ [1], Swift [2], C# [3], Zig [4], and LLVM IR [5].

[1] https://en.cppreference.com/w/cpp/numeric/bit_cast
[2] https://developer.apple.com/documentation/swift/unsafebitcast(_:to:)
[3] https://learn.microsoft.com/en-us/dotnet/api/system.runtime.compilerservices.unsafe.bitcast
[4] https://ziglang.org/documentation/0.10.0/#bitCast
[5] https://llvm.org/docs/LangRef.html#bitcast-to-instruction

* Add changelog entry for std.conv.bitCast
2025-02-28 13:54:10 -08:00
Dennis
600c721875
Fixes for -preview=rvaluerefparam (#9092)
* Update `hasToString` for `-preview=rvaluerefparam`

* Remove ref parameter test of parse()
2024-11-26 22:29:24 -08:00
Elias Batek
9771a247f5 Reference std.digest.fromHexString in doc of std.conv.hexString 2024-11-04 05:15:38 +01:00
Nicholas Wilson
dc4c187b2b
Fix style (#9074) 2024-10-27 19:11:52 +08:00
Nicholas Wilson
81ce86ef67
remove uses of classinfo, rebases part of #7445 (#9063) 2024-10-27 17:27:20 +08:00
Vladiwostok
231ae8b68a
Fix D-Scanner linting issues (#9070)
* Fix UndocumentedDeclarationCheck linting issue

* Fix IfConstraintsIndentCheck linting issue

* Address feedback

* Fix publictests CI

* Fix old (libdparse) D-Scanner linting warn
2024-10-27 01:21:56 -07:00
Walter Bright
a44abe9167 use cast() where we can 2024-03-08 11:57:50 -08:00
Dennis Korpel
2bb54df391 Move floatTraits to std.math.traits 2024-01-09 13:00:50 +01:00
Dennis
b29f127886
Update std/conv.d 2023-12-30 15:22:21 +01:00
Danil Sidoruk
7d012ab076
Replace case (type) num -> type(num) 2023-12-24 20:57:45 +03:00
Danil Sidoruk
db91b6ccbc
Add unittests for ubyte, ushort, byte, short overloads of conv.toChars 2023-12-20 18:06:47 +03:00
Danil Sidoruk
ce1da54631
Fix issue 24075 - Can't use toChars with ushort or ubyte 2023-12-20 18:06:35 +03:00
Feldwor
39712a19bf
Update conv.d: textImpl(): make static if more readable. (#8854)
* Update conv.d: textImpl(): make static if more readable.

Adds newlines at the end of statements in the source code.
2023-11-25 22:54:54 +08:00
Nick Treleaven
9a90edf7a9
[std.conv] Tweak to, parse docs (#8785)
* [std.conv] Tweak docs

Fix formatting of `Integer` grammar.
Minor tweaks.
Use the PANEL macro to introduce the `parse` overloads.
Reorder `parse` constraint expressions to follow parameter order. In
particular, Target should come first.

* Improve `parse` descriptions & continue reordering constraint exps
2023-07-31 13:04:46 +03:00
Dennis
ac7e69151d
Fix 24049 - std.conv.to: string to enum conversion is not documented (#8784)
* Fix 24049 - std.conv.to: string to enum conversion is not documented

* Update std/conv.d

Co-authored-by: Max Haughton <maxhaton@gmail.com>

---------

Co-authored-by: Max Haughton <maxhaton@gmail.com>
2023-07-24 11:21:52 +03:00
Dennis
5cd77a6e32
User hyperlinks to refer to bugzilla issues (#8766) 2023-06-16 14:45:44 +03:00
Walter Bright
4a1210ea1c std.conv integer to string: use core.internal.string 2023-05-20 23:23:26 -07:00
Walter Bright
9eb1f83403 std.conv handle default integer-to-string with core.internal.string 2023-05-08 11:30:48 +02:00
Nick Treleaven
c27f250eb5 Tweak 2 tests 2022-12-24 13:06:37 +00:00
Walter Bright
2c7e732236 replace isImplicitlyConvertible with is expression 2022-12-01 00:52:55 -08:00
Walter Bright
d284c57ecc std.conv.octal: simplify implementation 2022-09-11 23:50:28 -07:00
Grim Maple
1c3903c2e6 Fix Issue 22637 - std.conv to!double and parse!double dont throw on under/overflow
This happened because `parse` enforced on real.
And provided number actually fits real.
Changed to enforce on `Target` type instead
2022-07-09 18:09:25 +03:00
Dennis Korpel
6ceeb18c82 Improve std.conv.parse support for scope strings 2022-03-28 08:18:27 +00:00
Paul Backus
c6b4bd9638 [Refactor] Move toCtString to std.conv
Previously, it was duplicated in std.functional and std.sumtype.
2022-03-26 14:04:37 +00:00
Atila Neves
22959ab86c
Increase @safety of std.conv (#8410)
Increase @safety of std.conv

Signed-off-by: Dennis <dkorpel@users.noreply.github.com>
Merged-on-behalf-of: Dennis <dkorpel@users.noreply.github.com>
2022-03-14 16:33:45 +00:00
dkorpel
05700363b8 Add scope to toImpl of dynamic array 2022-02-17 23:36:10 +00:00
WebFreak001
dac59a4bde add isSomeFiniteCharInputRange as simplification
combines the very common constraint
`isInputRange!R && !isInfinite!R && isSomeChar!(ElementEncodingType!R)`
and adds a bunch of documentation with examples for users to understand
it better. This should lower the neccessary needed technical insight to
read basic docs, especially std.path and std.file docs.
2022-01-15 18:38:52 +01:00
Bianca Fodor
4f979130d3
Fix issue 13551 - std.conv.to for std.typecons tuples too (#8335)
Fix issue 13551 - std.conv.to for std.typecons tuples too

Signed-off-by: Nicholas Wilson <thewilsonator@users.noreply.github.com>
Signed-off-by: Razvan Nitu <RazvanN7@users.noreply.github.com>
Merged-on-behalf-of: Razvan Nitu <RazvanN7@users.noreply.github.com>
2022-01-13 16:00:10 +00:00
dkorpel
0eb2fb7aaa Make phobos compile with pure-scope fix 2021-12-23 18:52:04 +01:00
dkorpel
53086d4ffc remove workaround for issue 20150 2021-08-25 23:36:22 +02:00
dkorpel
010f6b7078 use static foreach for correct scope inference 2021-06-08 10:21:59 +00:00
Martin Kinkelin
36fd878467 Fix Issue 22001 - Avoid undefined bytes in std.conv.toChars() results for radix 10
The buffer is initialized from right-to-left in initialize(), and unused
bytes are left alone. Previously, the whole result wasn't preinitialized
with T.init, so the unused buffer bytes weren't well-defined. Initialize
it now (with zeros), as the whole buffer is still used for equality/
identity comparisons etc.
2021-06-08 07:25:08 +08:00
Witold Baryluk
a8d4b00f98 Fix issue 21926 - Allow leadings zeros in std.conv.octal
First of all, the DDoc currently says that:

"Leading zero is allowed, but not required."

The current implementation doesn't respect that.

D lexer allows leading zero(s) also.

And when considering octal from string, there is no possibility
of confusion, as the comments in the code claim. Disallowing
leading zeros for octal conversion from string, does not help
with anything actually.

So lets allow leading zeros.

Allowing leading zeros, does help when implementing various
APIs (i.e. glibc, Linux kernel), where a lot of octal constant,
are defined with multiple leading zeros, for readability and
alignment, in C headers. Having to manually or automatically
special case these when porting such API definitions, is
counter-productive.

Example from a Linux kernel (`include/uapi/linux/stat.h`):

```c
#define S_IFMT  00170000
#define S_IFSOCK 0140000
#define S_IFLNK	 0120000
#define S_IFREG  0100000
#define S_IFBLK  0060000
#define S_IFDIR  0040000
#define S_IFCHR  0020000
#define S_IFIFO  0010000
#define S_ISUID  0004000
#define S_ISGID  0002000
#define S_ISVTX  0001000
```

With this patch, now it is trivial and easier to convert these to D:

```d
...
enum S_ISVTX = octal!"0001000";
```

while being close to original. That helps with readability,
and long term maintenance.

In fact the run-time version provided by `parse!(int)(string, 8)`
also supports leading zeros already. So this makes `octal`
more consistent `parse`.
2021-05-20 01:48:15 +02:00
Witold Baryluk
46b7b3b02a Fix missing space in exception text in std.conv.to
For example:

Evaluating `to!(int[])("")`
Leads to `ConvException` with message:

`Can't parse string: unexpected end of input when expecting"["`

but should be

`Can't parse string: unexpected end of input when expecting "["`
2021-05-11 02:00:12 +02:00
berni44
b2019ebab0 Narrow imports of std.math in the rest of phobos. 2021-04-21 03:00:57 +02:00
berni44
6f2a0934a7 Adapt imports of std.format to new structure of std.format. 2021-03-19 13:22:00 +01:00
Nathan Sashihara
52da0ef73c Throughout Phobos use core.math intrinsics instead of std.math wrappers
Followup to PR #7821.
2021-03-02 07:09:08 +01:00
Martin Kinkelin
7558583c44 Replace usages of std.functional.forward with core.lifetime.forward
Where it has been moved to. Also get rid of the corresponding tests
in Phobos, an exact copy is in druntime (+ more forward tests).

Also extend a `scoped` test to make sure it properly forwards
r/lvalue-ness of its arguments. This required dlang/druntime#3352
and thus wasn't added in dlang/phobos#7776 directly.
2021-01-31 12:20:09 +01:00
Bernhard Seckinger
9cb7755041 Replace approxEqual with isClose 2021-01-28 10:39:50 +01:00
Razvan Nitu
89abc75f02
Merge pull request #7745 from kinke/emplace
Get rid of std.conv.emplace[Ref](), use core[.internal].lifetime
2021-01-25 15:36:04 +08:00
Bernhard Seckinger
54f224a03d Fix Issue 20539 - std.conv.to: internal overload conflict for enums
with base types that have a catch-all opEquals overload (?)
2021-01-19 16:00:42 +01:00
Martin Kinkelin
1a459c5996 Get rid of std.conv.emplace[Ref](), use core[.internal].lifetime
The emplace() stuff was moved to druntime; for some reason, it's still
in Phobos.

I've diffed the two versions, and they are still almost identical (incl.
unittests); the druntime version appears to have seen some improvements
(e.g., forwarding r/lvalueness of the arguments) in the meantime.
2021-01-17 16:02:25 +01:00
RazvanN7
e2f756866c Temporarily comment one test 2021-01-15 02:37:07 +09:00
Adela Vais
b9db8c8d60
Fix Issue 21233 - std.conv.parse doesn't report the number of characters consumed (#7642) 2020-11-16 10:14:43 +02:00
Iain Buclaw
51c457d1cb std.conv: Fix unittests for FreeBSD x86 53-bit precision reals 2020-11-09 14:25:07 +01:00
Martin Kinkelin
4d3ba080b7
Prepare for properly parsed float/double literals (#7591)
This fixes failing unittests with dlang/dmd#11387 on Linux x64 by
appending a L suffix to (some) literals, to keep full `real` parsing
precision (instead of double precision).
2020-08-14 21:06:56 +08:00
Nathan Sashihara
453faadf5b Replace is(Unqual!T == Unqual!U) with is(immutable T == immutable U) for speed & memory usage 2020-08-03 15:07:32 +02:00
Andrei Alexandrescu
05c79e1af1 unsignedToTempString: use the template version 2020-07-27 03:37:52 +02:00