Skip to content

Fix all dlang.org code examples to follow Phobos style #640

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 42 commits into from
Aug 27, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
1263155
Use Phobos style for index.dd code examples
Aug 23, 2014
f856508
Fix coding style in abi.dd
Aug 23, 2014
24209b2
Fix coding style in arrays.dd
Aug 23, 2014
1d8c84e
Fix coding style in attribute.dd
Aug 23, 2014
c7fe8a5
Fix coding style in class.dd
Aug 23, 2014
ac8eed8
Fix coding style in code_coverage.dd
Aug 23, 2014
7a99266
Fix coding style in contracts.dd
Aug 23, 2014
290fd92
Fix coding style in cpp_interface.dd
Aug 23, 2014
701a86b
Fix coding style in cpptod.dd
Aug 23, 2014
901e6fd
Fix coding style for ctod.dd
Aug 23, 2014
0d22b01
Fix coding style for d-array-article.dd
Aug 23, 2014
0d3b906
Fix coding style for ddoc.dd
Aug 24, 2014
a475d06
Fix coding style for declaration.dd
Aug 24, 2014
9f27efd
Fix coding style for d-floating-point.dd
Aug 24, 2014
d0597c2
Fix coding style for enum.dd
Aug 24, 2014
eae5855
Fix coding style in exception-safe.dd
Aug 24, 2014
d2d6e1f
Fix coding style in expression.dd
Aug 24, 2014
c57ab09
Fix coding style for faq.dd
Aug 24, 2014
a55c184
Fix coding style for function.dd
Aug 24, 2014
6b8b5cb
Fix coding style for garbage.dd
Aug 24, 2014
decc15a
Fix coding style for hash-map.dd
Aug 24, 2014
9afe3bb
Fix coding style for hijack.dd
Aug 24, 2014
e6eb7ff
Fix coding style for iasm.dd
Aug 24, 2014
d83e28f
Fix coding style for interface.dd
Aug 24, 2014
1003fc5
Fix coding style for interfaceToC.dd
Aug 24, 2014
d9f6932
Fix coding style for module.dd
Aug 24, 2014
32893a2
Fix coding style for operatoroverloading.dd
Aug 25, 2014
8326fe8
Fix coding style for pragma.dd
Aug 25, 2014
f6e91a8
Fix coding style for pretod.dd
Aug 25, 2014
43f9a29
Fix coding style for property.dd
Aug 25, 2014
c9dda97
Fix coding style for rationale.dd
Aug 25, 2014
1ac5b99
Fix coding style for statement.dd
Aug 25, 2014
0cc7e71
Fix coding style for struct.dd
Aug 25, 2014
6271ba8
Fix coding style for template.dd
Aug 26, 2014
c415a1b
Fix coding style for template-mixin.dd
Aug 26, 2014
e76e46f
Fix coding style for templates-revisited.dd
Aug 26, 2014
2548fde
Fix coding style for traits.dd
Aug 26, 2014
3474cc1
Fix coding style for type.dd
Aug 26, 2014
2ec4d77
Fix coding style for unittest.dd
Aug 26, 2014
2cdc0ee
Fix coding style for version.dd
Aug 26, 2014
a0f6573
Delete extraneous spaces around parentheses.
Aug 27, 2014
81dd769
Kill tab characters in code samples
Aug 27, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion abi.dd
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ $(CCODE
$(P The class definition:)

---------
class XXXX {
class XXXX
{
....
};
---------
Expand Down
69 changes: 38 additions & 31 deletions arrays.dd
Original file line number Diff line number Diff line change
Expand Up @@ -364,19 +364,22 @@ $(H3 $(LNAME2 pointer-arithmetic, Pointer Arithmetic))
int[3] abc; // static array of 3 ints
int[] def = [ 1, 2, 3 ]; // dynamic array of 3 ints

void dibb(int* array) {
array[2]; // means same thing as *(array + 2)
*(array + 2); // get 3rd element
void dibb(int* array)
{
array[2]; // means same thing as *(array + 2)
*(array + 2); // get 3rd element
}

void diss(int[] array) {
array[2]; // ok
*(array + 2); // error, array is not a pointer
void diss(int[] array)
{
array[2]; // ok
*(array + 2); // error, array is not a pointer
}

void ditt(int[3] array) {
array[2]; // ok
*(array + 2); // error, array is not a pointer
void ditt(int[3] array)
{
array[2]; // ok
*(array + 2); // error, array is not a pointer
}
---------

Expand Down Expand Up @@ -591,12 +594,13 @@ a[15] = 'z'; // does not affect c, because either a or c has reallocated.

---------
int[] array;
while (1) {
c = getinput();
if (!c)
break;
++array.length;
array[array.length - 1] = c;
while (1)
{
c = getinput();
if (!c)
break;
++array.length;
array[array.length - 1] = c;
}
---------

Expand All @@ -607,13 +611,14 @@ while (1) {
---------
int[] array;
array.length = 100; // guess
for (i = 0; ; i++) {
c = getinput();
if (!c)
break;
if (i == array.length)
array.length *= 2;
array[i] = c;
for (i = 0; ; i++)
{
c = getinput();
if (!c)
break;
if (i == array.length)
array.length *= 2;
array[i] = c;
}
array.length = i;
---------
Expand Down Expand Up @@ -652,21 +657,25 @@ $(H3 $(LNAME2 bounds, Array Bounds Checking))
)

---------
try {
for (i = 0; ; i++) {
array[i] = 5;
}
try
{
for (i = 0; ; i++)
{
array[i] = 5;
}
}
catch (RangeError) {
catch (RangeError)
{
// terminate loop
}
---------

The loop is correctly written:

---------
for (i = 0; i < array.length; i++) {
array[i] = 5;
for (i = 0; i < array.length; i++)
{
array[i] = 5;
}
---------

Expand Down Expand Up @@ -815,10 +824,8 @@ str ~= "\0";
)

---------

cast(immutable(wchar) [])"abc" // this is an array of wchar characters
"abc"w // so is this

---------

$(P String literals that do not have a postfix character and that
Expand Down
115 changes: 66 additions & 49 deletions attribute.dd
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ $(GNAME LinkageType):

---------------
extern (C):
int foo(); // call foo() with C conventions
int foo(); // call foo() with C conventions
---------------

$(P D conventions are:)
Expand All @@ -116,11 +116,11 @@ extern (D):

---------------
extern (Windows):
void *VirtualAlloc(
void *lpAddress,
uint dwSize,
uint flAllocationType,
uint flProtect
void *VirtualAlloc(
void *lpAddress,
uint dwSize,
uint flAllocationType,
uint flProtect
);
---------------

Expand Down Expand Up @@ -204,11 +204,12 @@ $(GNAME AlignAttribute):
of the companion C compiler.)

--------
struct S {
struct S
{
align:
byte a; // placed at offset 0
int b; // placed at offset 4
long c; // placed at offset 8
byte a; // placed at offset 0
int b; // placed at offset 4
long c; // placed at offset 8
}

auto sz = S.sizeof; // 16
Expand All @@ -224,11 +225,12 @@ auto sz = S.sizeof; // 16
)

--------
struct S {
struct S
{
align (1):
byte a; // placed at offset 0
int b; // placed at offset 1
long c; // placed at offset 5
byte a; // placed at offset 0
int b; // placed at offset 1
long c; // placed at offset 5
}

auto sz = S.sizeof; // 16
Expand All @@ -239,11 +241,12 @@ auto sz = S.sizeof; // 16
of the aggregate.)

--------
align (2) struct S {
align (2) struct S
{
align (1):
byte a; // placed at offset 0
int b; // placed at offset 1
long c; // placed at offset 5
byte a; // placed at offset 0
int b; // placed at offset 1
long c; // placed at offset 5
}

auto sz = S.sizeof; // 14
Expand All @@ -253,11 +256,12 @@ auto sz = S.sizeof; // 14
of the size of the field.)

--------
struct S {
struct S
{
align (4):
byte a; // placed at offset 0
byte b; // placed at offset 4
short c; // placed at offset 8
byte a; // placed at offset 0
byte b; // placed at offset 4
short c; // placed at offset 8
}

auto sz = S.sizeof; // 12
Expand Down Expand Up @@ -402,14 +406,17 @@ $(H3 $(LNAME2 const, $(D const) Attribute))
const int foo = 7;
static assert(is(typeof(foo) == const(int)));

const {
const
{
double bar = foo + 6;
}
static assert(is(typeof(bar) == const(double)));

class C {
class C
{
const void foo();
const {
const
{
void bar();
}
void baz() const;
Expand Down Expand Up @@ -456,11 +463,13 @@ $(H3 $(LNAME2 gshared, $(D __gshared) Attribute))
thread local.)

---
class Foo {
class Foo
{
__gshared int bar;
}

int foo() {
int foo()
{
__gshared int bar = 0;
return bar++; // Not thread safe.
}
Expand All @@ -484,7 +493,8 @@ $(H3 $(LNAME2 disable, $(D @disable) Attribute))
---
@disable void foo() { }

void main() {
void main()
{
foo(); // error, foo is disabled
}
---
Expand All @@ -507,10 +517,11 @@ $(H3 $(LNAME2 nogc, $(D @nogc) Attribute))
)

---
@nogc void foo(char[] a) {
auto p = new int; // error, operator new allocates
a ~= 'c'; // error, appending to arrays allocates
bar(); // error, bar() may allocate
@nogc void foo(char[] a)
{
auto p = new int; // error, operator new allocates
a ~= 'c'; // error, appending to arrays allocates
bar(); // error, bar() may allocate
}

void bar() { }
Expand All @@ -527,11 +538,12 @@ $(H3 $(LNAME2 nogc, $(D @nogc) Attribute))
void foo();
@nogc void bar();

void test() {
fp = &foo; // ok
fp = &bar; // ok, it's covariant
gp = &foo; // error, not contravariant
gp = &bar; // ok
void test()
{
fp = &foo; // ok
fp = &bar; // ok, it's covariant
gp = &foo; // error, not contravariant
gp = &bar; // ok
}
---

Expand Down Expand Up @@ -562,16 +574,19 @@ $(H3 $(LNAME2 override, $(D override) Attribute))
)

---------------
class Foo {
int bar();
int abc(int x);
class Foo
{
int bar();
int abc(int x);
}

class Foo2 : Foo {
override {
int bar(char c); // error, no bar(char) in Foo
int abc(int x); // ok
}
class Foo2 : Foo
{
override
{
int bar(char c); // error, no bar(char) in Foo
int abc(int x); // ok
}
}
---------------

Expand All @@ -585,9 +600,10 @@ $(H3 $(LNAME2 static, $(D static) Attribute))
)

---------------
class Foo {
static int bar() { return 6; }
int foobar() { return 7; }
class Foo
{
static int bar() { return 6; }
int foobar() { return 7; }
}

...
Expand Down Expand Up @@ -718,7 +734,8 @@ struct Bar
)

---
@(1) {
@(1)
{
@(2) int a; // has UDA's (1, 2)
@("string") int b; // has UDA's (1, "string")
}
Expand Down
Loading