diff --git a/cli/helper.cpp b/cli/helper.cpp index cb9c828..c49f561 100644 --- a/cli/helper.cpp +++ b/cli/helper.cpp @@ -1,16 +1,20 @@ #include "./helper.h" +#include "../application/knownfieldmodel.h" + #include #include #include +#include using namespace std; using namespace ApplicationUtilities; using namespace ConversionUtilities; using namespace ChronoUtilities; using namespace Media; +using namespace Settings; namespace Cli { @@ -127,6 +131,46 @@ void printProperty(const char *propName, ElementPosition elementPosition, const } } +void printFieldName(const char *fieldName, size_t fieldNameLen) +{ + cout << ' ' << fieldName; + // also write padding + for(auto i = fieldNameLen; i < 18; ++i) { + cout << ' '; + } +} + +void printField(const FieldScope &scope, const Tag *tag, bool skipEmpty) +{ + const auto &values = tag->values(scope.field); + if(!skipEmpty || !values.empty()) { + // write field name + const char *fieldName = KnownFieldModel::fieldName(scope.field); + const auto fieldNameLen = strlen(fieldName); + + // write value + if(values.empty()) { + printFieldName(fieldName, fieldNameLen); + cout << "none\n"; + } else { + for(const auto &value : values) { + printFieldName(fieldName, fieldNameLen); + try { + const auto textValue = value->toString(TagTextEncoding::Utf8); + if(textValue.empty()) { + cout << "can't display here (see --extract)"; + } else { + cout << textValue; + } + } catch(const ConversionException &) { + cout << "conversion error"; + } + cout << '\n'; + } + } + } +} + TagUsage parseUsageDenotation(const Argument &usageArg, TagUsage defaultUsage) { if(usageArg.isPresent()) { diff --git a/cli/helper.h b/cli/helper.h index c2d94f5..df0ab41 100644 --- a/cli/helper.h +++ b/cli/helper.h @@ -49,6 +49,24 @@ inline TagType &operator|= (TagType &lhs, TagType rhs) return lhs = static_cast(static_cast(lhs) | static_cast(rhs)); } +struct FieldId +{ + constexpr FieldId(KnownField field); + constexpr FieldId(const char *field); + KnownField genericField; + const char *nativeField; +}; + +constexpr FieldId::FieldId(KnownField field) : + genericField(field), + nativeField(nullptr) +{} + +constexpr FieldId::FieldId(const char *field) : + genericField(KnownField::Invalid), + nativeField(field) +{} + struct FieldScope { FieldScope(KnownField field = KnownField::Invalid, TagType tagType = TagType::Unspecified, TagTarget tagTarget = TagTarget()); @@ -192,6 +210,8 @@ inline void printProperty(const char *propName, const intType value, const char } } +void printField(const FieldScope &scope, const Tag *tag, bool skipEmpty); + TagUsage parseUsageDenotation(const ApplicationUtilities::Argument &usageArg, TagUsage defaultUsage); TagTextEncoding parseEncodingDenotation(const ApplicationUtilities::Argument &encodingArg, TagTextEncoding defaultEncoding); ElementPosition parsePositionDenotation(const ApplicationUtilities::Argument &posArg, const ApplicationUtilities::Argument &valueArg, ElementPosition defaultPos); diff --git a/cli/mainfeatures.cpp b/cli/mainfeatures.cpp index b5295bc..8b43418 100644 --- a/cli/mainfeatures.cpp +++ b/cli/mainfeatures.cpp @@ -272,71 +272,13 @@ void displayTagInfo(const Argument &fieldsArg, const Argument &filesArg, const A // iterate through fields specified by the user if(fields.empty()) { for(auto field = firstKnownField; field != KnownField::Invalid; field = nextKnownField(field)) { - const auto &values = tag->values(field); - if(!values.empty()) { - const char *fieldName = KnownFieldModel::fieldName(field); - const auto fieldNameLen = strlen(fieldName); - for(const auto &value : values) { - // write field name - cout << ' ' << fieldName; - // write padding - for(auto i = fieldNameLen; i < 18; ++i) { - cout << ' '; - } - // write value - try { - const auto textValue = value->toString(TagTextEncoding::Utf8); - if(textValue.empty()) { - cout << "can't display here (see --extract)"; - } else { - cout << textValue; - } - } catch(const ConversionException &) { - cout << "conversion error"; - } - cout << endl; - } - } + printField(FieldScope(field), tag, true); } } else { for(const auto &fieldDenotation : fields) { const FieldScope &denotedScope = fieldDenotation.first; if(denotedScope.tagType == TagType::Unspecified || (denotedScope.tagType | tagType) != TagType::Unspecified) { - const auto &values = tag->values(denotedScope.field); - const char *fieldName = KnownFieldModel::fieldName(denotedScope.field); - const auto fieldNameLen = strlen(fieldName); - if(values.empty()) { - // write field name - const char *fieldName = KnownFieldModel::fieldName(denotedScope.field); - cout << ' ' << fieldName; - // write padding - for(auto i = fieldNameLen; i < 18; ++i) { - cout << ' '; - } - cout << "none"; - } else { - for(const auto &value : values) { - // write field name - const char *fieldName = KnownFieldModel::fieldName(denotedScope.field); - cout << ' ' << fieldName; - // write padding - for(auto i = fieldNameLen; i < 18; ++i) { - cout << ' '; - } - // write value - try { - const auto textValue = value->toString(TagTextEncoding::Utf8); - if(textValue.empty()) { - cout << "can't display here (see --extract)"; - } else { - cout << textValue; - } - } catch(const ConversionException &) { - cout << "conversion error"; - } - cout << endl; - } - } + printField(denotedScope, tag, false); } } }