1 Star 0 Fork 10

chenjialong/lshw

forked from src-openEuler/lshw 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
lshw-B.02.18-revert-json.patch 1.78 KB
一键复制 编辑 原始数据 按行查看 历史
hexiaowen 提交于 2019-09-30 11:02 . Package init
commit 135a853c60582b14c5b67e5cd988a8062d9896f4
Author: Lyonel Vincent <lyonel@ezix.org>
Date: Fri Apr 28 16:54:42 2017 +0200
Fix JSON output format
cf. https://github.com/lyonel/lshw/pull/28
diff --git a/src/core/hw.cc b/src/core/hw.cc
index 68e5912..9defd26 100644
--- a/src/core/hw.cc
+++ b/src/core/hw.cc
@@ -1368,9 +1368,14 @@ string hwNode::asJSON(unsigned level)
config = getConfigKeys();
resources = getResources("\" value=\"");
+ if (level == 0)
+ {
+ out << "[" << endl;
+ }
+
if(visible(getClassName()))
{
- out << "{" << endl;
+ out << spaces(2*level) << "{" << endl;
out << spaces(2*level+2) << "\"id\" : \"" << getId() << "\"," << endl;
out << spaces(2*level+2) << "\"class\" : \"" << getClassName() << "\"";
@@ -1613,20 +1618,13 @@ string hwNode::asJSON(unsigned level)
resources.clear();
}
-
- if(countChildren()>0)
+ for (unsigned int i = 0; i < countChildren(); i++)
{
- if(visible(getClassName()))
- out << "," << endl << spaces(2*level+2) << "\"children\" : [" << endl;
-
- for (unsigned int i = 0; i < countChildren(); i++)
+ out << getChild(i)->asJSON(visible(getClassName()) ? level + 2 : 1);
+ if (visible(getChild(i)->getClassName()))
{
- out << spaces(2*level+4) << getChild(i)->asJSON(visible(getClassName()) ? level + 2 : 1);
- if(visible(getChild(i)->getClassName()) && (i < countChildren()-1)) out << "," << endl;
+ out << "," << endl;
}
-
- if(visible(getClassName()))
- out << endl << spaces(2*level+2) << "]";
}
if(visible(getClassName()))
@@ -1635,6 +1633,12 @@ string hwNode::asJSON(unsigned level)
out << "}";
}
+ if (level == 0)
+ {
+ out.seekp(-2, std::ios_base::end);
+ out << endl << "]" << endl;
+ }
+
return out.str();
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/pecs/lshw.git
git@gitee.com:pecs/lshw.git
pecs
lshw
lshw
master

搜索帮助