diff options
author | JamesTheMaker <jamesthemaker2005@gmail.com> | 2024-03-07 09:43:36 -0500 |
---|---|---|
committer | JamesTheMaker <jamesthemaker2005@gmail.com> | 2024-03-07 09:43:36 -0500 |
commit | 14ec64ace75c83238ee9f81fe4ea4c3c9eed09fb (patch) | |
tree | 0cbaa87de247dc914be8a7d5dc7e0540d976c16b /source/core/StarJson.cpp | |
parent | f1e3f6791d18f82e662a54ea407b5e5495e18a30 (diff) |
Added `jsonCompare` function
Diffstat (limited to 'source/core/StarJson.cpp')
-rw-r--r-- | source/core/StarJson.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/source/core/StarJson.cpp b/source/core/StarJson.cpp index 3feaf37..ed0e48f 100644 --- a/source/core/StarJson.cpp +++ b/source/core/StarJson.cpp @@ -1035,4 +1035,34 @@ Json jsonMerge(Json const& base, Json const& merger) { } } +bool jsonCompare(Json const& base, Json const& compare) { + if (base == compare) { + return true; + } else { + if (base.type() == Json::Type::Object && compare.type() == Json::Type::Object) { + for (auto const& c : compare.toObject()) { + if (!base.contains(c.first) || !jsonCompare(base.get(c.first), c.second)) + return false; + } + return true; + } + if (base.type() == Json::Type::Array && compare.type() == Json::Type::Array) { + for (auto const& c : compare.toArray()) { + bool similar = false; + for (auto const& b : base.toArray()) { + if (jsonCompare(c, b)) { + similar = true; + break; + } + } + if (!similar) + return false; + } + return true; + } + + return false; + } +} + }
\ No newline at end of file |