#11104: [PATCH] JSON parser ----------------------------+---------------------------- Reporter: waddlesplash | Owner: stippi Type: enhancement | Status: assigned Priority: normal | Milestone: R1 Component: Kits | Version: R1/Development Resolution: | Keywords: Blocked By: | Blocking: Has a Patch: 1 | Platform: All ----------------------------+---------------------------- Comment (by stippi): Thanks for the code! It looks like it gets the job done. There is some code with regards to handling null, true, false which looks like it could somehow be refactored to eliminate the repeating code. The code like this: {{{ case 't': { if (builder.What() != JSON_TYPE_ARRAY && key.Length() == 0) return B_BAD_DATA; // 'true' cannot be a key, it can only be a value BString value; JSON.CopyInto(value, (int32)pos, 4); if (value == "true") { if (builder.What() == JSON_TYPE_ARRAY) key.SetToFormat("%zu", builder.CountNames()); builder.AddBool(key.String(), true); key = ""; pos += 3; } else return B_BAD_DATA; // "t" out in the middle of nowhere!? break; } }}} should end up looking like this: {{{ case 't': if (_ParseConstant("true", JSON, &pos, builder, key)) { builder.AddBool(key.String(), true); key = ""; } else { return B_BAD_DATA; } break; }}} That you constantly have to reset "key" is also not so nice, but I have no better idea right now except to move the key adding into a templated method and change the MessageBuilder methods to all have the same name: {{{ template<typename DataType> void BJson::_AddKey(MessageBuilder& builder, BString& key, const DataType& dataType) { builder.AddData(key.String(), dataType); key = ""; } }}} And I am a bit sad you did not use my suggestion of the generic and abstract ObjectBuilder with MessageBuilder being the only concrete implementation of it for now. -- Ticket URL: <https://dev.haiku-os.org/ticket/11104#comment:11> Haiku <https://dev.haiku-os.org> Haiku - the operating system.