Skip to content
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

Give std.json an opEquals #3049

Merged
merged 1 commit into from
Mar 14, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 32 additions & 0 deletions std/json.d
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,38 @@ struct JSONValue
string a = ("author" in j).str;
}

bool opEquals(const JSONValue rhs) const
{
return opEquals(rhs);
}

bool opEquals(ref const JSONValue rhs) const
{
// Default doesn't work well since store is a union. Compare only
// what should be in store.
if (type_tag != rhs.type_tag) return false;

final switch (type_tag)
{
case JSON_TYPE.STRING:
return store.str == rhs.store.str;
case JSON_TYPE.INTEGER:
return store.integer == rhs.store.integer;
case JSON_TYPE.UINTEGER:
return store.uinteger == rhs.store.uinteger;
case JSON_TYPE.FLOAT:
return store.floating == rhs.store.floating;
case JSON_TYPE.OBJECT:
return store.object == rhs.store.object;
case JSON_TYPE.ARRAY:
return store.array == rhs.store.array;
case JSON_TYPE.TRUE:
case JSON_TYPE.FALSE:
case JSON_TYPE.NULL:
return true;
}
}

/// Implements the foreach $(D opApply) interface for json arrays.
int opApply(int delegate(size_t index, ref JSONValue) dg)
{
Expand Down