libsaria: Format each tag as it is read in
I lowercase everything, strip out some characters, and create a linked list of each word for each tag.
This commit is contained in:
parent
86e40cefcb
commit
fc50ceb34f
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include <libsaria/files.h>
|
||||
|
||||
#include <list>
|
||||
#include <string>
|
||||
using namespace std;
|
||||
|
||||
|
@ -24,7 +25,13 @@ class TrackTag
|
|||
int channels;
|
||||
ino_t inode;
|
||||
|
||||
list<string> title_words;
|
||||
list<string> artist_words;
|
||||
list<string> album_words;
|
||||
|
||||
void make_lenstr();
|
||||
void format_tag(string &, list<string> &);
|
||||
void format_tags();
|
||||
|
||||
public:
|
||||
TrackTag();
|
||||
|
|
|
@ -29,6 +29,10 @@ TrackTag::TrackTag(const TrackTag &tag)
|
|||
bitrate = tag.bitrate;
|
||||
sample = tag.sample;
|
||||
channels = tag.channels;
|
||||
|
||||
title_words = tag.title_words;
|
||||
artist_words = tag.artist_words;
|
||||
album_words = tag.album_words;
|
||||
}
|
||||
|
||||
TrackTag::TrackTag(string file, ino_t ino)
|
||||
|
@ -60,6 +64,7 @@ TrackTag::TrackTag(string file, ino_t ino)
|
|||
channels = prop->channels();
|
||||
|
||||
make_lenstr();
|
||||
format_tags();
|
||||
}
|
||||
|
||||
TrackTag::TrackTag(InFile &in)
|
||||
|
@ -78,6 +83,8 @@ TrackTag::TrackTag(InFile &in)
|
|||
bitrate = in.read_int();
|
||||
sample = in.read_int();
|
||||
channels = in.read_int();
|
||||
|
||||
format_tags();
|
||||
}
|
||||
|
||||
TrackTag::~TrackTag()
|
||||
|
@ -118,6 +125,58 @@ void TrackTag::make_lenstr()
|
|||
lenstr = stream.str();
|
||||
}
|
||||
|
||||
void TrackTag::format_tag(string &tag, list<string> &tag_list)
|
||||
{
|
||||
string word;
|
||||
char c, diff = 'a' - 'A';
|
||||
|
||||
for (unsigned int i = 0; i < tag.size(); i++) {
|
||||
c = tag[i];
|
||||
// Character already lower case
|
||||
if ( (c >= 'a') && (c <= 'z') )
|
||||
word += c;
|
||||
// Convert uppercase to lowercase
|
||||
else if ( (c >= 'A') && (c <= 'Z') )
|
||||
word += (c + diff);
|
||||
// Keep numbers
|
||||
else if ( (c >= '0') && (c <= '9') )
|
||||
word += c;
|
||||
else {
|
||||
// These characters indicate a new word
|
||||
switch (c) {
|
||||
case '-':
|
||||
case '\\':
|
||||
case '/':
|
||||
case ',':
|
||||
case ';':
|
||||
case '(':
|
||||
case ')':
|
||||
case '_':
|
||||
case '~':
|
||||
case '+':
|
||||
case '"':
|
||||
case ' ':
|
||||
if (word != "")
|
||||
tag_list.push_back(word);
|
||||
word = "";
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
if (word != "")
|
||||
tag_list.push_back(word);
|
||||
}
|
||||
|
||||
void TrackTag::format_tags()
|
||||
{
|
||||
format_tag(title, title_words);
|
||||
format_tag(artist, artist_words);
|
||||
format_tag(album, album_words);
|
||||
}
|
||||
|
||||
ino_t TrackTag::get_inode()
|
||||
{
|
||||
return inode;
|
||||
|
|
Loading…
Reference in New Issue