Revert "Improve representation of track numbers in indexes"
This reverts commit a3da259a37.
This commit is contained in:
@@ -51,7 +51,7 @@ static SingletonEnv<leveldb::EspEnv> sEnv;
|
||||
static const char kDbPath[] = "/.tangara-db";
|
||||
|
||||
static const char kKeyDbVersion[] = "schema_version";
|
||||
static const uint8_t kCurrentDbVersion = 4;
|
||||
static const uint8_t kCurrentDbVersion = 3;
|
||||
static const char kKeyCollator[] = "collator";
|
||||
static const char kKeyTrackId[] = "next_track_id";
|
||||
|
||||
|
||||
+9
-22
@@ -8,7 +8,6 @@
|
||||
|
||||
#include <cstdint>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <variant>
|
||||
|
||||
#include "collation.hpp"
|
||||
@@ -56,7 +55,7 @@ static auto missing_component_text(const Track& track, Tag tag)
|
||||
case Tag::kTitle:
|
||||
return track.TitleOrFilename();
|
||||
case Tag::kAlbumTrack:
|
||||
return "0";
|
||||
return "0000";
|
||||
case Tag::kDuration:
|
||||
default:
|
||||
return {};
|
||||
@@ -77,29 +76,17 @@ auto Index(locale::ICollator& collator, const IndexInfo& info, const Track& t)
|
||||
};
|
||||
|
||||
for (std::uint8_t i = 0; i < info.components.size(); i++) {
|
||||
Tag component = info.components.at(i);
|
||||
// Fill in the text for this depth.
|
||||
auto text = t.tags().at(info.components.at(i));
|
||||
std::pmr::string value;
|
||||
|
||||
if (component == Tag::kAlbumTrack) {
|
||||
// Track numbers are a special case, since they're numbers rather than
|
||||
// text.
|
||||
auto pmr_num = t.tags().at(component).value_or("0");
|
||||
// std::pmr continues to be a true disappointment.
|
||||
std::string raw_num{pmr_num.data(), pmr_num.size()};
|
||||
uint32_t num = std::stoi(raw_num);
|
||||
key.item = std::pmr::string{reinterpret_cast<char*>(&num), 4};
|
||||
if (text) {
|
||||
std::pmr::string orig = *text;
|
||||
auto xfrm = collator.Transform({orig.data(), orig.size()});
|
||||
key.item = {xfrm.data(), xfrm.size()};
|
||||
value = *text;
|
||||
} else {
|
||||
auto text = t.tags().at(component);
|
||||
if (text) {
|
||||
std::pmr::string orig = *text;
|
||||
auto xfrm = collator.Transform({orig.data(), orig.size()});
|
||||
key.item = {xfrm.data(), xfrm.size()};
|
||||
value = *text;
|
||||
} else {
|
||||
key.item = {};
|
||||
value = missing_component_text(t, info.components.at(i)).value_or("");
|
||||
}
|
||||
key.item = {};
|
||||
value = missing_component_text(t, info.components.at(i)).value_or("");
|
||||
}
|
||||
|
||||
// If this is the last component, then we should also fill in the track id
|
||||
|
||||
@@ -30,8 +30,9 @@ const static std::array<std::pair<const char*, Tag>, 5> kVorbisIdToTag = {{
|
||||
}};
|
||||
|
||||
static auto convert_track_number(int number) -> std::pmr::string {
|
||||
std::string s = std::to_string(number);
|
||||
return {s.data(), s.size()};
|
||||
std::ostringstream oss;
|
||||
oss << std::setw(4) << std::setfill('0') << number;
|
||||
return std::pmr::string(oss.str());
|
||||
}
|
||||
|
||||
static auto convert_track_number(const std::pmr::string& raw)
|
||||
@@ -166,7 +167,8 @@ auto TagParserImpl::ReadAndParseTags(const std::pmr::string& path)
|
||||
}
|
||||
}
|
||||
|
||||
// Normalise track numbers to ensure that they're actually numbers.
|
||||
// Normalise track numbers; they're usually treated as strings, but we would
|
||||
// like to sort them lexicographically.
|
||||
tags->set(Tag::kAlbumTrack,
|
||||
convert_track_number(tags->at(Tag::kAlbumTrack).value_or("0")));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user