apply all-man braces in Phobos

// 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
This commit is contained in:
Sebastian Wilzbach 2016-05-31 05:30:02 +02:00
parent f276dbc06b
commit 1d34a121e9
47 changed files with 1180 additions and 537 deletions

View file

@ -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
@ -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);

View file

@ -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)));
}
}
@ -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;
@ -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);
@ -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;
}
@ -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;
}
@ -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);
@ -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;
@ -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);
}
@ -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]));
}
}

View file

@ -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])))

View file

@ -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;
}
@ -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]));
@ -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);
}

View file

@ -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);
@ -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);
}
@ -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);
}
@ -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; }
@ -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);
@ -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);
@ -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();