From a563512c890f0b64354ed12b856dcb490652c53f Mon Sep 17 00:00:00 2001 From: Martin Nowak Date: Fri, 7 Aug 2015 13:32:30 +0200 Subject: [PATCH 1/3] Merge pull request #3530 from WalterBright/fix14881 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fix Issue 14881 - [REG] posix.mak omits package.d files when building… --- posix.mak | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/posix.mak b/posix.mak index c7c248a90..6600287a9 100644 --- a/posix.mak +++ b/posix.mak @@ -369,7 +369,8 @@ clean : rm -rf $(ROOT_OF_THEM_ALL) $(ZIPFILE) $(DOC_OUTPUT_DIR) zip : - zip $(ZIPFILE) $(MAKEFILE) $(ALL_D_FILES) $(ALL_C_FILES) index.d win32.mak win64.mak osmodel.mak + zip $(ZIPFILE) $(MAKEFILE) $(ALL_D_FILES) $(ALL_C_FILES) index.d win32.mak win64.mak osmodel.mak \ + $(addsuffix /package.d,$(STD_PACKAGES)) install2 : all $(eval lib_dir=$(if $(filter $(OS),osx), lib, lib$(MODEL))) From 70eea5de1decde102b0b8e41de099167793a1420 Mon Sep 17 00:00:00 2001 From: Andrei Alexandrescu Date: Fri, 26 Jun 2015 08:07:23 -0700 Subject: [PATCH 2/3] Merge pull request #3430 from WalterBright/rangestrip Range-ify std.string.strip and stripRight() --- std/string.d | 141 +++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 126 insertions(+), 15 deletions(-) diff --git a/std/string.d b/std/string.d index ab2377206..063da1526 100644 --- a/std/string.d +++ b/std/string.d @@ -2657,26 +2657,107 @@ Range stripLeft(Range)(Range str) /++ Strips trailing whitespace (as defined by $(XREF uni, isWhite)). - Returns: $(D str) stripped of trailing whitespace. + Params: + str = string or random access range of characters - Postconditions: $(D str) and the returned value - will share the same head (see $(XREF array, sameHead)). + Returns: + slice of $(D str) stripped of trailing whitespace. +/ -C[] stripRight(C)(C[] str) @safe pure @nogc - if (isSomeChar!C) +auto stripRight(Range)(Range str) + if (isSomeString!Range || + isRandomAccessRange!Range && hasLength!Range && hasSlicing!Range && + isSomeChar!(ElementEncodingType!Range)) { - import std.utf : codeLength; - foreach_reverse (i, dchar c; str) + alias C = Unqual!(ElementEncodingType!Range); + static if (isSomeString!Range) { - if (!std.uni.isWhite(c)) - return str[0 .. i + codeLength!C(c)]; - } + import std.utf : codeLength; + foreach_reverse (i, dchar c; str) + { + if (!std.uni.isWhite(c)) + return str[0 .. i + codeLength!C(c)]; + } - return str[0 .. 0]; + return str[0 .. 0]; + } + else + { + size_t i = str.length; + while (i--) + { + static if (C.sizeof == 4) + { + if (std.uni.isWhite(str[i])) + continue; + break; + } + else static if (C.sizeof == 2) + { + auto c2 = str[i]; + if (c2 < 0xD800 || c2 >= 0xE000) + { + if (std.uni.isWhite(c2)) + continue; + } + else if (c2 >= 0xDC00) + { + if (i) + { + auto c1 = str[i - 1]; + if (c1 >= 0xD800 && c1 < 0xDC00) + { + dchar c = ((c1 - 0xD7C0) << 10) + (c2 - 0xDC00); + if (std.uni.isWhite(c)) + { + --i; + continue; + } + } + } + } + break; + } + else static if (C.sizeof == 1) + { + import std.utf : byDchar; + + char cx = str[i]; + if (cx <= 0x7F) + { + if (std.uni.isWhite(cx)) + continue; + break; + } + else + { + size_t stride = 0; + + while (1) + { + ++stride; + if (!i || (cx & 0xC0) == 0xC0 || stride == 4) + break; + cx = str[i - 1]; + if (!(cx & 0x80)) + break; + --i; + } + + if (!std.uni.isWhite(str[i .. i + stride].byDchar.front)) + return str[0 .. i + stride]; + } + } + else + static assert(0); + } + + return str[0 .. i + 1]; + } } /// -@safe pure unittest +@safe pure +unittest { import std.uni : lineSep, paraSep; assert(stripRight(" hello world ") == @@ -2691,15 +2772,45 @@ C[] stripRight(C)(C[] str) @safe pure @nogc [paraSep] ~ "hello world"); } +unittest +{ + import std.utf; + import std.array; + import std.uni : lineSep, paraSep; + assert(stripRight(" hello world ".byChar).array == " hello world"); + assert(stripRight("\n\t\v\rhello world\n\t\v\r"w.byWchar).array == "\n\t\v\rhello world"w); + assert(stripRight("hello world"d.byDchar).array == "hello world"d); + assert(stripRight("\u2028hello world\u2020\u2028".byChar).array == "\u2028hello world\u2020"); + assert(stripRight("hello world\U00010001"w.byWchar).array == "hello world\U00010001"w); + + foreach (C; TypeTuple!(char, wchar, dchar)) + { + foreach (s; invalidUTFstrings!C()) + { + cast(void)stripRight(s.byUTF!C).array; + } + } + + cast(void)stripRight("a\x80".byUTF!char).array; + wstring ws = ['a', cast(wchar)0xDC00]; + cast(void)stripRight(ws.byUTF!wchar).array; +} + /++ Strips both leading and trailing whitespace (as defined by $(XREF uni, isWhite)). - Returns: $(D str) stripped of trailing whitespace. + Params: + str = string or random access range of characters + + Returns: + slice of $(D str) stripped of leading and trailing whitespace. +/ -C[] strip(C)(C[] str) @safe pure - if (isSomeChar!C) +auto strip(Range)(Range str) + if (isSomeString!Range || + isRandomAccessRange!Range && hasLength!Range && hasSlicing!Range && + isSomeChar!(ElementEncodingType!Range)) { return stripRight(stripLeft(str)); } From eff54e62ca7203f02360d71fc646e57d3bccf8d5 Mon Sep 17 00:00:00 2001 From: k-hara Date: Mon, 10 Aug 2015 11:56:59 +0900 Subject: [PATCH 3/3] fix Issue 14890 - Can not construct a RedBlackTree of Tuples --- std/typecons.d | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/std/typecons.d b/std/typecons.d index 15ba08295..8bb799bf1 100644 --- a/std/typecons.d +++ b/std/typecons.d @@ -394,9 +394,8 @@ template Tuple(Specs...) } enum areCompatibleTuples(Tup1, Tup2, string op) = isTuple!Tup2 && is(typeof( + (ref Tup1 tup1, ref Tup2 tup2) { - Tup1 tup1 = void; - Tup2 tup2 = void; static assert(tup1.field.length == tup2.field.length); foreach (i, _; Tup1.Types) { @@ -1148,6 +1147,24 @@ unittest static assert( is(typeof(tc4 < tm4))); static assert( is(typeof(tc4 < tc4))); } + // Bugzilla 14890 + static void test14890(inout int[] dummy) + { + alias V = Tuple!(int, int); + + V mv; + const V cv; + immutable V iv; + inout V wv; // OK <- NG + inout const V wcv; // OK <- NG + + foreach (v1; TypeTuple!(mv, cv, iv, wv, wcv)) + foreach (v2; TypeTuple!(mv, cv, iv, wv, wcv)) + { + static assert(__traits(compiles, v1 < v2), + typeof(v1).stringof ~ " < " ~ typeof(v2).stringof); + } + } { int[2] ints = [ 1, 2 ]; Tuple!(int, int) t = ints;