std.json: use proper block comments

This commit is contained in:
Walter Bright 2017-02-09 12:39:55 -08:00
parent 140aa0da1f
commit 0cc2d6fa35

View file

@ -130,9 +130,11 @@ struct JSONValue
assert(j["language"].type == JSON_TYPE.STRING); assert(j["language"].type == JSON_TYPE.STRING);
} }
/// Value getter/setter for $(D JSON_TYPE.STRING). /***
/// Throws: $(D JSONException) for read access if $(D type) is not * Value getter/setter for $(D JSON_TYPE.STRING).
/// $(D JSON_TYPE.STRING). * Throws: $(D JSONException) for read access if $(D type) is not
* $(D JSON_TYPE.STRING).
*/
@property string str() const pure @trusted @property string str() const pure @trusted
{ {
enforce!JSONException(type == JSON_TYPE.STRING, enforce!JSONException(type == JSON_TYPE.STRING,
@ -158,9 +160,11 @@ struct JSONValue
assert(j["language"].str == "Perl"); assert(j["language"].str == "Perl");
} }
/// Value getter/setter for $(D JSON_TYPE.INTEGER). /***
/// Throws: $(D JSONException) for read access if $(D type) is not * Value getter/setter for $(D JSON_TYPE.INTEGER).
/// $(D JSON_TYPE.INTEGER). * Throws: $(D JSONException) for read access if $(D type) is not
* $(D JSON_TYPE.INTEGER).
*/
@property inout(long) integer() inout pure @safe @property inout(long) integer() inout pure @safe
{ {
enforce!JSONException(type == JSON_TYPE.INTEGER, enforce!JSONException(type == JSON_TYPE.INTEGER,
@ -174,9 +178,11 @@ struct JSONValue
return store.integer; return store.integer;
} }
/// Value getter/setter for $(D JSON_TYPE.UINTEGER). /***
/// Throws: $(D JSONException) for read access if $(D type) is not * Value getter/setter for $(D JSON_TYPE.UINTEGER).
/// $(D JSON_TYPE.UINTEGER). * Throws: $(D JSONException) for read access if $(D type) is not
* $(D JSON_TYPE.UINTEGER).
*/
@property inout(ulong) uinteger() inout pure @safe @property inout(ulong) uinteger() inout pure @safe
{ {
enforce!JSONException(type == JSON_TYPE.UINTEGER, enforce!JSONException(type == JSON_TYPE.UINTEGER,
@ -190,10 +196,12 @@ struct JSONValue
return store.uinteger; return store.uinteger;
} }
/// Value getter/setter for $(D JSON_TYPE.FLOAT). Note that despite /***
/// the name, this is a $(B 64)-bit `double`, not a 32-bit `float`. * Value getter/setter for $(D JSON_TYPE.FLOAT). Note that despite
/// Throws: $(D JSONException) for read access if $(D type) is not * the name, this is a $(B 64)-bit `double`, not a 32-bit `float`.
/// $(D JSON_TYPE.FLOAT). * Throws: $(D JSONException) for read access if $(D type) is not
* $(D JSON_TYPE.FLOAT).
*/
@property inout(double) floating() inout pure @safe @property inout(double) floating() inout pure @safe
{ {
enforce!JSONException(type == JSON_TYPE.FLOAT, enforce!JSONException(type == JSON_TYPE.FLOAT,
@ -207,10 +215,11 @@ struct JSONValue
return store.floating; return store.floating;
} }
/// Value getter/setter for $(D JSON_TYPE.OBJECT). /***
/// Throws: $(D JSONException) for read access if $(D type) is not * Value getter/setter for $(D JSON_TYPE.OBJECT).
/// $(D JSON_TYPE.OBJECT). * Throws: $(D JSONException) for read access if $(D type) is not
/* Note: this is @system because of the following pattern: * $(D JSON_TYPE.OBJECT).
* Note: this is @system because of the following pattern:
--- ---
auto a = &(json.object()); auto a = &(json.object());
json.uinteger = 0; // overwrite AA pointer json.uinteger = 0; // overwrite AA pointer
@ -230,19 +239,21 @@ struct JSONValue
return v; return v;
} }
/// Value getter for $(D JSON_TYPE.OBJECT). /***
/// Unlike $(D object), this retrieves the object by value and can be used in @safe code. * Value getter for $(D JSON_TYPE.OBJECT).
/// * Unlike $(D object), this retrieves the object by value and can be used in @safe code.
/// A caveat is that, if the returned value is null, modifications will not be visible: *
/// --- * A caveat is that, if the returned value is null, modifications will not be visible:
/// JSONValue json; * ---
/// json.object = null; * JSONValue json;
/// json.objectNoRef["hello"] = JSONValue("world"); * json.object = null;
/// assert("hello" !in json.object); * json.objectNoRef["hello"] = JSONValue("world");
/// --- * assert("hello" !in json.object);
/// * ---
/// Throws: $(D JSONException) for read access if $(D type) is not *
/// $(D JSON_TYPE.OBJECT). * Throws: $(D JSONException) for read access if $(D type) is not
* $(D JSON_TYPE.OBJECT).
*/
@property inout(JSONValue[string]) objectNoRef() inout pure @trusted @property inout(JSONValue[string]) objectNoRef() inout pure @trusted
{ {
enforce!JSONException(type == JSON_TYPE.OBJECT, enforce!JSONException(type == JSON_TYPE.OBJECT,
@ -250,10 +261,11 @@ struct JSONValue
return store.object; return store.object;
} }
/// Value getter/setter for $(D JSON_TYPE.ARRAY). /***
/// Throws: $(D JSONException) for read access if $(D type) is not * Value getter/setter for $(D JSON_TYPE.ARRAY).
/// $(D JSON_TYPE.ARRAY). * Throws: $(D JSONException) for read access if $(D type) is not
/* Note: this is @system because of the following pattern: * $(D JSON_TYPE.ARRAY).
* Note: this is @system because of the following pattern:
--- ---
auto a = &(json.array()); auto a = &(json.array());
json.uinteger = 0; // overwrite array pointer json.uinteger = 0; // overwrite array pointer
@ -273,20 +285,22 @@ struct JSONValue
return v; return v;
} }
/// Value getter for $(D JSON_TYPE.ARRAY). /***
/// Unlike $(D array), this retrieves the array by value and can be used in @safe code. * Value getter for $(D JSON_TYPE.ARRAY).
/// * Unlike $(D array), this retrieves the array by value and can be used in @safe code.
/// A caveat is that, if you append to the returned array, the new values aren't visible in the *
/// JSONValue: * A caveat is that, if you append to the returned array, the new values aren't visible in the
/// --- * JSONValue:
/// JSONValue json; * ---
/// json.array = [JSONValue("hello")]; * JSONValue json;
/// json.arrayNoRef ~= JSONValue("world"); * json.array = [JSONValue("hello")];
/// assert(json.array.length == 1); * json.arrayNoRef ~= JSONValue("world");
/// --- * assert(json.array.length == 1);
/// * ---
/// Throws: $(D JSONException) for read access if $(D type) is not *
/// $(D JSON_TYPE.ARRAY). * Throws: $(D JSONException) for read access if $(D type) is not
* $(D JSON_TYPE.ARRAY).
*/
@property inout(JSONValue[]) arrayNoRef() inout pure @trusted @property inout(JSONValue[]) arrayNoRef() inout pure @trusted
{ {
enforce!JSONException(type == JSON_TYPE.ARRAY, enforce!JSONException(type == JSON_TYPE.ARRAY,
@ -450,8 +464,10 @@ struct JSONValue
assignRef(arg); assignRef(arg);
} }
/// Array syntax for json arrays. /***
/// Throws: $(D JSONException) if $(D type) is not $(D JSON_TYPE.ARRAY). * Array syntax for json arrays.
* Throws: $(D JSONException) if $(D type) is not $(D JSON_TYPE.ARRAY).
*/
ref inout(JSONValue) opIndex(size_t i) inout pure @safe ref inout(JSONValue) opIndex(size_t i) inout pure @safe
{ {
auto a = this.arrayNoRef; auto a = this.arrayNoRef;
@ -467,8 +483,10 @@ struct JSONValue
assert( j[1].integer == 43 ); assert( j[1].integer == 43 );
} }
/// Hash syntax for json objects. /***
/// Throws: $(D JSONException) if $(D type) is not $(D JSON_TYPE.OBJECT). * Hash syntax for json objects.
* Throws: $(D JSONException) if $(D type) is not $(D JSON_TYPE.OBJECT).
*/
ref inout(JSONValue) opIndex(string k) inout pure @safe ref inout(JSONValue) opIndex(string k) inout pure @safe
{ {
auto o = this.objectNoRef; auto o = this.objectNoRef;
@ -482,13 +500,15 @@ struct JSONValue
assert( j["language"].str == "D" ); assert( j["language"].str == "D" );
} }
/// Operator sets $(D value) for element of JSON object by $(D key). /***
/// * Operator sets $(D value) for element of JSON object by $(D key).
/// If JSON value is null, then operator initializes it with object and then *
/// sets $(D value) for it. * If JSON value is null, then operator initializes it with object and then
/// * sets $(D value) for it.
/// Throws: $(D JSONException) if $(D type) is not $(D JSON_TYPE.OBJECT) *
/// or $(D JSON_TYPE.NULL). * Throws: $(D JSONException) if $(D type) is not $(D JSON_TYPE.OBJECT)
* or $(D JSON_TYPE.NULL).
*/
void opIndexAssign(T)(auto ref T value, string key) pure void opIndexAssign(T)(auto ref T value, string key) pure
{ {
enforceEx!JSONException(type == JSON_TYPE.OBJECT || type == JSON_TYPE.NULL, enforceEx!JSONException(type == JSON_TYPE.OBJECT || type == JSON_TYPE.NULL,
@ -649,18 +669,22 @@ struct JSONValue
return result; return result;
} }
/// Implicitly calls $(D toJSON) on this JSONValue. /***
/// * Implicitly calls $(D toJSON) on this JSONValue.
/// $(I options) can be used to tweak the conversion behavior. *
* $(I options) can be used to tweak the conversion behavior.
*/
string toString(in JSONOptions options = JSONOptions.none) const @safe string toString(in JSONOptions options = JSONOptions.none) const @safe
{ {
return toJSON(this, false, options); return toJSON(this, false, options);
} }
/// Implicitly calls $(D toJSON) on this JSONValue, like $(D toString), but /***
/// also passes $(I true) as $(I pretty) argument. * Implicitly calls $(D toJSON) on this JSONValue, like $(D toString), but
/// * also passes $(I true) as $(I pretty) argument.
/// $(I options) can be used to tweak the conversion behavior *
* $(I options) can be used to tweak the conversion behavior
*/
string toPrettyString(in JSONOptions options = JSONOptions.none) const @safe string toPrettyString(in JSONOptions options = JSONOptions.none) const @safe
{ {
return toJSON(this, true, options); return toJSON(this, true, options);