Skip to content

Commit 0c8e5e5

Browse files
authored
Merge pull request #8808 from jtbx/std-doc
Improve documentation in std.json and std.socket Signed-off-by: Vladimir Panteleev <CyberShadow@users.noreply.github.com> Signed-off-by: Nicholas Wilson <thewilsonator@users.noreply.github.com> Merged-on-behalf-of: Nicholas Wilson <thewilsonator@users.noreply.github.com>
2 parents efc64f3 + 80747a9 commit 0c8e5e5

File tree

2 files changed

+54
-55
lines changed

2 files changed

+54
-55
lines changed

std/json.d

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -70,25 +70,25 @@ String literals used to represent special float values within JSON strings.
7070
*/
7171
enum JSONFloatLiteral : string
7272
{
73-
nan = "NaN", /// string representation of floating-point NaN
74-
inf = "Infinite", /// string representation of floating-point Infinity
75-
negativeInf = "-Infinite", /// string representation of floating-point negative Infinity
73+
nan = "NaN", /// String representation of floating-point NaN
74+
inf = "Infinite", /// String representation of floating-point Infinity
75+
negativeInf = "-Infinite", /// String representation of floating-point negative Infinity
7676
}
7777

7878
/**
79-
Flags that control how json is encoded and parsed.
79+
Flags that control how JSON is encoded and parsed.
8080
*/
8181
enum JSONOptions
8282
{
83-
none, /// standard parsing
84-
specialFloatLiterals = 0x1, /// encode NaN and Inf float values as strings
85-
escapeNonAsciiChars = 0x2, /// encode non ascii characters with an unicode escape sequence
86-
doNotEscapeSlashes = 0x4, /// do not escape slashes ('/')
83+
none, /// Standard parsing and encoding
84+
specialFloatLiterals = 0x1, /// Encode NaN and Inf float values as strings
85+
escapeNonAsciiChars = 0x2, /// Encode non-ASCII characters with a Unicode escape sequence
86+
doNotEscapeSlashes = 0x4, /// Do not escape slashes ('/')
8787
strictParsing = 0x8, /// Strictly follow RFC-8259 grammar when parsing
8888
}
8989

9090
/**
91-
JSON type enumeration
91+
Enumeration of JSON types
9292
*/
9393
enum JSONType : byte
9494
{
@@ -275,7 +275,7 @@ struct JSONValue
275275
* Value getter/setter for `JSONType.object`.
276276
* Throws: `JSONException` for read access if `type` is not
277277
* `JSONType.object`.
278-
* Note: this is @system because of the following pattern:
278+
* Note: This is @system because of the following pattern:
279279
---
280280
auto a = &(json.object());
281281
json.uinteger = 0; // overwrite AA pointer
@@ -297,9 +297,11 @@ struct JSONValue
297297

298298
/***
299299
* Value getter for `JSONType.object`.
300-
* Unlike `object`, this retrieves the object by value and can be used in @safe code.
300+
* Unlike `object`, this retrieves the object by value
301+
* and can be used in @safe code.
301302
*
302-
* A caveat is that, if the returned value is null, modifications will not be visible:
303+
* One possible caveat is that, if the returned value is null,
304+
* modifications will not be visible:
303305
* ---
304306
* JSONValue json;
305307
* json.object = null;
@@ -321,7 +323,7 @@ struct JSONValue
321323
* Value getter/setter for `JSONType.array`.
322324
* Throws: `JSONException` for read access if `type` is not
323325
* `JSONType.array`.
324-
* Note: this is @system because of the following pattern:
326+
* Note: This is @system because of the following pattern:
325327
---
326328
auto a = &(json.array());
327329
json.uinteger = 0; // overwrite array pointer
@@ -345,8 +347,8 @@ struct JSONValue
345347
* Value getter for `JSONType.array`.
346348
* Unlike `array`, this retrieves the array by value and can be used in @safe code.
347349
*
348-
* A caveat is that, if you append to the returned array, the new values aren't visible in the
349-
* JSONValue:
350+
* One possible caveat is that, if you append to the returned array,
351+
* the new values aren't visible in the `JSONValue`:
350352
* ---
351353
* JSONValue json;
352354
* json.array = [JSONValue("hello")];
@@ -371,9 +373,8 @@ struct JSONValue
371373
}
372374

373375
/***
374-
* Generic type value getter
375376
* A convenience getter that returns this `JSONValue` as the specified D type.
376-
* Note: only numeric, `bool`, `string`, `JSONValue[string]` and `JSONValue[]` types are accepted
377+
* Note: Only numeric types, `bool`, `string`, `JSONValue[string]`, and `JSONValue[]` types are accepted
377378
* Throws: `JSONException` if `T` cannot hold the contents of this `JSONValue`
378379
* `ConvException` in case of integer overflow when converting to `T`
379380
*/
@@ -659,7 +660,7 @@ struct JSONValue
659660
}
660661

661662
/***
662-
* Array syntax for json arrays.
663+
* Array syntax for JSON arrays.
663664
* Throws: `JSONException` if `type` is not `JSONType.array`.
664665
*/
665666
ref inout(JSONValue) opIndex(size_t i) inout pure @safe
@@ -678,7 +679,7 @@ struct JSONValue
678679
}
679680

680681
/***
681-
* Hash syntax for json objects.
682+
* Hash syntax for JSON objects.
682683
* Throws: `JSONException` if `type` is not `JSONType.object`.
683684
*/
684685
ref inout(JSONValue) opIndex(return scope string k) inout pure @safe
@@ -695,10 +696,12 @@ struct JSONValue
695696
}
696697

697698
/***
698-
* Operator sets `value` for element of JSON object by `key`.
699+
* Provides support for index assignments, which sets the
700+
* corresponding value of the JSON object's `key` field to `value`.
699701
*
700-
* If JSON value is null, then operator initializes it with object and then
701-
* sets `value` for it.
702+
* If the `JSONValue` is `JSONType.null_`, then this function
703+
* initializes it with a JSON object and then performs
704+
* the index assignment.
702705
*
703706
* Throws: `JSONException` if `type` is not `JSONType.object`
704707
* or `JSONType.null_`.
@@ -777,12 +780,12 @@ struct JSONValue
777780
}
778781

779782
/**
780-
* Support for the `in` operator.
783+
* Provides support for the `in` operator.
781784
*
782-
* Tests wether a key can be found in an object.
785+
* Tests whether a key can be found in an object.
783786
*
784787
* Returns:
785-
* when found, the `inout(JSONValue)*` that matches to the key,
788+
* When found, the `inout(JSONValue)*` that matches to the key,
786789
* otherwise `null`.
787790
*
788791
* Throws: `JSONException` if the right hand side argument `JSONType`

std/socket.d

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -181,16 +181,13 @@ string formatSocketError(int err) @trusted
181181
return "Socket error " ~ to!string(err);
182182
}
183183

184-
/// Retrieve the error message for the most recently encountered network error.
184+
/// Returns the error message of the most recently encountered network error.
185185
@property string lastSocketError()
186186
{
187187
return formatSocketError(_lasterr());
188188
}
189189

190-
/**
191-
* Socket exceptions representing network errors reported by the operating
192-
* system.
193-
*/
190+
/// Socket exception representing network errors reported by the operating system.
194191
class SocketOSException: SocketException
195192
{
196193
int errorCode; /// Platform-specific error code.
@@ -234,14 +231,14 @@ class SocketOSException: SocketException
234231
}
235232
}
236233

237-
/// Socket exceptions representing invalid parameters specified by user code.
234+
/// Socket exception representing invalid parameters specified by user code.
238235
class SocketParameterException: SocketException
239236
{
240237
mixin basicExceptionCtors;
241238
}
242239

243240
/**
244-
* Socket exceptions representing attempts to use network capabilities not
241+
* Socket exception representing attempts to use network capabilities not
245242
* available on the current system.
246243
*/
247244
class SocketFeatureException: SocketException
@@ -254,7 +251,7 @@ class SocketFeatureException: SocketException
254251
* Returns:
255252
* `true` if the last socket operation failed because the socket
256253
* was in non-blocking mode and the operation would have blocked,
257-
* or if the socket is in blocking mode and set a SNDTIMEO or RCVTIMEO,
254+
* or if the socket is in blocking mode and set a `SNDTIMEO` or `RCVTIMEO`,
258255
* and the operation timed out.
259256
*/
260257
bool wouldHaveBlocked() nothrow @nogc
@@ -334,7 +331,7 @@ shared static ~this() @system nothrow @nogc
334331
enum AddressFamily: ushort
335332
{
336333
UNSPEC = AF_UNSPEC, /// Unspecified address family
337-
UNIX = AF_UNIX, /// Local communication
334+
UNIX = AF_UNIX, /// Local communication (Unix socket)
338335
INET = AF_INET, /// Internet Protocol version 4
339336
IPX = AF_IPX, /// Novell IPX
340337
APPLETALK = AF_APPLETALK, /// AppleTalk
@@ -374,7 +371,7 @@ enum ProtocolType: int
374371

375372

376373
/**
377-
* `Protocol` is a class for retrieving protocol information.
374+
* Class for retrieving protocol information.
378375
*
379376
* Example:
380377
* ---
@@ -473,7 +470,7 @@ version (CRuntime_Bionic) {} else
473470

474471

475472
/**
476-
* `Service` is a class for retrieving service information.
473+
* Class for retrieving service information.
477474
*
478475
* Example:
479476
* ---
@@ -618,7 +615,7 @@ class HostException: SocketOSException
618615
}
619616

620617
/**
621-
* `InternetHost` is a class for resolving IPv4 addresses.
618+
* Class for resolving IPv4 addresses.
622619
*
623620
* Consider using `getAddress`, `parseAddress` and `Address` methods
624621
* instead of using this class directly.
@@ -1220,7 +1217,7 @@ class AddressException: SocketOSException
12201217

12211218

12221219
/**
1223-
* `Address` is an abstract class for representing a socket addresses.
1220+
* Abstract class for representing a socket address.
12241221
*
12251222
* Example:
12261223
* ---
@@ -1402,7 +1399,7 @@ abstract class Address
14021399
}
14031400

14041401
/**
1405-
* `UnknownAddress` encapsulates an unknown socket address.
1402+
* Encapsulates an unknown socket address.
14061403
*/
14071404
class UnknownAddress: Address
14081405
{
@@ -1431,7 +1428,7 @@ public:
14311428

14321429

14331430
/**
1434-
* `UnknownAddressReference` encapsulates a reference to an arbitrary
1431+
* Encapsulates a reference to an arbitrary
14351432
* socket address.
14361433
*/
14371434
class UnknownAddressReference: Address
@@ -1474,8 +1471,7 @@ public:
14741471

14751472

14761473
/**
1477-
* `InternetAddress` encapsulates an IPv4 (Internet Protocol version 4)
1478-
* socket address.
1474+
* Encapsulates an IPv4 (Internet Protocol version 4) socket address.
14791475
*
14801476
* Consider using `getAddress`, `parseAddress` and `Address` methods
14811477
* instead of using this class directly.
@@ -1624,7 +1620,8 @@ public:
16241620
}
16251621

16261622
/**
1627-
* Compares with another InternetAddress of same type for equality
1623+
* Provides support for comparing equality with another
1624+
* InternetAddress of the same type.
16281625
* Returns: true if the InternetAddresses share the same address and
16291626
* port number.
16301627
*/
@@ -1728,8 +1725,7 @@ public:
17281725

17291726

17301727
/**
1731-
* `Internet6Address` encapsulates an IPv6 (Internet Protocol version 6)
1732-
* socket address.
1728+
* Encapsulates an IPv6 (Internet Protocol version 6) socket address.
17331729
*
17341730
* Consider using `getAddress`, `parseAddress` and `Address` methods
17351731
* instead of using this class directly.
@@ -1913,8 +1909,8 @@ version (StdDdoc)
19131909
}
19141910

19151911
/**
1916-
* `UnixAddress` encapsulates an address for a Unix domain socket
1917-
* (`AF_UNIX`), i.e. a socket bound to a path name in the file system.
1912+
* Encapsulates an address for a Unix domain socket (`AF_UNIX`),
1913+
* i.e. a socket bound to a path name in the file system.
19181914
* Available only on supported systems.
19191915
*
19201916
* Linux also supports an abstract address namespace, in which addresses
@@ -2111,7 +2107,7 @@ static if (is(sockaddr_un))
21112107

21122108

21132109
/**
2114-
* Class for exceptions thrown by `Socket.accept`.
2110+
* Exception thrown by `Socket.accept`.
21152111
*/
21162112
class SocketAcceptException: SocketOSException
21172113
{
@@ -2127,7 +2123,7 @@ enum SocketShutdown: int
21272123
}
21282124

21292125

2130-
/// Flags may be OR'ed together:
2126+
/// Socket flags that may be OR'ed together:
21312127
enum SocketFlags: int
21322128
{
21332129
NONE = 0, /// no flags specified
@@ -2622,7 +2618,7 @@ enum SocketOption: int
26222618

26232619

26242620
/**
2625-
* `Socket` is a class that creates a network communication endpoint using
2621+
* Class that creates a network communication endpoint using
26262622
* the Berkeley sockets interface.
26272623
*/
26282624
class Socket
@@ -2969,7 +2965,7 @@ public:
29692965

29702966

29712967
/**
2972-
* Returns: the local machine's host name
2968+
* Returns: The local machine's host name
29732969
*/
29742970
static @property string hostName() @trusted // getter
29752971
{
@@ -3518,7 +3514,7 @@ public:
35183514

35193515
/**
35203516
* Can be overridden to support other addresses.
3521-
* Returns: a new `Address` object for the current address family.
3517+
* Returns: A new `Address` object for the current address family.
35223518
*/
35233519
protected Address createAddress() pure nothrow
35243520
{
@@ -3549,7 +3545,7 @@ public:
35493545
}
35503546

35513547

3552-
/// `TcpSocket` is a shortcut class for a TCP Socket.
3548+
/// Shortcut class for a TCP Socket.
35533549
class TcpSocket: Socket
35543550
{
35553551
/// Constructs a blocking TCP Socket.
@@ -3566,7 +3562,7 @@ class TcpSocket: Socket
35663562

35673563

35683564
//shortcut
3569-
/// Constructs a blocking TCP Socket and connects to an `Address`.
3565+
/// Constructs a blocking TCP Socket and connects to the given `Address`.
35703566
this(Address connectTo)
35713567
{
35723568
this(connectTo.addressFamily);
@@ -3575,7 +3571,7 @@ class TcpSocket: Socket
35753571
}
35763572

35773573

3578-
/// `UdpSocket` is a shortcut class for a UDP Socket.
3574+
/// Shortcut class for a UDP Socket.
35793575
class UdpSocket: Socket
35803576
{
35813577
/// Constructs a blocking UDP Socket.

0 commit comments

Comments
 (0)