Improve coding style in CLI code
* Use `std::string_view` instead of `const std::string &` * Use `const` and `auto` where it makes sense
This commit is contained in:
parent
c71fde86ec
commit
dca5905744
|
@ -475,12 +475,15 @@ std::uint64_t parseUInt64(const Argument &arg, std::uint64_t defaultValue)
|
||||||
return defaultValue;
|
return defaultValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
TagTarget::IdContainerType parseIds(const std::string &concatenatedIds)
|
TagTarget::IdContainerType parseIds(std::string_view concatenatedIds)
|
||||||
{
|
{
|
||||||
auto splittedIds = splitString(concatenatedIds, ",", EmptyPartsTreat::Omit);
|
const auto splittedIds = splitStringSimple(concatenatedIds, ",");
|
||||||
TagTarget::IdContainerType convertedIds;
|
auto convertedIds = TagTarget::IdContainerType();
|
||||||
convertedIds.reserve(splittedIds.size());
|
convertedIds.reserve(splittedIds.size());
|
||||||
for (const auto &id : splittedIds) {
|
for (const auto &id : splittedIds) {
|
||||||
|
if (id.empty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
convertedIds.push_back(stringToNumber<TagTarget::IdType>(id));
|
convertedIds.push_back(stringToNumber<TagTarget::IdType>(id));
|
||||||
} catch (const ConversionException &) {
|
} catch (const ConversionException &) {
|
||||||
|
@ -492,7 +495,7 @@ TagTarget::IdContainerType parseIds(const std::string &concatenatedIds)
|
||||||
return convertedIds;
|
return convertedIds;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool applyTargetConfiguration(TagTarget &target, const std::string &configStr)
|
bool applyTargetConfiguration(TagTarget &target, std::string_view configStr)
|
||||||
{
|
{
|
||||||
if (!configStr.empty()) {
|
if (!configStr.empty()) {
|
||||||
if (configStr.compare(0, 13, "target-level=") == 0) {
|
if (configStr.compare(0, 13, "target-level=") == 0) {
|
||||||
|
@ -504,7 +507,7 @@ bool applyTargetConfiguration(TagTarget &target, const std::string &configStr)
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
} else if (configStr.compare(0, 17, "target-levelname=") == 0) {
|
} else if (configStr.compare(0, 17, "target-levelname=") == 0) {
|
||||||
target.setLevelName(configStr.substr(17));
|
target.setLevelName(std::string(configStr.substr(17)));
|
||||||
} else if (configStr.compare(0, 14, "target-tracks=") == 0) {
|
} else if (configStr.compare(0, 14, "target-tracks=") == 0) {
|
||||||
target.tracks() = parseIds(configStr.substr(14));
|
target.tracks() = parseIds(configStr.substr(14));
|
||||||
} else if (configStr.compare(0, 16, "target-chapters=") == 0) {
|
} else if (configStr.compare(0, 16, "target-chapters=") == 0) {
|
||||||
|
@ -616,9 +619,9 @@ FieldDenotations parseFieldDenotations(const Argument &fieldsArg, bool readOnly)
|
||||||
|
|
||||||
// read field name
|
// read field name
|
||||||
const auto equationPos = strchr(fieldDenotationString, '=');
|
const auto equationPos = strchr(fieldDenotationString, '=');
|
||||||
size_t fieldNameLen = equationPos ? static_cast<size_t>(equationPos - fieldDenotationString) : strlen(fieldDenotationString);
|
auto fieldNameLen = equationPos ? static_cast<size_t>(equationPos - fieldDenotationString) : strlen(fieldDenotationString);
|
||||||
// field name might denote increment ("+") or path disclosure (">")
|
// field name might denote increment ("+") or path disclosure (">")
|
||||||
DenotationType type = DenotationType::Normal;
|
auto type = DenotationType::Normal;
|
||||||
if (fieldNameLen && equationPos) {
|
if (fieldNameLen && equationPos) {
|
||||||
switch (*(equationPos - 1)) {
|
switch (*(equationPos - 1)) {
|
||||||
case '+':
|
case '+':
|
||||||
|
|
|
@ -298,8 +298,8 @@ TagUsage parseUsageDenotation(const CppUtilities::Argument &usageArg, TagUsage d
|
||||||
TagTextEncoding parseEncodingDenotation(const CppUtilities::Argument &encodingArg, TagTextEncoding defaultEncoding);
|
TagTextEncoding parseEncodingDenotation(const CppUtilities::Argument &encodingArg, TagTextEncoding defaultEncoding);
|
||||||
ElementPosition parsePositionDenotation(const CppUtilities::Argument &posArg, const CppUtilities::Argument &valueArg, ElementPosition defaultPos);
|
ElementPosition parsePositionDenotation(const CppUtilities::Argument &posArg, const CppUtilities::Argument &valueArg, ElementPosition defaultPos);
|
||||||
std::uint64_t parseUInt64(const CppUtilities::Argument &arg, std::uint64_t defaultValue);
|
std::uint64_t parseUInt64(const CppUtilities::Argument &arg, std::uint64_t defaultValue);
|
||||||
TagTarget::IdContainerType parseIds(const std::string &concatenatedIds);
|
TagTarget::IdContainerType parseIds(std::string_view concatenatedIds);
|
||||||
bool applyTargetConfiguration(TagTarget &target, const std::string &configStr);
|
bool applyTargetConfiguration(TagTarget &target, std::string_view configStr);
|
||||||
FieldDenotations parseFieldDenotations(const CppUtilities::Argument &fieldsArg, bool readOnly);
|
FieldDenotations parseFieldDenotations(const CppUtilities::Argument &fieldsArg, bool readOnly);
|
||||||
std::string tagName(const Tag *tag);
|
std::string tagName(const Tag *tag);
|
||||||
bool stringToBool(const std::string &str);
|
bool stringToBool(const std::string &str);
|
||||||
|
|
|
@ -579,12 +579,12 @@ void setTagInfo(const SetTagInfoArgs &args)
|
||||||
fileInfo.parseTags(diag, parsingProgress);
|
fileInfo.parseTags(diag, parsingProgress);
|
||||||
fileInfo.parseTracks(diag, parsingProgress);
|
fileInfo.parseTracks(diag, parsingProgress);
|
||||||
fileInfo.parseAttachments(diag, parsingProgress);
|
fileInfo.parseAttachments(diag, parsingProgress);
|
||||||
vector<Tag *> tags;
|
|
||||||
|
|
||||||
// remove tags with the specified targets
|
// remove tags with the specified targets
|
||||||
if (validRemoveTargetsSpecified) {
|
auto tags = std::vector<Tag *>();
|
||||||
|
if (!targetsToRemove.empty()) {
|
||||||
fileInfo.tags(tags);
|
fileInfo.tags(tags);
|
||||||
for (auto *tag : tags) {
|
for (auto *const tag : tags) {
|
||||||
if (find(targetsToRemove.cbegin(), targetsToRemove.cend(), tag->target()) != targetsToRemove.cend()) {
|
if (find(targetsToRemove.cbegin(), targetsToRemove.cend(), tag->target()) != targetsToRemove.cend()) {
|
||||||
fileInfo.removeTag(tag);
|
fileInfo.removeTag(tag);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue