TagValue TagValue::fromQVariant(const QVariant& variant) { TagValue result; const QVariant::Type type = variant.type(); switch(type) { default: assert(!"unknown type"); break; case QVariant::String: result = TagValue( variant.toString() ); break; case QVariant::Date: result = TagValue( variant.toDate() ); break; case QVariant::Time: result = TagValue( variant.toTime() ); break; } return result; }
QString OrganiseFormat::ParseBlock(QString block, const Song& song, bool* any_empty) const { QRegExp tag_regexp(kTagPattern); QRegExp block_regexp(kBlockPattern); // Find any blocks first int pos = 0; while ((pos = block_regexp.indexIn(block, pos)) != -1) { // Recursively parse the block bool empty = false; QString value = ParseBlock(block_regexp.cap(1), song, &empty); if (empty) value = ""; // Replace the block's value block.replace(pos, block_regexp.matchedLength(), value); pos += value.length(); } // Now look for tags bool empty = false; pos = 0; while ((pos = tag_regexp.indexIn(block, pos)) != -1) { QString value = TagValue(tag_regexp.cap(1), song); if (value.isEmpty()) empty = true; block.replace(pos, tag_regexp.matchedLength(), value); pos += value.length(); } if (any_empty) *any_empty = empty; return block; }
TagValue TagValue::fromQVariant(const QVariant& variant) { TagValue result; const QVariant::Type type = variant.type(); switch(type) { default: assert(!"unknown type"); break; case QVariant::StringList: { std::deque<TagValue> list; QStringList stringList = variant.toStringList(); list.insert(list.end(), stringList.begin(), stringList.end()); result = TagValue(list); break; } case QVariant::String: result = TagValue( variant.toString() ); break; case QVariant::Date: result = TagValue( variant.toDate() ); break; case QVariant::Time: result = TagValue( variant.toTime() ); break; } return result; }
TagValue TagValue::fromRaw(const QString& raw, const TagNameInfo::Type& type) { return TagValue().fromString(raw, type); }