From f255c9e689b8fa6e52743ad46bac1adc77eeabdc Mon Sep 17 00:00:00 2001 From: Daniel Murphy Date: Wed, 28 Jan 2015 16:33:12 +1100 Subject: [PATCH] Replace more implicit array to bool conversions --- std/conv.d | 2 +- std/format.d | 4 ++-- std/json.d | 2 +- std/process.d | 2 +- std/range/package.d | 2 +- std/signals.d | 26 +++++++++++++------------- std/string.d | 2 +- 7 files changed, 20 insertions(+), 20 deletions(-) diff --git a/std/conv.d b/std/conv.d index 28a8874ba..f9d424a57 100644 --- a/std/conv.d +++ b/std/conv.d @@ -2378,7 +2378,7 @@ Target parse(Target, Source)(ref Source p) ConvException bailOut()(string msg = null, string fn = __FILE__, size_t ln = __LINE__) { - if (!msg) + if (msg == null) msg = "Floating point conversion error"; return new ConvException(text(msg, " for input \"", p, "\"."), fn, ln); } diff --git a/std/format.d b/std/format.d index 209a0d998..aa5d96d9d 100644 --- a/std/format.d +++ b/std/format.d @@ -4857,9 +4857,9 @@ body enforce(i <= T.length); } - if (spec.sep) + if (spec.sep != null) fmt.readUpToNextSpec(input); - auto sep = spec.sep ? spec.sep + auto sep = spec.sep != null ? spec.sep : fmt.trailing; debug (unformatRange) { if (!sep.empty && !input.empty) printf("-> %c, sep = %.*s\n", input.front, sep); diff --git a/std/json.d b/std/json.d index a55795605..a62184488 100644 --- a/std/json.d +++ b/std/json.d @@ -714,7 +714,7 @@ JSONValue parseJSON(T)(T json, int maxDepth = -1) if(isInputRange!T) goto Next; } - return str.data ? str.data : ""; + return str.data.length ? str.data : ""; } void parseValue(JSONValue* value) diff --git a/std/process.d b/std/process.d index 93375b2bc..5ecf2590c 100644 --- a/std/process.d +++ b/std/process.d @@ -879,7 +879,7 @@ unittest // Specifying empty working directory. TestScript prog = ""; string directory = ""; - assert(directory && !directory.length); + assert(directory.ptr && !directory.length); spawnProcess([prog.path], null, Config.none, directory).wait(); } diff --git a/std/range/package.d b/std/range/package.d index 2a39488a2..576e6c90a 100644 --- a/std/range/package.d +++ b/std/range/package.d @@ -8053,7 +8053,7 @@ unittest assert(wrapper[2] == 2); assert(arr == [1, 42, 2, 41, 3, 40, 4, 42, 9]); - assert(*wrapper[3 .. 6].ptr, [41, 3, 40]); + assert(*wrapper[3 .. 6].ptr != null, [41, 3, 40]); assert(arr == [1, 42, 2, 41, 3, 40, 4, 42, 9]); } diff --git a/std/signals.d b/std/signals.d index 519b2ff28..c683f733e 100644 --- a/std/signals.d +++ b/std/signals.d @@ -252,7 +252,7 @@ mixin template Signal(T1...) * know that this object is destroyed so they are not left * with dangling references to it. */ - if (slots) + if (slots.length) { foreach (slot; slots[0 .. slots_idx]) { @@ -386,20 +386,20 @@ unittest { a.s2.connect(&o2.watchInt); a.s3.connect(&o3.watchLong); - assert(!o1.i && !o1.l && !o1.str); - assert(!o2.i && !o2.l && !o2.str); - assert(!o3.i && !o3.l && !o3.str); + assert(!o1.i && !o1.l && o1.str == null); + assert(!o2.i && !o2.l && o2.str == null); + assert(!o3.i && !o3.l && o3.str == null); a.value1 = 11; assert(o1.i == 11 && !o1.l && o1.str == "str1"); - assert(!o2.i && !o2.l && !o2.str); - assert(!o3.i && !o3.l && !o3.str); + assert(!o2.i && !o2.l && o2.str == null); + assert(!o3.i && !o3.l && o3.str == null); o1.i = -11; o1.str = "x1"; a.value2 = 12; assert(o1.i == -11 && !o1.l && o1.str == "x1"); assert(o2.i == 12 && !o2.l && o2.str == "str2"); - assert(!o3.i && !o3.l && !o3.str); + assert(!o3.i && !o3.l && o3.str == null); o2.i = -12; o2.str = "x2"; a.value3 = 13; @@ -468,20 +468,20 @@ unittest { a.s5.connect(&o5.watchInt); a.s6.connect(&o6.watchLong); - assert(!o4.i && !o4.l && !o4.str); - assert(!o5.i && !o5.l && !o5.str); - assert(!o6.i && !o6.l && !o6.str); + assert(!o4.i && !o4.l && o4.str == null); + assert(!o5.i && !o5.l && o5.str == null); + assert(!o6.i && !o6.l && o6.str == null); a.value4 = 44; assert(o4.i == 44 && !o4.l && o4.str == "str4"); - assert(!o5.i && !o5.l && !o5.str); - assert(!o6.i && !o6.l && !o6.str); + assert(!o5.i && !o5.l && o5.str == null); + assert(!o6.i && !o6.l && o6.str == null); o4.i = -44; o4.str = "x4"; a.value5 = 45; assert(o4.i == -44 && !o4.l && o4.str == "x4"); assert(o5.i == 45 && !o5.l && o5.str == "str5"); - assert(!o6.i && !o6.l && !o6.str); + assert(!o6.i && !o6.l && o6.str == null); o5.i = -45; o5.str = "x5"; a.value6 = 46; diff --git a/std/string.d b/std/string.d index 6abdf3966..c1d4e410d 100644 --- a/std/string.d +++ b/std/string.d @@ -3175,7 +3175,7 @@ body assert(translate(to!S("hello world"), makeTrans("hl", "q5")) == to!S("qe55o wor5d")); assert(translate(to!S("hello \U00010143 world"), makeTrans("hl", "q5")) == to!S("qe55o \U00010143 wor5d")); - assert(translate(to!S("hello world"), makeTrans("ol", "1o")), to!S("heool wlrdd")); + assert(translate(to!S("hello world"), makeTrans("ol", "1o")) == to!S("heoo1 w1rod")); assert(translate(to!S("hello world"), makeTrans("", "")) == to!S("hello world")); assert(translate(to!S("hello world"), makeTrans("12345", "67890")) == to!S("hello world")); assert(translate(to!S("hello \U00010143 world"), makeTrans("12345", "67890")) ==