Forráskód Böngészése

[add] inline empty container
[add] inline collapsed container

isundil 9 éve
szülő
commit
0a4574a1b7

+ 2 - 0
include/jsonArray.hh

@@ -12,5 +12,7 @@ class JSonArray: public JSonContainer, public std::list<JSonElement *>
 
         virtual JSonElement *firstChild();
         virtual const JSonElement *firstChild() const;
+
+        virtual std::string stringify() const;
 };
 

+ 0 - 2
include/jsonContainer.hh

@@ -10,7 +10,5 @@ class JSonContainer: public JSonElement
         virtual unsigned int size() const =0;
         virtual JSonElement *firstChild() =0;
         virtual const JSonElement *firstChild() const =0;
-
-        virtual std::string stringify() const;
 };
 

+ 2 - 0
include/jsonObject.hh

@@ -19,5 +19,7 @@ class JSonObject: public JSonContainer, public std::map<std::string, JSonElement
         virtual const JSonElement *firstChild() const;
 
         const JSonElement* get(const std::string &) const;
+
+        virtual std::string stringify() const;
 };
 

+ 11 - 4
src/curseOutput.cpp

@@ -228,7 +228,8 @@ bool CurseOutput::writeContent(std::pair<int, int> &cursor, const std::pair<int,
     {
         const std::pair<std::string, JSonElement *> ipair = *i;
         cursor.first += indentLevel /2;
-        if (dynamic_cast<const JSonContainer *>(ipair.second) == nullptr)
+        if (dynamic_cast<const JSonContainer *>(ipair.second) == nullptr
+                || ((const JSonContainer *) ipair.second)->size() == 0)
         {
             checkSelection(ipair.second, item);
             write(cursor.first, cursor.second, ipair.first +": " +ipair.second->stringify(), selection == ipair.second);
@@ -236,11 +237,17 @@ bool CurseOutput::writeContent(std::pair<int, int> &cursor, const std::pair<int,
             if (++cursor.second > maxSize.second)
                 return false;
         }
-        else if (collapsed.find((const JSonContainer *)item) != collapsed.end())
+        else if (collapsed.find((const JSonContainer *)ipair.second) != collapsed.end())
         {
-            //TODO test this
+            char childDelimiter[2];
+            if (dynamic_cast<const JSonObject *>(ipair.second))
+                memcpy(childDelimiter, "{}", sizeof(*childDelimiter) * 2);
+            else
+                memcpy(childDelimiter, "[]", sizeof(*childDelimiter) * 2);
+            std::string ss = ipair.first;
+            ss.append(": ").append(&childDelimiter[0], 1).append(" ... ").append(&childDelimiter[1], 1);
             checkSelection(ipair.second, item);
-            write(cursor.first, cursor.second, ipair.first +"_: ...", selection == ipair.second);
+            write(cursor.first, cursor.second, ss, selection == ipair.second);
             cursor.first -= indentLevel /2;
             if (++cursor.second > maxSize.second)
                 return false;

+ 5 - 0
src/jsonArray.cpp

@@ -30,3 +30,8 @@ const JSonElement *JSonArray::firstChild() const
     return *cbegin();
 }
 
+std::string JSonArray::stringify() const
+{
+    return "[ ]";
+}
+

+ 0 - 5
src/jsonContainer.cpp

@@ -6,8 +6,3 @@ JSonContainer::JSonContainer(JSonContainer *p):JSonElement(p)
 JSonContainer::~JSonContainer()
 { }
 
-std::string JSonContainer::stringify() const
-{
-    return std::string();
-}
-

+ 5 - 0
src/jsonObject.cpp

@@ -47,3 +47,8 @@ const JSonElement *JSonObject::firstChild() const
     return (*cbegin()).second;
 }
 
+std::string JSonObject::stringify() const
+{
+    return "{ }";
+}
+