simplify
This commit is contained in:
@@ -10,7 +10,10 @@ struct TitleTrans
|
|||||||
{
|
{
|
||||||
Regex TitleFrom, SubFrom, ArtistFrom;
|
Regex TitleFrom, SubFrom, ArtistFrom;
|
||||||
CString TitleTo, SubTo, ArtistTo; /* plain text */
|
CString TitleTo, SubTo, ArtistTo; /* plain text */
|
||||||
|
|
||||||
|
/* If this is true, no translit fields will be generated automatically. */
|
||||||
bool translit;
|
bool translit;
|
||||||
|
TitleTrans() { translit = true; }
|
||||||
|
|
||||||
TitleTrans(CString tf, CString sf, CString af, CString tt, CString st, CString at,
|
TitleTrans(CString tf, CString sf, CString af, CString tt, CString st, CString at,
|
||||||
bool translit_):
|
bool translit_):
|
||||||
@@ -31,11 +34,9 @@ bool TitleTrans::Matches(CString title, CString sub, CString artist)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TitleSubst::AddTrans(const CString &tf, const CString &sf, const CString &af,
|
void TitleSubst::AddTrans(const TitleTrans &tr)
|
||||||
const CString &tt, const CString &st, const CString &at,
|
|
||||||
bool translit)
|
|
||||||
{
|
{
|
||||||
ttab.push_back(new TitleTrans(tf, sf, af, tt, st, at, translit));
|
ttab.push_back(new TitleTrans(tr));
|
||||||
}
|
}
|
||||||
|
|
||||||
void TitleSubst::Subst(CString &title, CString &subtitle, CString &artist,
|
void TitleSubst::Subst(CString &title, CString &subtitle, CString &artist,
|
||||||
@@ -46,23 +47,20 @@ void TitleSubst::Subst(CString &title, CString &subtitle, CString &artist,
|
|||||||
if(!ttab[i]->Matches(title, subtitle, artist))
|
if(!ttab[i]->Matches(title, subtitle, artist))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
/* The song matches. Replace whichever strings aren't empty.
|
/* The song matches. Replace whichever strings aren't empty. */
|
||||||
* Don't replace any that already have a transliteration set.
|
if(!ttab[i]->TitleTo.empty())
|
||||||
* Wait, do; too many songs have translits set with hacked
|
|
||||||
* titles. */
|
|
||||||
if(!ttab[i]->TitleTo.empty()) // && ttitle.empty())
|
|
||||||
{
|
{
|
||||||
if(ttab[i]->translit) ttitle = title;
|
if(ttab[i]->translit) ttitle = title;
|
||||||
title = ttab[i]->TitleTo;
|
title = ttab[i]->TitleTo;
|
||||||
FontCharAliases::ReplaceMarkers( title );
|
FontCharAliases::ReplaceMarkers( title );
|
||||||
}
|
}
|
||||||
if(!ttab[i]->SubTo.empty()) // && tsubtitle.empty())
|
if(!ttab[i]->SubTo.empty())
|
||||||
{
|
{
|
||||||
if(ttab[i]->translit) tsubtitle = subtitle;
|
if(ttab[i]->translit) tsubtitle = subtitle;
|
||||||
subtitle = ttab[i]->SubTo;
|
subtitle = ttab[i]->SubTo;
|
||||||
FontCharAliases::ReplaceMarkers( subtitle );
|
FontCharAliases::ReplaceMarkers( subtitle );
|
||||||
}
|
}
|
||||||
if(!ttab[i]->ArtistTo.empty()) // && tartist.empty())
|
if(!ttab[i]->ArtistTo.empty())
|
||||||
{
|
{
|
||||||
if(ttab[i]->translit) tartist = artist;
|
if(ttab[i]->translit) tartist = artist;
|
||||||
artist = ttab[i]->ArtistTo;
|
artist = ttab[i]->ArtistTo;
|
||||||
@@ -82,13 +80,12 @@ void TitleSubst::Load(const CString &filename, const CString §ion)
|
|||||||
ifstream f;
|
ifstream f;
|
||||||
f.open(filename);
|
f.open(filename);
|
||||||
if(!f.good()) return;
|
if(!f.good()) return;
|
||||||
CString TitleFrom, ArtistFrom, SubtitleFrom, TitleTo, ArtistTo, SubtitleTo;
|
|
||||||
bool translit = true;
|
|
||||||
CString CurrentSection;
|
CString CurrentSection;
|
||||||
|
TitleTrans tr;
|
||||||
|
|
||||||
while(!f.eof())
|
while(!f.eof())
|
||||||
{
|
{
|
||||||
|
|
||||||
CString line;
|
CString line;
|
||||||
if(!getline(f, line)) continue;
|
if(!getline(f, line)) continue;
|
||||||
|
|
||||||
@@ -105,10 +102,9 @@ void TitleSubst::Load(const CString &filename, const CString §ion)
|
|||||||
if(line.size() == 0) continue; /* blank */
|
if(line.size() == 0) continue; /* blank */
|
||||||
if(line[0] == '#') continue; /* comment */
|
if(line[0] == '#') continue; /* comment */
|
||||||
|
|
||||||
|
|
||||||
if(!line.CompareNoCase("DontTransliterate"))
|
if(!line.CompareNoCase("DontTransliterate"))
|
||||||
{
|
{
|
||||||
translit = false;
|
tr.translit = false;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -120,31 +116,25 @@ void TitleSubst::Load(const CString &filename, const CString §ion)
|
|||||||
CString txt = line.substr(pos+1);
|
CString txt = line.substr(pos+1);
|
||||||
TrimLeft(txt);
|
TrimLeft(txt);
|
||||||
|
|
||||||
if(!id.CompareNoCase("TitleFrom")) TitleFrom = txt;
|
/* Surround each regex with ^(...)$, to force all comparisons to default
|
||||||
else if(!id.CompareNoCase("ArtistFrom")) ArtistFrom = txt;
|
* to being a full-line match. (Add ".*" manually if this isn't wanted.) */
|
||||||
else if(!id.CompareNoCase("SubtitleFrom")) SubtitleFrom = txt;
|
if(!id.CompareNoCase("TitleFrom")) tr.TitleFrom = "^(" + txt + ")$";
|
||||||
else if(!id.CompareNoCase("TitleTo")) TitleTo = txt;
|
else if(!id.CompareNoCase("ArtistFrom")) tr.ArtistFrom = "^(" + txt + ")$";
|
||||||
else if(!id.CompareNoCase("ArtistTo")) ArtistTo = txt;
|
else if(!id.CompareNoCase("SubtitleFrom")) tr.SubFrom = "^(" + txt + ")$";
|
||||||
else if(!id.CompareNoCase("SubtitleTo")) SubtitleTo = txt;
|
else if(!id.CompareNoCase("TitleTo")) tr.TitleTo = txt;
|
||||||
|
else if(!id.CompareNoCase("ArtistTo")) tr.ArtistTo = txt;
|
||||||
|
else if(!id.CompareNoCase("SubtitleTo")) tr.SubTo = txt;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Add the translation if this is a terminator (*) or section
|
/* Add the translation if this is a terminator (*) or section
|
||||||
* marker ([foo]). */
|
* marker ([foo]). */
|
||||||
if(line[0] == '*' || line[0] == '[')
|
if(line[0] == '*' || line[0] == '[')
|
||||||
{
|
{
|
||||||
/* Surround each regex with ^(...)$, to force all comparisons to default
|
if(!CurrentSection.CompareNoCase(section))
|
||||||
* to being a full-line match. (Add ".*" manually if htis isn't wanted.) */
|
AddTrans(tr);
|
||||||
if(TitleFrom.size()) TitleFrom = "^(" + TitleFrom + ")$";
|
|
||||||
if(ArtistFrom.size()) ArtistFrom = "^(" + ArtistFrom + ")$";
|
|
||||||
if(SubtitleFrom.size()) SubtitleFrom = "^(" + SubtitleFrom + ")$";
|
|
||||||
|
|
||||||
if(!CurrentSection.CompareNoCase(section) &&
|
|
||||||
(TitleFrom.size() || SubtitleFrom.size() || ArtistFrom.size()))
|
|
||||||
AddTrans(TitleFrom, SubtitleFrom, ArtistFrom, TitleTo, SubtitleTo, ArtistTo, translit);
|
|
||||||
|
|
||||||
/* Reset. */
|
/* Reset. */
|
||||||
TitleFrom = ArtistFrom = SubtitleFrom = TitleTo = ArtistTo = SubtitleTo = "";
|
tr = TitleTrans();
|
||||||
translit = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(line[0] == '[' && line[line.size()-1] == ']')
|
if(line[0] == '[' && line[line.size()-1] == ']')
|
||||||
|
|||||||
@@ -7,8 +7,7 @@ class TitleSubst
|
|||||||
{
|
{
|
||||||
vector<TitleTrans *> ttab;
|
vector<TitleTrans *> ttab;
|
||||||
|
|
||||||
void AddTrans(const CString &tf, const CString &sf, const CString &af,
|
void AddTrans(const TitleTrans &tr);
|
||||||
const CString &tt, const CString &st, const CString &at, bool translit);
|
|
||||||
public:
|
public:
|
||||||
TitleSubst(const CString §ion);
|
TitleSubst(const CString §ion);
|
||||||
~TitleSubst();
|
~TitleSubst();
|
||||||
|
|||||||
Reference in New Issue
Block a user