Skip to content

Commit 87373fc

Browse files
committed
chore: Clear up deprecations through the code base
Replaces `approxEqual` with `isClose` and add `pure` to `doubleValue` as it was otherwise failing to compile. As void initialization of bool is no longer safe, this led to two other minor code adjustments.
1 parent 04da94d commit 87373fc

File tree

3 files changed

+11
-17
lines changed

3 files changed

+11
-17
lines changed

source/stdx/data/json/generator.d

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -485,12 +485,12 @@ private void writeNumber(R)(ref R dst, BigInt num) @trusted
485485

486486
auto num = toJSONValue("-67.199307");
487487
auto exp = -67.199307;
488-
assert(num.get!double.approxEqual(exp));
488+
assert(num.get!double.isClose(exp));
489489

490490
auto snum = appender!string;
491491
snum.writeNumber!(GeneratorOptions.init)(JSONNumber(num.get!double));
492492
auto pnum = toJSONValue(snum.data);
493-
assert(pnum.get!double.approxEqual(num.get!double));
493+
assert(pnum.get!double.isClose(num.get!double));
494494
}
495495

496496
@safe unittest // special float values

source/stdx/data/json/lexer.d

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -607,17 +607,11 @@ struct JSONLexerRange(Input, LexOptions options = LexOptions.init, String = stri
607607
return;
608608
}
609609

610-
bool negexp = void;
611-
if (_input.front == '-')
612-
{
613-
negexp = true;
610+
bool negexp = (_input.front == '-');
611+
if (negexp)
612+
skipChar();
613+
else if (_input.front == '+')
614614
skipChar();
615-
}
616-
else
617-
{
618-
negexp = false;
619-
if (_input.front == '+') skipChar();
620-
}
621615

622616
if (_input.empty || !_input.front.isDigit)
623617
{
@@ -747,7 +741,7 @@ struct JSONLexerRange(Input, LexOptions options = LexOptions.init, String = stri
747741
@safe unittest
748742
{
749743
import std.exception;
750-
import std.math : approxEqual, isNaN;
744+
import std.math : isClose, isNaN;
751745

752746
static double parseNumberHelper(LexOptions options, R)(ref R input, ref Location loc)
753747
{
@@ -765,7 +759,7 @@ struct JSONLexerRange(Input, LexOptions options = LexOptions.init, String = stri
765759
Location loc;
766760
auto strcopy = str;
767761
auto res = parseNumberHelper!options(strcopy, loc);
768-
assert((res.isNaN && expected.isNaN) || approxEqual(res, expected), () @trusted {return res.to!string;}());
762+
assert((res.isNaN && expected.isNaN) || isClose(res, expected), () @trusted {return res.to!string;}());
769763
assert(strcopy == remainder);
770764
assert(loc.line == 0);
771765
assert(loc.column == str.length - remainder.length, text(loc.column));
@@ -947,7 +941,7 @@ struct JSONLexerRange(Input, LexOptions options = LexOptions.init, String = stri
947941
@property bool boolean(bool value) pure nothrow @nogc
948942
{
949943
_kind = Kind.boolean;
950-
_boolean = value;
944+
() @trusted { _boolean = value; } ();
951945
return value;
952946
}
953947

@@ -1287,7 +1281,7 @@ enum JSONTokenKind
12871281
* yield a value converted to $(D double). Setting this property will
12881282
* automatically update the number type to $(D Type.double_).
12891283
*/
1290-
@property double doubleValue() const nothrow @trusted @nogc
1284+
@property double doubleValue() const nothrow @trusted @nogc pure
12911285
{
12921286
final switch (_type)
12931287
{

source/stdx/data/json/package.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -948,7 +948,7 @@ unittest
948948
{
949949
if (a.kind == b.kind && a.kind == JSONParserNodeKind.literal) {
950950
if (a.literal.kind == b.literal.kind && a.literal.kind == JSONTokenKind.number)
951-
return a.literal.number.approxEqual(b.literal.number);
951+
return a.literal.number.isClose(b.literal.number);
952952
}
953953
return a == b;
954954
}

0 commit comments

Comments
 (0)