aslze / asl

A compact C++ cross-platform library including JSON, XML, HTTP, Sockets, WebSockets, threads, processes, logs, file system, CSV, INI files, vectors and matrices, etc.
Other
69 stars 17 forks source link

Map join doesn't getting applied to the levels #23

Closed dezashibi closed 1 year ago

dezashibi commented 1 year ago

consider an Object is Dic<Var> that naturally can have other Objects or Array<Object> as well inside when I use join on the top level and let's say I want ", " and " : " it won't make any difference to the nested objects and it will use the default "," and "=" instead.

P.S. to print out the Object I can use Json::encode which is fine, in some cases join characters might be completely different based on usecases.

aslze commented 1 year ago

Dic::join() only works on one level (key: value, ...). The Dic class knows nothing about nesting. join() converts all keys and values to String, if possible. A value of type Var is just converted to String with its toString() method that does a simple serialization, always using ',', '=' for objects.

Json::encode() and Xdl::encode() are better ways to serialize nested objects, but they have a fixed syntax. Making .join() smarter for the Dic<Var> case would be too complicated. You could look at the Var::toString() function to make new configurable function out of the library.

dezashibi commented 1 year ago

I checked, yes might make it complicated, I will though try to see if I can do something about it and if the solution was good enough to be put in the ASL I will open pull request. thanks.