use Regex
This commit is contained in:
+21
-5
@@ -343,17 +343,20 @@ CString Font::GetFontName(CString FileName)
|
|||||||
splitpath( FileName, sDir, sFName, sExt );
|
splitpath( FileName, sDir, sFName, sExt );
|
||||||
FileName = sFName;
|
FileName = sFName;
|
||||||
|
|
||||||
/* If it ends in an extension, remove it. */
|
/* If it ends in an extension, remove it. XXX */
|
||||||
if(regex("\\....", FileName))
|
static Regex drop_ext("\\....");
|
||||||
|
if(drop_ext.Compare(FileName))
|
||||||
FileName.erase(FileName.size()-4);
|
FileName.erase(FileName.size()-4);
|
||||||
|
|
||||||
/* If it ends in a dimension spec, remove it. */
|
/* If it ends in a dimension spec, remove it. */
|
||||||
CStringArray mat;
|
CStringArray mat;
|
||||||
if(regex("( [0-9]+x[0-9]+)$", FileName, mat))
|
static Regex DimSpec("( [0-9]+x[0-9]+)$");
|
||||||
|
if(DimSpec.Compare(FileName, mat))
|
||||||
FileName.erase(FileName.size()-mat[0].size());
|
FileName.erase(FileName.size()-mat[0].size());
|
||||||
|
|
||||||
/* If it ends in a page name, remove it. */
|
/* If it ends in a page name, remove it. */
|
||||||
if(regex("( \\[.+\\])$", FileName, mat))
|
static Regex PageName("( \\[.+\\])$");
|
||||||
|
if(PageName.Compare(FileName, mat))
|
||||||
FileName.erase(FileName.size()-mat[0].size());
|
FileName.erase(FileName.size()-mat[0].size());
|
||||||
|
|
||||||
TrimRight(FileName);
|
TrimRight(FileName);
|
||||||
@@ -366,6 +369,18 @@ CString Font::GetFontName(CString FileName)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Font::WeedFontNames(vector<CString> &v, const CString &FileName)
|
||||||
|
{
|
||||||
|
CString FontName = Font::GetFontName(FileName);
|
||||||
|
/* Weed out false matches. (For example, this gets rid of "normal2" when
|
||||||
|
* we're really looking for "normal".) */
|
||||||
|
for(unsigned i = 0; i < v.size(); ) {
|
||||||
|
if(FontName.CompareNoCase(Font::GetFontName(v[i])))
|
||||||
|
v.erase(v.begin()+i);
|
||||||
|
else i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Given a file in a font, find all of the files for the font.
|
/* Given a file in a font, find all of the files for the font.
|
||||||
*
|
*
|
||||||
* Possibilities:
|
* Possibilities:
|
||||||
@@ -541,7 +556,8 @@ void Font::LoadFontPageSettings(FontPageSettings &cfg, IniFile &ini, const CStri
|
|||||||
* range Unicode #3041-3094=0
|
* range Unicode #3041-3094=0
|
||||||
*/
|
*/
|
||||||
vector<CString> matches;
|
vector<CString> matches;
|
||||||
bool match = regex("^RANGE ([A-Z\\-]+)( ?#([0-9A-F]+)-([0-9A-F]+))?$" , val, matches);
|
static Regex parse("^RANGE ([A-Z\\-]+)( ?#([0-9A-F]+)-([0-9A-F]+))?$");
|
||||||
|
bool match = parse.Compare(val, matches);
|
||||||
|
|
||||||
ASSERT(matches.size() == 4); /* 4 parens */
|
ASSERT(matches.size() == 4); /* 4 parens */
|
||||||
|
|
||||||
|
|||||||
@@ -132,6 +132,8 @@ public:
|
|||||||
static const longchar DEFAULT_GLYPH;
|
static const longchar DEFAULT_GLYPH;
|
||||||
|
|
||||||
static CString GetFontName(CString FileName);
|
static CString GetFontName(CString FileName);
|
||||||
|
/* Remove filenames in 'v' that aren't in the same font as "FileName". */
|
||||||
|
static void WeedFontNames(vector<CString> &v, const CString &FileName);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/* List of pages and fonts that we use (and are responsible for freeing). */
|
/* List of pages and fonts that we use (and are responsible for freeing). */
|
||||||
|
|||||||
@@ -563,17 +563,18 @@ void Song::TidyUpData()
|
|||||||
|
|
||||||
struct TitleTrans
|
struct TitleTrans
|
||||||
{
|
{
|
||||||
CString TitleFrom, SubFrom, ArtistFrom, /* regex */
|
Regex TitleFrom, SubFrom, ArtistFrom;
|
||||||
TitleTo, SubTo, ArtistTo; /* plain text */
|
CString TitleTo, SubTo, ArtistTo; /* plain text */
|
||||||
|
|
||||||
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):
|
||||||
TitleFrom(tf), SubFrom(sf), ArtistFrom(af),
|
TitleFrom(tf), SubFrom(sf), ArtistFrom(af),
|
||||||
TitleTo(tt), SubTo(st), ArtistTo(at) { }
|
TitleTo(tt), SubTo(st), ArtistTo(at) { }
|
||||||
|
|
||||||
bool Matches(CString title, CString sub, CString artist)
|
bool Matches(CString title, CString sub, CString artist)
|
||||||
{
|
{
|
||||||
if(!TitleFrom.empty() && !regex(TitleFrom, title)) return false; /* no match */
|
if(!TitleFrom.Compare(title)) return false; /* no match */
|
||||||
if(!SubFrom.empty() && !regex(SubFrom, sub)) return false; /* no match */
|
if(!SubFrom.Compare(sub)) return false; /* no match */
|
||||||
if(!ArtistFrom.empty() && !regex(ArtistFrom, artist)) return false; /* no match */
|
if(!ArtistFrom.Compare(artist)) return false; /* no match */
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user