Skip to content

Commit

Permalink
apply all-man braces in Phobos
Browse files Browse the repository at this point in the history
// find common cases
sed -E "s/^(\s*)((if|static if|for|foreach|foreach_reverse|while|unittest|switch|else|version).*)\s*\{$/\1\2\n\1{/" -i **/*.d
// catch else-if
sed -E "s/^(\s*)} (else static if| if|else if|else)(.*)\s*\{$/\1}\n\1\2\3\n\1{/" -i **/*.d
// remove created trailing whitespace
sed -i 's/[ \t]*$//' **/*.d
  • Loading branch information
wilzbach committed May 31, 2016
1 parent f276dbc commit 1d34a12
Show file tree
Hide file tree
Showing 47 changed files with 1,180 additions and 537 deletions.
3 changes: 2 additions & 1 deletion etc/c/curl.d
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ alias CURL = void;
alias curl_socket_t = socket_t;

/// jdrewsen - Would like to get socket error constant from std.socket by it is private atm.
version(Windows) {
version(Windows)
{
private import core.sys.windows.windows, core.sys.windows.winsock2;
enum CURL_SOCKET_BAD = SOCKET_ERROR;
}
Expand Down
6 changes: 4 additions & 2 deletions etc/c/zlib.d
Original file line number Diff line number Diff line change
Expand Up @@ -1284,7 +1284,8 @@ void gzclearerr (gzFile file);
uint adler = adler32(0L, Z_NULL, 0);
while (read_buffer(buffer, length) != EOF) {
while (read_buffer(buffer, length) != EOF)
{
adler = adler32(adler, buffer, length);
}
if (adler != original_adler) error();
Expand All @@ -1308,7 +1309,8 @@ uint crc32(uint crc, ubyte* buf, uint len);
uint crc = crc32(0L, Z_NULL, 0);
while (read_buffer(buffer, length) != EOF) {
while (read_buffer(buffer, length) != EOF)
{
crc = crc32(crc, buffer, length);
}
if (crc != original_crc) error();
Expand Down
9 changes: 6 additions & 3 deletions std/algorithm/comparison.d
Original file line number Diff line number Diff line change
Expand Up @@ -923,13 +923,15 @@ private struct Levenshtein(Range, alias equals, CostType = size_t)
EditOp[] result;
size_t i = rows - 1, j = cols - 1;
// restore the path
while (i || j) {
while (i || j)
{
auto cIns = j == 0 ? CostType.max : matrix(i,j - 1);
auto cDel = i == 0 ? CostType.max : matrix(i - 1,j);
auto cSub = i == 0 || j == 0
? CostType.max
: matrix(i - 1,j - 1);
switch (min_index(cSub, cIns, cDel)) {
switch (min_index(cSub, cIns, cDel))
{
case 0:
result ~= matrix(i - 1,j - 1) == matrix(i,j)
? EditOp.none
Expand Down Expand Up @@ -968,7 +970,8 @@ private:
void AllocMatrix(size_t r, size_t c) @trusted {
rows = r;
cols = c;
if (_matrix.length < r * c) {
if (_matrix.length < r * c)
{
import core.stdc.stdlib : realloc;
import core.exception : onOutOfMemoryError;
auto m = cast(CostType *)realloc(_matrix.ptr, r * c * _matrix[0].sizeof);
Expand Down
36 changes: 24 additions & 12 deletions std/algorithm/iteration.d
Original file line number Diff line number Diff line change
Expand Up @@ -1154,12 +1154,14 @@ private struct FilterResult(alias pred, Range)
static assert(isInfinite!(typeof(infinite)));
static assert(isForwardRange!(typeof(infinite)));

foreach (DummyType; AllDummyRanges) {
foreach (DummyType; AllDummyRanges)
{
DummyType d;
auto f = filter!"a & 1"(d);
assert(equal(f, [1,3,5,7,9]));

static if (isForwardRange!DummyType) {
static if (isForwardRange!DummyType)
{
static assert(isForwardRange!(typeof(f)));
}
}
Expand Down Expand Up @@ -1416,7 +1418,8 @@ struct Group(alias pred, R) if (isInputRange!R)
return _current;
}

static if (isForwardRange!R) {
static if (isForwardRange!R)
{
///
@property typeof(this) save() {
typeof(this) ret = this;
Expand Down Expand Up @@ -1451,7 +1454,8 @@ struct Group(alias pred, R) if (isInputRange!R)
tuple(4, 3u), tuple(5, 1u) ][]));
static assert(isForwardRange!(typeof(group(arr))));

foreach (DummyType; AllDummyRanges) {
foreach (DummyType; AllDummyRanges)
{
DummyType d;
auto g = group(d);

Expand Down Expand Up @@ -2480,7 +2484,8 @@ unittest
// Can't use array() or equal() directly because they fail with transient
// .front.
int[] result;
foreach (c; rr.joiner()) {
foreach (c; rr.joiner())
{
result ~= c;
}

Expand Down Expand Up @@ -2525,7 +2530,8 @@ unittest
// Can't use array() or equal() directly because they fail with transient
// .front.
dchar[] result;
foreach (c; rr.joiner()) {
foreach (c; rr.joiner())
{
result ~= c;
}

Expand Down Expand Up @@ -3715,7 +3721,8 @@ if (is(typeof(binaryFun!pred(r.front, s)) : bool)
assert(split.back == "r ");

foreach (DummyType; AllDummyRanges) { // Bug 4408
static if (isRandomAccessRange!DummyType) {
static if (isRandomAccessRange!DummyType)
{
static assert(isBidirectionalRange!DummyType);
DummyType d;
auto s = splitter(d, 5);
Expand Down Expand Up @@ -4369,8 +4376,10 @@ if (isSomeChar!C)
lines[0] = "line one".dup;
lines[1] = "line \ttwo".dup;
lines[2] = "yah last line\ryah".dup;
foreach (line; lines) {
foreach (word; splitter(strip(line))) {
foreach (line; lines)
{
foreach (word; splitter(strip(line)))
{
if (word in dictionary) continue; // Nothing to do
auto newID = dictionary.length;
dictionary[to!string(word)] = cast(uint)newID;
Expand Down Expand Up @@ -4843,7 +4852,8 @@ private struct UniqResult(alias pred, Range)
@property bool empty() { return _input.empty; }
}

static if (isForwardRange!Range) {
static if (isForwardRange!Range)
{
@property typeof(this) save() {
return typeof(this)(_input.save);
}
Expand All @@ -4865,14 +4875,16 @@ private struct UniqResult(alias pred, Range)
assert(equal(r, [ 1, 2, 3, 4, 5 ][]));
assert(equal(retro(r), retro([ 1, 2, 3, 4, 5 ][])));

foreach (DummyType; AllDummyRanges) {
foreach (DummyType; AllDummyRanges)
{
DummyType d;
auto u = uniq(d);
assert(equal(u, [1,2,3,4,5,6,7,8,9,10]));

static assert(d.rt == RangeType.Input || isForwardRange!(typeof(u)));

static if (d.rt >= RangeType.Bidirectional) {
static if (d.rt >= RangeType.Bidirectional)
{
assert(equal(retro(u), [10,9,8,7,6,5,4,3,2,1]));
}
}
Expand Down
3 changes: 2 additions & 1 deletion std/algorithm/mutation.d
Original file line number Diff line number Diff line change
Expand Up @@ -2396,7 +2396,8 @@ Params:
*/
void swapAt(R)(auto ref R r, size_t i1, size_t i2)
{
static if (is(typeof(&r.swapAt))) {
static if (is(typeof(&r.swapAt)))
{
r.swapAt(i1, i2);
}
else static if (is(typeof(&r[i1])))
Expand Down
9 changes: 6 additions & 3 deletions std/algorithm/searching.d
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,8 @@ is ignored.
import std.algorithm.comparison : equal;
ptrdiff_t virtual_begin = needle.length - offset - portion;
ptrdiff_t ignore = 0;
if (virtual_begin < 0) {
if (virtual_begin < 0)
{
ignore = -virtual_begin;
virtual_begin = 0;
}
Expand Down Expand Up @@ -2173,7 +2174,8 @@ if (Ranges.length > 1 && is(typeof(startsWith!pred(haystack, needles))))
assert(find(a, b) == [ 1, 2, 3, 4, 5 ]);
assert(find(b, a).empty);

foreach (DummyType; AllDummyRanges) {
foreach (DummyType; AllDummyRanges)
{
DummyType d;
auto findRes = find(d, 5);
assert(equal(findRes, [5,6,7,8,9,10]));
Expand Down Expand Up @@ -2206,7 +2208,8 @@ Range1 find(Range1, alias pred, Range2)(
"(.gnu.linkonce.tmain+0x74): In function `main' undefined reference"~
" to `_Dmain':";
string[] ns = ["libphobos", "function", " undefined", "`", ":"];
foreach (n ; ns) {
foreach (n ; ns)
{
auto p = find(h, boyerMooreFinder(n));
assert(!p.empty);
}
Expand Down
21 changes: 14 additions & 7 deletions std/algorithm/sorting.d
Original file line number Diff line number Diff line change
Expand Up @@ -998,7 +998,8 @@ private size_t getPivot(alias less, Range)(Range r)
((cast(uint) (pred(r[0], r[len - 1]))) << 1) |
(cast(uint) (pred(r[mid], r[len - 1])));

switch (result) {
switch (result)
{
case 0b001:
r.swapAt(0, len - 1);
r.swapAt(0, mid);
Expand Down Expand Up @@ -1070,7 +1071,8 @@ private void optimisticInsertionSort(alias less, Range)(Range r)

auto rnd = Random(1);
auto a = new int[uniform(100, 200, rnd)];
foreach (ref e; a) {
foreach (ref e; a)
{
e = uniform(-100, 100, rnd);
}

Expand Down Expand Up @@ -1216,7 +1218,8 @@ unittest
// sort using delegate
auto a = new int[100];
auto rnd = Random(unpredictableSeed);
foreach (ref e; a) {
foreach (ref e; a)
{
e = uniform(-100, 100, rnd);
}

Expand All @@ -1231,7 +1234,8 @@ unittest
assert(isSorted!("a < b")(a));

// sort using function; all elements equal
foreach (ref e; a) {
foreach (ref e; a)
{
e = 5;
}
static bool less(int a, int b) { return a < b; }
Expand Down Expand Up @@ -2223,7 +2227,8 @@ unittest

static double entropy(double[] probs) {
double result = 0;
foreach (p; probs) {
foreach (p; probs)
{
if (!p) continue;
//enforce(p > 0 && p <= 1, "Wrong probability passed to entropy");
result -= p * log2(p);
Expand Down Expand Up @@ -2256,7 +2261,8 @@ unittest

static double entropy(double[] probs) {
double result = 0;
foreach (p; probs) {
foreach (p; probs)
{
if (!p) continue;
//enforce(p > 0 && p <= 1, "Wrong probability passed to entropy");
result -= p * log2(p);
Expand Down Expand Up @@ -2799,7 +2805,8 @@ bool nextPermutation(alias less="a < b", BidirectionalRange)
break;
}

if (i.empty) {
if (i.empty)
{
// Entire range is decreasing: it's lexicographically the greatest. So
// wrap it around.
range.reverse();
Expand Down
3 changes: 2 additions & 1 deletion std/array.d
Original file line number Diff line number Diff line change
Expand Up @@ -2966,7 +2966,8 @@ if (isDynamicArray!A)
}

///
unittest{
unittest
{
auto app = appender!string();
string b = "abcdefg";
foreach (char c; b)
Expand Down
19 changes: 13 additions & 6 deletions std/bigint.d
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,13 @@ public:
}
else static if (op=="*")
{
if (y == 0) {
if (y == 0)
{
sign = false;
data = 0UL;
} else {
}
else
{
sign = ( sign != (y<0) );
data = BigUint.mulInt(data, u);
}
Expand Down Expand Up @@ -1095,23 +1098,26 @@ Unsigned!T absUnsign(T)(T x) if (isIntegral!T)
}

nothrow pure
unittest {
unittest
{
BigInt a, b;
a = 1;
b = 2;
auto c = a + b;
}

nothrow pure
unittest {
unittest
{
long a;
BigInt b;
auto c = a + b;
auto d = b + a;
}

nothrow pure
unittest {
unittest
{
BigInt x = 1, y = 2;
assert(x < y);
assert(x <= y);
Expand All @@ -1134,7 +1140,8 @@ unittest {
assert(incr == BigInt(1));
}

unittest {
unittest
{
// Radix conversion
assert( toDecimalString(BigInt("-1_234_567_890_123_456_789"))
== "-1234567890123456789");
Expand Down
3 changes: 2 additions & 1 deletion std/complex.d
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,8 @@ Complex!T cos(T)(Complex!T z) @safe pure nothrow @nogc
}

///
unittest{
unittest
{
import std.math;
import std.complex;
assert(cos(complex(0.0)) == 1.0);
Expand Down
11 changes: 8 additions & 3 deletions std/concurrency.d
Original file line number Diff line number Diff line change
Expand Up @@ -1716,11 +1716,16 @@ void yield(T)(T value)
}


version (Win64) {
version (Win64)
{
// fibers are broken on Win64
} else version (Win32) {
}
else version (Win32)
{
// fibers are broken in Win32 under server 2012: bug 13821
} else unittest {
}
else unittest
{
import core.exception;
import std.exception;

Expand Down
3 changes: 2 additions & 1 deletion std/container/array.d
Original file line number Diff line number Diff line change
Expand Up @@ -1291,7 +1291,8 @@ unittest
}

// Test issue 11194
unittest {
unittest
{
static struct S {
int i = 1337;
void* p;
Expand Down
3 changes: 2 additions & 1 deletion std/container/package.d
Original file line number Diff line number Diff line change
Expand Up @@ -1051,6 +1051,7 @@ Complexity: $(BIGOH n)
}
}

unittest {
unittest
{
TotalContainer!int test;
}
Loading

0 comments on commit 1d34a12

Please sign in to comment.