use Regex

This commit is contained in:
Glenn Maynard
2003-01-23 04:25:04 +00:00
parent a81855f608
commit 6903d7047d
3 changed files with 29 additions and 10 deletions
+21 -5
View File
@@ -343,17 +343,20 @@ CString Font::GetFontName(CString FileName)
splitpath( FileName, sDir, sFName, sExt );
FileName = sFName;
/* If it ends in an extension, remove it. */
if(regex("\\....", FileName))
/* If it ends in an extension, remove it. XXX */
static Regex drop_ext("\\....");
if(drop_ext.Compare(FileName))
FileName.erase(FileName.size()-4);
/* If it ends in a dimension spec, remove it. */
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());
/* 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());
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.
*
* Possibilities:
@@ -541,7 +556,8 @@ void Font::LoadFontPageSettings(FontPageSettings &cfg, IniFile &ini, const CStri
* range Unicode #3041-3094=0
*/
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 */
+2
View File
@@ -132,6 +132,8 @@ public:
static const longchar DEFAULT_GLYPH;
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:
/* List of pages and fonts that we use (and are responsible for freeing). */
+6 -5
View File
@@ -563,17 +563,18 @@ void Song::TidyUpData()
struct TitleTrans
{
CString TitleFrom, SubFrom, ArtistFrom, /* regex */
TitleTo, SubTo, ArtistTo; /* plain text */
Regex TitleFrom, SubFrom, ArtistFrom;
CString TitleTo, SubTo, ArtistTo; /* plain text */
TitleTrans(CString tf, CString sf, CString af, CString tt, CString st, CString at):
TitleFrom(tf), SubFrom(sf), ArtistFrom(af),
TitleTo(tt), SubTo(st), ArtistTo(at) { }
bool Matches(CString title, CString sub, CString artist)
{
if(!TitleFrom.empty() && !regex(TitleFrom, title)) return false; /* no match */
if(!SubFrom.empty() && !regex(SubFrom, sub)) return false; /* no match */
if(!ArtistFrom.empty() && !regex(ArtistFrom, artist)) return false; /* no match */
if(!TitleFrom.Compare(title)) return false; /* no match */
if(!SubFrom.Compare(sub)) return false; /* no match */
if(!ArtistFrom.Compare(artist)) return false; /* no match */
return true;
}