---------------------------------------------------------------------------
| 239 | |
| 240 | //--------------------------------------------------------------------------- |
| 241 | string To_JSON_Elements(Node& Cur_Node, const int& Level, bool Indent, bool Carriage_Returns) |
| 242 | { |
| 243 | string Result; |
| 244 | |
| 245 | for (size_t Pos=0; Pos<Cur_Node.Childs.size(); Pos++) |
| 246 | { |
| 247 | if (!Cur_Node.Childs[Pos]) |
| 248 | continue; |
| 249 | |
| 250 | if (!Cur_Node.Childs[Pos]->RawContent.empty()) |
| 251 | { |
| 252 | if (Level && Carriage_Returns) |
| 253 | Result+='\n'; |
| 254 | Result+=Cur_Node.Childs[Pos]->RawContent; |
| 255 | |
| 256 | delete Cur_Node.Childs[Pos]; |
| 257 | Cur_Node.Childs[Pos]=NULL; |
| 258 | |
| 259 | continue; |
| 260 | } |
| 261 | |
| 262 | if (Cur_Node.Name.empty()) |
| 263 | continue; |
| 264 | |
| 265 | Result+=(Carriage_Returns?("\n"+(Indent?string(Level, '\t'):string())):string())+"\""+Cur_Node.Childs[Pos]->Name+(Carriage_Returns?"\": ":"\":"); |
| 266 | |
| 267 | bool Multiple=Cur_Node.Childs[Pos]->Multiple; |
| 268 | if (Multiple) |
| 269 | { |
| 270 | Result+='['; |
| 271 | if (Carriage_Returns) |
| 272 | Result+='\n'; |
| 273 | } |
| 274 | |
| 275 | string Name=Cur_Node.Childs[Pos]->Name; |
| 276 | for (size_t Pos2=Pos; Pos2<Cur_Node.Childs.size() && Cur_Node.Childs[Pos2]->Name==Name; Pos2++) |
| 277 | { |
| 278 | if (!Cur_Node.Childs[Pos2]) |
| 279 | continue; |
| 280 | |
| 281 | if (Cur_Node.Childs[Pos2]->Attrs.empty() && Cur_Node.Childs[Pos2]->Childs.empty() && !Cur_Node.Childs[Pos2]->Multiple) |
| 282 | { |
| 283 | if (Cur_Node.Childs[Pos2]->Value.empty()) |
| 284 | Result+="null"; |
| 285 | else |
| 286 | Result+="\""+JSON_Encode(Cur_Node.Childs[Pos2]->Value)+"\""; |
| 287 | } |
| 288 | else |
| 289 | { |
| 290 | Result+=(Indent?string(Level+1, '\t'):string())+"{"; |
| 291 | Result+=To_JSON_Attributes(*Cur_Node.Childs[Pos2], Level+2, Indent, Carriage_Returns); |
| 292 | Result+=To_JSON_Elements(*Cur_Node.Childs[Pos2], Level+2, Indent, Carriage_Returns); |
| 293 | if (Carriage_Returns) |
| 294 | Result+='\n'; |
| 295 | |
| 296 | if(!Cur_Node.Childs[Pos2]->Value.empty()) |
| 297 | { |
| 298 | Result+=(Indent?string(Level+2, '\t'):string())+(Carriage_Returns?"\"#value\": \"":"\"#value\":\"")+JSON_Encode(Cur_Node.Childs[Pos2]->Value)+'\"'; |
no test coverage detected