Commit graph

728 commits

Author SHA1 Message Date
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
Per Nordlöw
8ef03bc2ee
Reuse new builtin trait isCopyable in std.traits.isCopyable (#7522) 2020-07-17 09:46:32 +08:00
Atila Neves
46933cf73e Fix issue 20782 - allow std.conv.to to convert string to const enum
The commit allows the following code to compile:

------------------------
enum Enum { oops }
"foo".to!(const Enum);
------------------------
2020-04-28 12:19:52 +02:00
Geod24
62c72ca6ff Follow up review on PR 7441
Steven identified a couple mistakes in the massive round of linkification.
Fixing them here.
2020-04-15 02:15:04 +09:00
Geod24
04f3979317 Replace 'Issue XXX' with Bugzilla links
Make the links clickable, as was done in the DMD repository.
Also avoids any ambiguity w.r.t. where the issue is stored.
2020-04-13 16:28:09 +09:00
Geod24
a2560c711c Remove outdated comment about fixed issue 2020-04-11 02:51:48 +09:00
MoonlightSentinel
d7e0c0ce70
Add tests for Issue 20623 - std.conv.to!string error when argument
is an inout float. This bug was fixed as side effect of #7407.
2020-03-10 17:59:29 +01:00
drug007
7ffdfef3f7 Fix issue 20589 - typeof may give wrong result in case of classes defining opCall operator 2020-02-26 16:41:17 +03:00
Adam D. Ruppe
ae93f5317c Use consistent quickindex wrapper around hand-written list-of-links tables 2020-02-21 21:04:05 -05:00
Martin Kinkelin
9c04113936 Fix recent test regressions for targets with double-precision real 2020-02-22 00:36:56 +01:00
Robert Schadek
9740b9afae adding assert messages to std.conv 2020-01-31 15:36:25 +00:00
Alexandru Militaru
bb62aaca3d Replaced version (unittest) with version (StdUnittest) to avoid unnecessary overhead when compiling with -unittest 2020-01-19 14:05:17 +02:00
Bernhard Seckinger
6a1b88fcb8 Fix Issue 5232 - [patch] std.conv.to & std.conv.roundTo report invalid
overflows for very large numbers
2019-12-28 09:27:40 +01:00
Bernhard Seckinger
088e55a56a Fix Issue 18248 - radix overload of std.conv.parse fails to throw on
non-empty range without number
2019-12-08 14:06:30 +01:00
Bernhard Seckinger
932d49b217 Fix partially Issue 9621 - std.conv.parseEscape fails on octals and named 2019-11-13 12:54:31 +01:00
Robert Schadek
2b2ed40f61 Fix Issue 20288
std.format with separator and double causes RangeError

trying to find the win32 bug

windows nan -nan fix

harder workaround

name clash fix

moving some stuff around

making it shorter

oh win32_64 what are you doing to me

and another try

some windows special case

and another

and again

removed some duplicated code

make it compile again

some debug output

I need a win32_64 box

and again

better infos

finding the failing test

something strange is going on

getting closer

I got it maybe

less output

I think I understand now

tighter code

making the commit nicer

removed an import

undoing some debug changes

removed an unneeded test
2019-10-22 12:17:46 +01:00
The Dlang Bot
7f48a36a26
Merge pull request #7197 from Panke/std-conv-formatvalue
Reference std.format.formatValue from std.conv
merged-on-behalf-of: Nicholas Wilson <thewilsonator@users.noreply.github.com>
2019-10-02 09:01:54 +02:00
Berni
1cc164d6a6 Move "print" to "convert" in example of to template. 2019-09-28 16:22:35 +02:00
Tobias Pankrath
fffb5a81c8 Reference std.format.formatValue from std.conv 2019-09-25 18:50:47 +02:00
Vladimir Panteleev
e9c8d30d7b When parsing char types then appending to a string, parse as dchar
Parsing as the string element type (char, in non-autodecode mode) does
not allow fitting the result of parsing escapes. Those always need to
be parsed into a dchar.
2019-08-15 12:48:11 +00:00
Vladimir Panteleev
108672bd2b std.conv: Allow instantiating parseElement only with dchar
Narrower char types cannot fit the result of parsing an escaped
character.
2019-08-15 12:33:51 +00:00
Vladimir Panteleev
c4ae17a02d std.conv: Fix instantiations of parseElement with const Target
This is a pedantic fix.
2019-08-15 12:30:45 +00:00
Martin Nowak
d2e931f149 Merge remote-tracking branch 'upstream/stable' into merge_stable 2019-08-05 08:51:49 +02:00