mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2025-03-19 18:47:14 +01:00
Compare commits
No commits in common. "52cfa235be3e992faed75d181f5694bf016b6526" and "a788e059a59fd86306c759d76135934013972c94" have entirely different histories.
52cfa235be
...
a788e059a5
@ -2,7 +2,6 @@
|
|||||||
#include "Library/JSON.hpp"
|
#include "Library/JSON.hpp"
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
#include <sajson.h>
|
|
||||||
#include <sqratConst.h>
|
#include <sqratConst.h>
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
@ -181,23 +180,6 @@ CtxJSON & CtxJSON::CloseArray()
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
|
||||||
CtxJSON & CtxJSON::ReopenArray()
|
|
||||||
{
|
|
||||||
// If the last character is a comma then remove it
|
|
||||||
if (mOutput.back() == ',')
|
|
||||||
{
|
|
||||||
mOutput.pop_back();
|
|
||||||
}
|
|
||||||
// If the last character is the array-end character then replace it with a comma
|
|
||||||
if (mOutput.back() == ']')
|
|
||||||
{
|
|
||||||
mOutput.back() = ',';
|
|
||||||
}
|
|
||||||
// Allow chaining
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
CtxJSON & CtxJSON::OpenObject()
|
CtxJSON & CtxJSON::OpenObject()
|
||||||
{
|
{
|
||||||
@ -230,23 +212,6 @@ CtxJSON & CtxJSON::CloseObject()
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
|
||||||
CtxJSON & CtxJSON::ReopenObject()
|
|
||||||
{
|
|
||||||
// If the last character is a comma then remove it
|
|
||||||
if (mOutput.back() == ',')
|
|
||||||
{
|
|
||||||
mOutput.pop_back();
|
|
||||||
}
|
|
||||||
// If the last character is the object-end character then replace it with a comma
|
|
||||||
if (mOutput.back() == '}')
|
|
||||||
{
|
|
||||||
mOutput.back() = ',';
|
|
||||||
}
|
|
||||||
// Allow chaining
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
CtxJSON & CtxJSON::MakeKey()
|
CtxJSON & CtxJSON::MakeKey()
|
||||||
{
|
{
|
||||||
@ -260,11 +225,6 @@ CtxJSON & CtxJSON::MakeKey()
|
|||||||
{
|
{
|
||||||
mOutput.push_back(':');
|
mOutput.push_back(':');
|
||||||
}
|
}
|
||||||
// Allow the hook to react
|
|
||||||
if (mKeyHook)
|
|
||||||
{
|
|
||||||
mKeyHook(*this);
|
|
||||||
}
|
|
||||||
// Allow chaining
|
// Allow chaining
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@ -507,7 +467,7 @@ SQRESULT CtxJSON::SerializeTable(HSQUIRRELVM vm, SQInteger idx) // NOLINT(misc-n
|
|||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
SQRESULT CtxJSON::SerializeInstance(HSQUIRRELVM vm, SQInteger idx)
|
SQRESULT CtxJSON::SerializeInstance(HSQUIRRELVM vm, SQInteger idx)
|
||||||
{
|
{
|
||||||
sq_pushstring(vm, mMetaMethod.c_str(), static_cast< SQInteger >(mMetaMethod.size()));
|
sq_pushstring(vm, _SC("_tojson"), 7);
|
||||||
// Attempt to retrieve the meta-method from the instance
|
// Attempt to retrieve the meta-method from the instance
|
||||||
if(SQRESULT r = sq_get(vm, idx); SQ_FAILED(r))
|
if(SQRESULT r = sq_get(vm, idx); SQ_FAILED(r))
|
||||||
{
|
{
|
||||||
@ -669,8 +629,6 @@ void CtxJSON::PushString(const SQChar * str)
|
|||||||
mOutput.append(str);
|
mOutput.append(str);
|
||||||
mOutput.push_back('"');
|
mOutput.push_back('"');
|
||||||
mOutput.push_back(',');
|
mOutput.push_back(',');
|
||||||
// Allow the hook to know
|
|
||||||
mString.assign(str);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
@ -680,8 +638,6 @@ void CtxJSON::PushString(const SQChar * str, size_t length)
|
|||||||
mOutput.append(str, length);
|
mOutput.append(str, length);
|
||||||
mOutput.push_back('"');
|
mOutput.push_back('"');
|
||||||
mOutput.push_back(',');
|
mOutput.push_back(',');
|
||||||
// Allow the hook to know
|
|
||||||
mString.assign(str, length);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
@ -722,7 +678,6 @@ void Register_JSON(HSQUIRRELVM vm)
|
|||||||
// Constructors
|
// Constructors
|
||||||
.Ctor()
|
.Ctor()
|
||||||
.Ctor< bool >()
|
.Ctor< bool >()
|
||||||
.Ctor< bool, StackStrF & >()
|
|
||||||
// Meta-methods
|
// Meta-methods
|
||||||
.SquirrelFunc(_SC("_typename"), &SqCtxJSON::Fn)
|
.SquirrelFunc(_SC("_typename"), &SqCtxJSON::Fn)
|
||||||
// Properties
|
// Properties
|
||||||
|
@ -5,13 +5,12 @@
|
|||||||
#include "Library/IO/Buffer.hpp"
|
#include "Library/IO/Buffer.hpp"
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
#include <functional>
|
#include <sajson.h>
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
|
||||||
#include <fmt/args.h>
|
#include <fmt/args.h>
|
||||||
#include <fmt/format.h>
|
#include <fmt/format.h>
|
||||||
#include <fmt/xchar.h>
|
#include <fmt/xchar.h>
|
||||||
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
namespace SqMod {
|
namespace SqMod {
|
||||||
|
|
||||||
@ -36,55 +35,20 @@ struct CtxJSON
|
|||||||
*/
|
*/
|
||||||
uint32_t mDepth{0};
|
uint32_t mDepth{0};
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
|
||||||
* The meta-method name to use on objects.
|
|
||||||
*/
|
|
||||||
String mMetaMethod{"_tojson"};
|
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
|
||||||
* Last pushed string value. Can be used to heck for key name in the hook.
|
|
||||||
*/
|
|
||||||
String mString{};
|
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
|
||||||
* Internal utility used to monitor the existence of certain keys to allow overloading.
|
|
||||||
*/
|
|
||||||
std::function< void(CtxJSON&) > mKeyHook{};
|
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
/* --------------------------------------------------------------------------------------------
|
||||||
* Default constructor.
|
* Default constructor.
|
||||||
*/
|
*/
|
||||||
CtxJSON() = default;
|
CtxJSON() noexcept = default;
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
/* --------------------------------------------------------------------------------------------
|
||||||
* Explicit constructor.
|
* Explicit constructor.
|
||||||
*/
|
*/
|
||||||
explicit CtxJSON(bool ooa)
|
explicit CtxJSON(bool ooa) noexcept
|
||||||
: CtxJSON()
|
: CtxJSON()
|
||||||
{
|
{
|
||||||
mObjectOverArray = ooa;
|
mObjectOverArray = ooa;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
|
||||||
* Explicit constructor.
|
|
||||||
*/
|
|
||||||
CtxJSON(bool ooa, StackStrF & mmname)
|
|
||||||
: CtxJSON()
|
|
||||||
{
|
|
||||||
mObjectOverArray = ooa;
|
|
||||||
// Allow custom metamethod names
|
|
||||||
mMetaMethod.assign(mmname.mPtr, static_cast< size_t >(mmname.mLen));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
|
||||||
* Internal constructor.
|
|
||||||
*/
|
|
||||||
explicit CtxJSON(std::function< void(CtxJSON&) > && kh)
|
|
||||||
: CtxJSON()
|
|
||||||
{
|
|
||||||
mKeyHook = std::move(kh);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
/* --------------------------------------------------------------------------------------------
|
||||||
* Copy constructor.
|
* Copy constructor.
|
||||||
*/
|
*/
|
||||||
@ -171,11 +135,6 @@ struct CtxJSON
|
|||||||
*/
|
*/
|
||||||
CtxJSON & CloseArray();
|
CtxJSON & CloseArray();
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
|
||||||
* Resume writing an array.
|
|
||||||
*/
|
|
||||||
CtxJSON & ReopenArray();
|
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
/* --------------------------------------------------------------------------------------------
|
||||||
* Begin writing an object.
|
* Begin writing an object.
|
||||||
*/
|
*/
|
||||||
@ -186,11 +145,6 @@ struct CtxJSON
|
|||||||
*/
|
*/
|
||||||
CtxJSON & CloseObject();
|
CtxJSON & CloseObject();
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
|
||||||
* Resume writing an object.
|
|
||||||
*/
|
|
||||||
CtxJSON & ReopenObject();
|
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
/* --------------------------------------------------------------------------------------------
|
||||||
* Begin writing a key value.
|
* Begin writing a key value.
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user