TitleSubstitution cleanup, license update

This commit is contained in:
Glenn Maynard
2004-05-31 00:59:33 +00:00
parent 93e274b3ac
commit 41ef4f0edc
4 changed files with 126 additions and 55 deletions
+6 -3
View File
@@ -259,9 +259,12 @@ void Course::LoadFromCRSFile( CString sPath )
} }
static TitleSubst tsub("courses"); static TitleSubst tsub("courses");
CString ignore; TitleFields title;
tsub.Subst( m_sName, ignore, ignore, title.Title = m_sName;
m_sNameTranslit, ignore, ignore ); title.TitleTranslit = m_sNameTranslit;
tsub.Subst( title );
m_sName = title.Title;
m_sNameTranslit = title.TitleTranslit;
} }
void Course::Init() void Course::Init()
+4 -2
View File
@@ -822,8 +822,10 @@ void Song::TranslateTitles()
{ {
static TitleSubst tsub("songs"); static TitleSubst tsub("songs");
tsub.Subst(m_sMainTitle, m_sSubTitle, m_sArtist, TitleFields title;
m_sMainTitleTranslit, m_sSubTitleTranslit, m_sArtistTranslit); title.LoadFromStrings( m_sMainTitle, m_sSubTitle, m_sArtist, m_sMainTitleTranslit, m_sSubTitleTranslit, m_sArtistTranslit );
tsub.Subst( title );
title.SaveToStrings( m_sMainTitle, m_sSubTitle, m_sArtist, m_sMainTitleTranslit, m_sSubTitleTranslit, m_sArtistTranslit );
} }
void Song::ReCalculateRadarValuesAndLastBeat() void Song::ReCalculateRadarValuesAndLastBeat()
+64 -44
View File
@@ -13,28 +13,28 @@
struct TitleTrans struct TitleTrans
{ {
Regex TitleFrom, SubFrom, ArtistFrom; Regex TitleFrom, SubFrom, ArtistFrom;
CString TitleTo, SubTo, ArtistTo; /* plain text */ TitleFields Dest;
CString TitleTransTo, SubTransTo, ArtistTransTo; /* plain text */
/* If this is true, no translit fields will be generated automatically. */ /* If this is true, no translit fields will be generated automatically. */
bool translit; bool translit;
TitleTrans() { translit = true; } TitleTrans() { translit = true; }
TitleTrans(CString tf, CString sf, CString af, CString tt, CString st, CString at, TitleTrans( const TitleFields &tf, bool translit_):
bool translit_): Dest(tf), translit(translit_) { }
TitleFrom(tf), SubFrom(sf), ArtistFrom(af),
TitleTo(tt), SubTo(st), ArtistTo(at), translit(translit_) { }
bool Matches(CString title, CString sub, CString artist); bool Matches( const TitleFields &tf );
}; };
vector<TitleTrans> ttab; vector<TitleTrans> ttab;
bool TitleTrans::Matches(CString title, CString sub, CString artist) bool TitleTrans::Matches( const TitleFields &tf )
{ {
if(!TitleFrom.Compare(title)) return false; /* no match */ if( !TitleFrom.Compare(tf.Title) )
if(!SubFrom.Compare(sub)) return false; /* no match */ return false; /* no match */
if(!ArtistFrom.Compare(artist)) return false; /* no match */ if( !SubFrom.Compare(tf.Subtitle) )
return false; /* no match */
if( !ArtistFrom.Compare(tf.Artist) )
return false; /* no match */
return true; return true;
} }
@@ -44,51 +44,52 @@ void TitleSubst::AddTrans(const TitleTrans &tr)
ttab.push_back(new TitleTrans(tr)); ttab.push_back(new TitleTrans(tr));
} }
void TitleSubst::Subst(CString &title, CString &subtitle, CString &artist, void TitleSubst::Subst( TitleFields &tf )
CString &ttitle, CString &tsubtitle, CString &tartist)
{ {
for(unsigned i = 0; i < ttab.size(); ++i) for(unsigned i = 0; i < ttab.size(); ++i)
{ {
if(!ttab[i]->Matches(title, subtitle, artist)) if(!ttab[i]->Matches(tf))
continue; continue;
/* The song matches. Replace whichever strings aren't empty. */ /* The song matches. Replace whichever strings aren't empty. */
if(!ttab[i]->TitleTo.empty()) if( !ttab[i]->Dest.Title.empty() && tf.Title != ttab[i]->Dest.Title )
{ {
if(ttab[i]->translit && title != ttab[i]->TitleTo) ttitle = title; if( ttab[i]->translit )
title = ttab[i]->TitleTo; tf.TitleTranslit = tf.Title;
FontCharAliases::ReplaceMarkers( title ); tf.Title = ttab[i]->Dest.Title;
FontCharAliases::ReplaceMarkers( tf.Title );
} }
if(!ttab[i]->SubTo.empty()) if( !ttab[i]->Dest.Subtitle.empty() && tf.Subtitle != ttab[i]->Dest.Subtitle )
{ {
if(ttab[i]->translit && subtitle != ttab[i]->SubTo) tsubtitle = subtitle; if( ttab[i]->translit )
subtitle = ttab[i]->SubTo; tf.SubtitleTranslit = tf.Subtitle;
FontCharAliases::ReplaceMarkers( subtitle ); tf.Subtitle = ttab[i]->Dest.Subtitle;
FontCharAliases::ReplaceMarkers( tf.Subtitle );
} }
if( !ttab[i]->Dest.Artist.empty() && tf.Artist != ttab[i]->Dest.Artist )
if(!ttab[i]->ArtistTo.empty() && artist != ttab[i]->ArtistTo)
{ {
if(ttab[i]->translit) tartist = artist; if( ttab[i]->translit )
artist = ttab[i]->ArtistTo; tf.ArtistTranslit = tf.Artist;
FontCharAliases::ReplaceMarkers( artist ); tf.Artist = ttab[i]->Dest.Artist;
FontCharAliases::ReplaceMarkers( tf.Artist );
} }
/* These are used when applying kanji to a field that doesn't have the /* These are used when applying kanji to a field that doesn't have the
* correct data. Should be used sparingly. */ * correct data. Should be used sparingly. */
if(!ttab[i]->TitleTransTo.empty()) if( !ttab[i]->Dest.TitleTranslit.empty() )
{ {
ttitle = ttab[i]->TitleTransTo; tf.TitleTranslit = ttab[i]->Dest.TitleTranslit;
FontCharAliases::ReplaceMarkers( ttitle ); FontCharAliases::ReplaceMarkers( tf.TitleTranslit );
} }
if(!ttab[i]->SubTransTo.empty()) if( !ttab[i]->Dest.SubtitleTranslit.empty() )
{ {
tsubtitle = ttab[i]->SubTransTo; tf.SubtitleTranslit = ttab[i]->Dest.SubtitleTranslit;
FontCharAliases::ReplaceMarkers( tsubtitle ); FontCharAliases::ReplaceMarkers( tf.SubtitleTranslit );
} }
if(!ttab[i]->ArtistTransTo.empty()) if( !ttab[i]->Dest.ArtistTranslit.empty() )
{ {
tartist = ttab[i]->ArtistTransTo; tf.ArtistTranslit = ttab[i]->Dest.ArtistTranslit;
FontCharAliases::ReplaceMarkers( tartist ); FontCharAliases::ReplaceMarkers( tf.ArtistTranslit );
} }
} }
} }
@@ -155,12 +156,12 @@ void TitleSubst::Load(const CString &filename, const CString &section)
if(!id.CompareNoCase("TitleFrom")) tr.TitleFrom = "^(" + txt + ")$"; if(!id.CompareNoCase("TitleFrom")) tr.TitleFrom = "^(" + txt + ")$";
else if(!id.CompareNoCase("ArtistFrom")) tr.ArtistFrom = "^(" + txt + ")$"; else if(!id.CompareNoCase("ArtistFrom")) tr.ArtistFrom = "^(" + txt + ")$";
else if(!id.CompareNoCase("SubtitleFrom")) tr.SubFrom = "^(" + txt + ")$"; else if(!id.CompareNoCase("SubtitleFrom")) tr.SubFrom = "^(" + txt + ")$";
else if(!id.CompareNoCase("TitleTo")) tr.TitleTo = txt; else if(!id.CompareNoCase("TitleTo")) tr.Dest.Title = txt;
else if(!id.CompareNoCase("ArtistTo")) tr.ArtistTo = txt; else if(!id.CompareNoCase("ArtistTo")) tr.Dest.Artist = txt;
else if(!id.CompareNoCase("SubtitleTo")) tr.SubTo = txt; else if(!id.CompareNoCase("SubtitleTo")) tr.Dest.Subtitle = txt;
else if(!id.CompareNoCase("TitleTransTo")) tr.TitleTransTo = txt; else if(!id.CompareNoCase("TitleTransTo")) tr.Dest.TitleTranslit = txt;
else if(!id.CompareNoCase("ArtistTransTo")) tr.ArtistTransTo = txt; else if(!id.CompareNoCase("ArtistTransTo")) tr.Dest.ArtistTranslit = txt;
else if(!id.CompareNoCase("SubtitleTransTo")) tr.SubTransTo = txt; else if(!id.CompareNoCase("SubtitleTransTo")) tr.Dest.SubtitleTranslit = txt;
else else
LOG->Warn( "Unknown TitleSubst tag: \"%s\"", id.c_str() ); LOG->Warn( "Unknown TitleSubst tag: \"%s\"", id.c_str() );
} }
@@ -190,7 +191,26 @@ TitleSubst::~TitleSubst()
} }
/* /*
* Copyright (c) 2003 by the person(s) listed below. All rights reserved. * (c) 2003-2004 Glenn Maynard
* All rights reserved.
* *
* Glenn Maynard * Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, and/or sell copies of the Software, and to permit persons to
* whom the Software is furnished to do so, provided that the above
* copyright notice(s) and this permission notice appear in all copies of
* the Software and that both the above copyright notice(s) and this
* permission notice appear in supporting documentation.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
* THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS
* INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT
* OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/ */
+50 -4
View File
@@ -1,6 +1,34 @@
/* TitleSubst - automatic translation for song titles */
#ifndef TITLE_SUBSTITUTION_H #ifndef TITLE_SUBSTITUTION_H
#define TITLE_SUBSTITUTION_H 1 #define TITLE_SUBSTITUTION_H 1
struct TitleFields
{
void SaveToStrings( CString &sTitle, CString &sSubtitle, CString &sArtist,
CString &sTitleTranslit, CString &sSubtitleTranslit, CString &sArtistTranslit ) const
{
sTitle = Title;
sSubtitle = Subtitle;
sArtist = Artist;
sTitleTranslit = TitleTranslit;
sSubtitleTranslit = SubtitleTranslit;
sArtistTranslit = ArtistTranslit;
}
void LoadFromStrings( CString sTitle, CString sSubtitle, CString sArtist,
CString sTitleTranslit, CString sSubtitleTranslit, CString sArtistTranslit )
{
Title = sTitle;
Subtitle = sSubtitle;
Artist = sArtist;
TitleTranslit = sTitleTranslit;
SubtitleTranslit = sSubtitleTranslit;
ArtistTranslit = sArtistTranslit;
}
CString Title, Subtitle, Artist;
CString TitleTranslit, SubtitleTranslit, ArtistTranslit;
};
struct TitleTrans; struct TitleTrans;
class TitleSubst class TitleSubst
@@ -14,14 +42,32 @@ public:
void Load(const CString &filename, const CString &section); void Load(const CString &filename, const CString &section);
void Subst(CString &title, CString &sub, CString &artist, void Subst( TitleFields &tf );
CString &ttitle, CString &tsub, CString &tartist);
}; };
#endif #endif
/* /*
* Copyright (c) 2003 by the person(s) listed below. All rights reserved. * (c) 2003-2004 Glenn Maynard
* All rights reserved.
* *
* Glenn Maynard * Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, and/or sell copies of the Software, and to permit persons to
* whom the Software is furnished to do so, provided that the above
* copyright notice(s) and this permission notice appear in all copies of
* the Software and that both the above copyright notice(s) and this
* permission notice appear in supporting documentation.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
* THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS
* INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT
* OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/ */