代码编程规范整改

Signed-off-by: chencheng31 <chencheng8@huawei.com>
This commit is contained in:
chencheng31
2022-02-28 20:38:41 +08:00
parent 85495a1b20
commit ecced2ebc7
22 changed files with 80 additions and 113 deletions
+3 -20
View File
@@ -7,9 +7,9 @@ OpenHarmony resource compile tool
>developtools/
>>----global_resource_tool
>>>----include
>>>----src
>>>----third_party denpence third patry lib make script
>>>----CMakeLists.txt
>>>----src
>>>----third_party denpence third patry lib make script
>>>----CMakeLists.txt
>>>----win32.cmake windows cross compile script
#### Installation
@@ -26,20 +26,3 @@ OpenHarmony resource compile tool
1. restool -v show version.
2. restool show help.
#### Contribution
1. Fork the repository
2. Create Feat_xxx branch
3. Commit your code
4. Create Pull Request
#### Gitee Feature
1. You can use Readme\_XXX.md to support different languages, such as Readme\_en.md, Readme\_zh.md
2. Gitee blog [blog.gitee.com](https://blog.gitee.com)
3. Explore open source project [https://gitee.com/explore](https://gitee.com/explore)
4. The most valuable open source project [GVP](https://gitee.com/gvp)
5. The manual of Gitee [https://gitee.com/help](https://gitee.com/help)
6. The most popular members [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)
+3 -20
View File
@@ -7,9 +7,9 @@ OpenHarmony 资源编译编译工具
>developtools/
>>----global_resource_tool
>>>----include
>>>----src
>>>----third_party 依赖三方库编译脚本
>>>----CMakeLists.txt
>>>----src
>>>----third_party 依赖三方库编译脚本
>>>----CMakeLists.txt
>>>----win32.cmake windows交叉编译脚本
@@ -27,20 +27,3 @@ OpenHarmony 资源编译编译工具
1. restool -v 显示版本信息
2. restool 显示帮助信息
#### 参与贡献
1. Fork 本仓库
2. 新建 Feat_xxx 分支
3. 提交代码
4. 新建 Pull Request
#### 特技
1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md
2. Gitee 官方博客 [blog.gitee.com](https://blog.gitee.com)
3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解 Gitee 上的优秀开源项目
4. [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目
5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help)
6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)
+4 -2
View File
@@ -28,8 +28,10 @@ public:
private:
typedef bool (*parse_key_founction)(const std::string &folderName, std::vector<KeyParam> &keyparams);
static bool ParseMatch(const std::vector<std::string> &keys, std::vector<KeyParam> &keyparams, const std::vector<parse_key_founction> &founctions);
static bool ParseMatchBySeq(const std::vector<std::string> &keys, std::vector<KeyParam> &keyparams, const std::vector<parse_key_founction> &founctions);
static bool ParseMatch(const std::vector<std::string> &keys,
std::vector<KeyParam> &keyparams, const std::vector<parse_key_founction> &founctions);
static bool ParseMatchBySeq(const std::vector<std::string> &keys,
std::vector<KeyParam> &keyparams, const std::vector<parse_key_founction> &founctions);
static bool ParseMccMnc(const std::string &folderName, std::vector<KeyParam> &keyparams);
static bool ParseMcc(const std::string &folderName, std::vector<KeyParam> &keyparams);
-1
View File
@@ -24,7 +24,6 @@
namespace OHOS {
namespace Global {
namespace Restool {
class ResourceUtil {
public:
/**
-1
View File
@@ -21,7 +21,6 @@
namespace OHOS {
namespace Global {
namespace Restool {
class TaskHandle {
public:
TaskHandle() {};
+1 -1
View File
@@ -302,7 +302,7 @@ uint32_t PackageParser::ParseCommand(int argc, char *argv[])
restoolPath_ = string(argv[0]);
while (true) {
int optIndex = 0;
int c = getopt_long(argc, argv, CMD_PARAMS.c_str(), CMD_OPTS,&optIndex);
int c = getopt_long(argc, argv, CMD_PARAMS.c_str(), CMD_OPTS, &optIndex);
if (c == -1) {
break;
}
+2 -2
View File
@@ -45,12 +45,12 @@ const map<string, string> ConfigParser::JSON_ARRAY_IDS = {
bool ConfigParser::useModule_ = false;
ConfigParser::ConfigParser()
: filePath_("") ,packageName_("") ,moduleName_(""), moduleType_(ModuleType::NONE)
: filePath_(""), packageName_(""), moduleName_(""), moduleType_(ModuleType::NONE)
{
}
ConfigParser::ConfigParser(const string &filePath)
: filePath_(filePath) ,packageName_("") ,moduleName_(""), moduleType_(ModuleType::NONE)
: filePath_(filePath), packageName_(""), moduleName_(""), moduleType_(ModuleType::NONE)
{
}
+1 -1
View File
@@ -52,7 +52,7 @@ uint32_t FileManager::ScanIncrement(const string &output)
return ParseReference(output, sxmlFolders);
}
//below private founction
// below private founction
uint32_t FileManager::ScanModule(const string &input, const string &output,
map<ResType, vector<DirectoryInfo>> &resTypeOfDirs)
{
+1 -1
View File
@@ -16,8 +16,8 @@
#include "generic_compiler.h"
#include<filesystem>
#include<iostream>
#include "restool_errors.h"
#include "resource_util.h"
#include "restool_errors.h"
namespace OHOS {
namespace Global {
+1 -1
View File
@@ -16,8 +16,8 @@
#include "header.h"
#include<algorithm>
#include<fstream>
#include<iostream>
#include<iomanip>
#include<iostream>
namespace OHOS {
namespace Global {
+5 -5
View File
@@ -173,11 +173,11 @@ uint32_t IdWorker::InitIdDefined()
string idDefinedPath;
if (type_ == ResourceIdCluster::RES_ID_SYS) {
for (const auto &inputPath : packageParser.GetInputs()) {
idDefinedPath = filesystem::path(inputPath).append(RESOURCES_DIR)
.append("base").append("element").append(ID_DEFINED_FILE).string();
if (InitIdDefined(idDefinedPath) != RESTOOL_SUCCESS) {
return RESTOOL_ERROR;
}
idDefinedPath = filesystem::path(inputPath).append(RESOURCES_DIR)
.append("base").append("element").append(ID_DEFINED_FILE).string();
if (InitIdDefined(idDefinedPath) != RESTOOL_SUCCESS) {
return RESTOOL_ERROR;
}
}
return RESTOOL_SUCCESS;
}
+7 -7
View File
@@ -76,7 +76,7 @@ uint32_t JsonCompiler::CompileSingleFile(const FileInfo &fileInfo)
return RESTOOL_SUCCESS;
}
//below private
// below private
void JsonCompiler::InitParser()
{
using namespace placeholders;
@@ -169,12 +169,12 @@ bool JsonCompiler::HandleBoolean(const Json::Value &objectNode, ResourceItem &re
{
Json::Value valueNode = objectNode[TAG_VALUE];
if (valueNode.isString()) {
regex ref("^\\$boolean:.*");
if (!regex_match(valueNode.asString(), ref)) {
cerr << "Error: '" << valueNode.asString() << "' only refer '$boolean:xxx',";
cerr << resourceItem.GetFilePath() << endl;
return false;
}
regex ref("^\\$boolean:.*");
if (!regex_match(valueNode.asString(), ref)) {
cerr << "Error: '" << valueNode.asString() << "' only refer '$boolean:xxx',";
cerr << resourceItem.GetFilePath() << endl;
return false;
}
} else if (!valueNode.isBool()) {
cerr << "Error: '" << resourceItem.GetName() << "' value not boolean," << resourceItem.GetFilePath() << endl;
return false;
+4 -2
View File
@@ -51,7 +51,8 @@ bool KeyParser::Parse(const string &folderName, vector<KeyParam> &keyparams)
return true;
}
bool KeyParser::ParseMatch(const vector<string> &keys, vector<KeyParam> &keyparams, const vector<parse_key_founction> &founctions)
bool KeyParser::ParseMatch(const vector<string> &keys,
vector<KeyParam> &keyparams, const vector<parse_key_founction> &founctions)
{
size_t next = 0;
for (const auto &key : keys) {
@@ -71,7 +72,8 @@ bool KeyParser::ParseMatch(const vector<string> &keys, vector<KeyParam> &keypara
return true;
}
bool KeyParser::ParseMatchBySeq(const vector<string> &keys, vector<KeyParam> &keyparams, const vector<parse_key_founction> &founctions)
bool KeyParser::ParseMatchBySeq(const vector<string> &keys,
vector<KeyParam> &keyparams, const vector<parse_key_founction> &founctions)
{
for (size_t i = 0; i < keys.size(); i++) {
if (!founctions[i](keys[i], keyparams)) {
+32 -32
View File
@@ -24,35 +24,35 @@ namespace Global {
namespace Restool {
using namespace std;
const map<string, ResType> ReferenceParser::ID_REFS = {
{ "^\\$id:", ResType::ID },
{ "^\\$boolean:", ResType::BOOLEAN },
{ "^\\$color:", ResType::COLOR },
{ "^\\$float:", ResType::FLOAT },
{ "^\\$media:", ResType::MEDIA },
{ "^\\$profile:", ResType::PROF },
{ "^\\$integer:", ResType::INTEGER },
{ "^\\$string:", ResType::STRING },
{ "^\\$layout:", ResType::LAYOUT },
{ "^\\$pattern:", ResType::PATTERN },
{ "^\\$plural:", ResType::PLURAL },
{ "^\\$graphic:", ResType::GRAPHIC },
{ "^\\$theme:", ResType::THEME }
{ "^\\$id:", ResType::ID },
{ "^\\$boolean:", ResType::BOOLEAN },
{ "^\\$color:", ResType::COLOR },
{ "^\\$float:", ResType::FLOAT },
{ "^\\$media:", ResType::MEDIA },
{ "^\\$profile:", ResType::PROF },
{ "^\\$integer:", ResType::INTEGER },
{ "^\\$string:", ResType::STRING },
{ "^\\$layout:", ResType::LAYOUT },
{ "^\\$pattern:", ResType::PATTERN },
{ "^\\$plural:", ResType::PLURAL },
{ "^\\$graphic:", ResType::GRAPHIC },
{ "^\\$theme:", ResType::THEME }
};
const map<string, ResType> ReferenceParser::ID_OHOS_REFS = {
{ "^\\$ohos:id:", ResType::ID },
{ "^\\$ohos:boolean:", ResType::BOOLEAN },
{ "^\\$ohos:color:", ResType::COLOR },
{ "^\\$ohos:float:", ResType::FLOAT },
{ "^\\$ohos:media:", ResType::MEDIA },
{ "^\\$ohos:profile:", ResType::PROF },
{ "^\\$ohos:integer:", ResType::INTEGER },
{ "^\\$ohos:string:", ResType::STRING },
{ "^\\$ohos:layout:", ResType::LAYOUT },
{ "^\\$ohos:pattern:", ResType::PATTERN },
{ "^\\$ohos:plural:", ResType::PLURAL },
{ "^\\$ohos:graphic:", ResType::GRAPHIC },
{ "^\\$ohos:theme:", ResType::THEME }
{ "^\\$ohos:id:", ResType::ID },
{ "^\\$ohos:boolean:", ResType::BOOLEAN },
{ "^\\$ohos:color:", ResType::COLOR },
{ "^\\$ohos:float:", ResType::FLOAT },
{ "^\\$ohos:media:", ResType::MEDIA },
{ "^\\$ohos:profile:", ResType::PROF },
{ "^\\$ohos:integer:", ResType::INTEGER },
{ "^\\$ohos:string:", ResType::STRING },
{ "^\\$ohos:layout:", ResType::LAYOUT },
{ "^\\$ohos:pattern:", ResType::PATTERN },
{ "^\\$ohos:plural:", ResType::PLURAL },
{ "^\\$ohos:graphic:", ResType::GRAPHIC },
{ "^\\$ohos:theme:", ResType::THEME }
};
ReferenceParser::ReferenceParser() : idWorker_(IdWorker::GetInstance())
@@ -75,7 +75,7 @@ uint32_t ReferenceParser::ParseRefInSolidXml(const vector<string> &solidXmlFolde
XmlKeyNode xmlKeyNode;
if (!xmlKeyNode.LoadFromFile(filePath, [this](auto &key) -> bool {
return ParseRefString(key);
})) {
})) {
return RESTOOL_ERROR;
}
@@ -103,10 +103,10 @@ uint32_t ReferenceParser::ParseRefInElement(map<int32_t, vector<ResourceItem>> &
uint32_t ReferenceParser::ParseRefInString(string &value, bool &update) const
{
if (ParseRefString(value, update)) {
return RESTOOL_SUCCESS;
}
return RESTOOL_ERROR;
if (ParseRefString(value, update)) {
return RESTOOL_SUCCESS;
}
return RESTOOL_ERROR;
}
uint32_t ReferenceParser::ParseRefInProfile(const string &output) const
@@ -156,7 +156,7 @@ bool ReferenceParser::ParseRefResourceItem(ResourceItem &resourceItem) const
string data;
bool update = false;
if (IsStringOfResourceItem(resType)) {
data= string(reinterpret_cast<const char *>(resourceItem.GetData()), resourceItem.GetDataLength());
data = string(reinterpret_cast<const char *>(resourceItem.GetData()), resourceItem.GetDataLength());
if (!ParseRefString(data, update)) {
cerr << "Error: in " << resourceItem.GetFilePath() << endl;
return false;
+2 -2
View File
@@ -31,7 +31,7 @@ ResourceItem::ResourceItem(const ResourceItem &other)
}
ResourceItem::ResourceItem(const string &name, const vector<KeyParam> &keyparams, ResType type)
:data_(nullptr), dataLen_(0), name_(name),keyparams_(keyparams), type_(type)
: data_(nullptr), dataLen_(0), name_(name), keyparams_(keyparams), type_(type)
{
}
@@ -118,7 +118,7 @@ ResourceItem &ResourceItem::operator=(const ResourceItem &other)
return *this;
}
//below private founction
// below private founction
void ResourceItem::ReleaseData()
{
if (data_ != nullptr) {
+4 -6
View File
@@ -71,7 +71,7 @@ uint32_t ResourcePack::Package()
return RESTOOL_SUCCESS;
}
//below private founction
// below private founction
uint32_t ResourcePack::Init()
{
InitHeaderCreater();
@@ -185,7 +185,7 @@ uint32_t ResourcePack::InitConfigJson()
{
string config = packageParser_.GetConfig();
if (config.empty()) {
if( packageParser_.GetInputs().size() > 1) {
if (packageParser_.GetInputs().size() > 1) {
cerr << "Error: more input path, -j config.json empty" << endl;
return RESTOOL_ERROR;
}
@@ -234,8 +234,7 @@ uint32_t ResourcePack::GenerateCplusHeader(const string &headerPath) const
buffer << "#define RESOURCE_TABLE_H\n\n";
buffer << "#include<stdint.h>\n\n";
buffer << "namespace OHOS {\n";
},
[](stringstream &buffer, const IdWorker::ResourceId& resourceId) {
}, [](stringstream &buffer, const IdWorker::ResourceId& resourceId) {
string name = resourceId.type + "_" + resourceId.name;
transform(name.begin(), name.end(), name.begin(), ::toupper);
buffer << "const int32_t " << name << " = ";
@@ -254,8 +253,7 @@ uint32_t ResourcePack::GenerateJsHeader(const std::string &headerPath) const
uint32_t result = JsHeader.Create([](stringstream &buffer) {
buffer << Header::LICENSE_HEADER << "\n";
buffer << "export default {\n";
},
[&itemType](stringstream &buffer, const IdWorker::ResourceId& resourceId) {
}, [&itemType](stringstream &buffer, const IdWorker::ResourceId& resourceId) {
if (itemType != resourceId.type) {
if (!itemType.empty()) {
buffer << "\n" << " " << "},\n";
+1 -1
View File
@@ -15,10 +15,10 @@
#include "resource_table.h"
#include <filesystem>
#include "securec.h"
#include "cmd_parser.h"
#include "file_manager.h"
#include "resource_util.h"
#include "securec.h"
namespace OHOS {
namespace Global {
+3 -3
View File
@@ -34,7 +34,7 @@ const map<string, ResourceUtil::IgnoreType> ResourceUtil::IGNORE_FILE_REGEX = {
{ "desktop\\.ini", IgnoreType::IGNORE_ALL },
{ "picasa\\.ini", IgnoreType::IGNORE_ALL },
{ "\\..+", IgnoreType::IGNORE_ALL },
{ "_.+",IgnoreType::IGNORE_DIR },
{ "_.+", IgnoreType::IGNORE_DIR },
{ "cvs", IgnoreType::IGNORE_ALL },
{ "thumbs\\.db", IgnoreType::IGNORE_ALL },
{ ".+~", IgnoreType::IGNORE_ALL }
@@ -88,7 +88,7 @@ bool ResourceUtil::OpenJsonFile(const string &path, Json::Value &root)
readBuilder["collectComments"] = false;
readBuilder["failIfExtra"] = true;
JSONCPP_STRING errs;
if(!parseFromStream(readBuilder, ifs, &root, &errs)) {
if (!parseFromStream(readBuilder, ifs, &root, &errs)) {
cerr << "Error: parseFromStream '" << path;
cerr << "\n" << errs << endl;
ifs.close();
@@ -144,7 +144,7 @@ string ResourceUtil::ResTypeToString(ResType type)
string ResourceUtil::GetIdName(const string &name, ResType type)
{
if (type != ResType::MEDIA && type != ResType::LAYOUT && type != ResType::PROF &&
type != ResType::ANIMATION && type != ResType::GRAPHIC ) {
type != ResType::ANIMATION && type != ResType::GRAPHIC) {
return name;
}
+2 -1
View File
@@ -19,7 +19,8 @@
using namespace std;
using namespace OHOS::Global::Restool;
uint32_t ProccssHap(PackageParser &packageParser) {
uint32_t ProccssHap(PackageParser &packageParser)
{
TaskHandle taskHandle;
return taskHandle.HandlePackage(packageParser);
}
+1 -1
View File
@@ -17,8 +17,8 @@
#include<filesystem>
#include<iostream>
#include<regex>
#include "restool_errors.h"
#include "resource_util.h"
#include "restool_errors.h"
namespace OHOS {
namespace Global {
+2 -2
View File
@@ -78,7 +78,7 @@ bool SolidXml::FlushNodeKeys(const string &filePath, map<XmlKeyNode::KeyType, sh
return SaveToFile(filePath);
}
//below private
// below private
void SolidXml::Compile(const xmlNodePtr nodePtr, shared_ptr<XmlNode> &node)
{
if (nodePtr->type == XML_COMMENT_NODE) {
@@ -119,7 +119,7 @@ void SolidXml::CompileAttr(const xmlAttrPtr attrPtr, shared_ptr<XmlNode> &node)
return;
}
xmlChar * xmlValue = xmlNodeListGetString(attrPtr->doc, attrPtr->children, 1);
xmlChar *xmlValue = xmlNodeListGetString(attrPtr->doc, attrPtr->children, 1);
string value(reinterpret_cast<const char *>(xmlValue));
PretreatmentAttr(value);
xmlFree(xmlValue);
+1 -1
View File
@@ -56,7 +56,7 @@ bool XmlKeyNode::SaveToFile(const string &filePath) const
}
vector<pair<string, int32_t>> sets(keyMap_.begin(), keyMap_.end());
sort(sets.begin(), sets.end(),[](const auto &a, const auto &b) {
sort(sets.begin(), sets.end(), [](const auto &a, const auto &b) {
return a.second < b.second;
});