rationalize stopsuffix list usage
This commit is contained in:
parent
0bf54fe7d6
commit
02c14a6281
@ -1,5 +1,5 @@
|
|||||||
#ifndef lint
|
#ifndef lint
|
||||||
static char rcsid[] = "@(#$Id: rclconfig.cpp,v 1.33 2006-11-20 15:28:14 dockes Exp $ (C) 2004 J.F.Dockes";
|
static char rcsid[] = "@(#$Id: rclconfig.cpp,v 1.34 2006-12-11 14:50:53 dockes Exp $ (C) 2004 J.F.Dockes";
|
||||||
#endif
|
#endif
|
||||||
/*
|
/*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
@ -230,7 +230,7 @@ std::list<string> RclConfig::getAllMimeTypes()
|
|||||||
return lst;
|
return lst;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RclConfig::getStopSuffixes(list<string>& sufflist)
|
const list<string>* RclConfig::getStopSuffixes()
|
||||||
{
|
{
|
||||||
if (stopsuffixes == 0 && (stopsuffixes = new list<string>) != 0) {
|
if (stopsuffixes == 0 && (stopsuffixes = new list<string>) != 0) {
|
||||||
string stp;
|
string stp;
|
||||||
@ -239,11 +239,7 @@ bool RclConfig::getStopSuffixes(list<string>& sufflist)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stopsuffixes) {
|
return stopsuffixes;
|
||||||
sufflist = *stopsuffixes;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
string RclConfig::getMimeTypeFromSuffix(const string &suff)
|
string RclConfig::getMimeTypeFromSuffix(const string &suff)
|
||||||
|
|||||||
@ -16,7 +16,7 @@
|
|||||||
*/
|
*/
|
||||||
#ifndef _RCLCONFIG_H_INCLUDED_
|
#ifndef _RCLCONFIG_H_INCLUDED_
|
||||||
#define _RCLCONFIG_H_INCLUDED_
|
#define _RCLCONFIG_H_INCLUDED_
|
||||||
/* @(#$Id: rclconfig.h,v 1.25 2006-11-20 15:28:04 dockes Exp $ (C) 2004 J.F.Dockes */
|
/* @(#$Id: rclconfig.h,v 1.26 2006-12-11 14:50:53 dockes Exp $ (C) 2004 J.F.Dockes */
|
||||||
|
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <string>
|
#include <string>
|
||||||
@ -84,7 +84,7 @@ class RclConfig {
|
|||||||
* The list is initialized on first call, and not changed for subsequent
|
* The list is initialized on first call, and not changed for subsequent
|
||||||
* setKeydirs.
|
* setKeydirs.
|
||||||
*/
|
*/
|
||||||
bool getStopSuffixes(list<string>& sufflist);
|
const list<string>* getStopSuffixes();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check in mimeconf if input mime type is a compressed one, and
|
* Check in mimeconf if input mime type is a compressed one, and
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
#ifndef lint
|
#ifndef lint
|
||||||
static char rcsid[] = "@(#$Id: mimetype.cpp,v 1.17 2006-03-21 11:04:39 dockes Exp $ (C) 2004 J.F.Dockes";
|
static char rcsid[] = "@(#$Id: mimetype.cpp,v 1.18 2006-12-11 14:50:53 dockes Exp $ (C) 2004 J.F.Dockes";
|
||||||
#endif
|
#endif
|
||||||
/*
|
/*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
@ -109,15 +109,11 @@ string mimetype(const string &fn, RclConfig *cfg, bool usfc)
|
|||||||
if (cfg == 0)
|
if (cfg == 0)
|
||||||
return "";
|
return "";
|
||||||
|
|
||||||
list<string> stoplist;
|
const list<string>* stoplist = cfg->getStopSuffixes();
|
||||||
cfg->getStopSuffixes(stoplist);
|
if (stoplist && !stoplist->empty()) {
|
||||||
if (!stoplist.empty()) {
|
for (list<string>::const_iterator it = stoplist->begin();
|
||||||
for (list<string>::const_iterator it = stoplist.begin();
|
it != stoplist->end(); it++) {
|
||||||
it != stoplist.end(); it++) {
|
if (!stringisuffcmp(fn, *it)) {
|
||||||
if (it->length() > fn.length())
|
|
||||||
continue;
|
|
||||||
if (!stringicmp(fn.substr(fn.length() - it->length(),
|
|
||||||
string::npos), *it)) {
|
|
||||||
LOGDEB(("mimetype: fn %s in stoplist (%s)\n", fn.c_str(),
|
LOGDEB(("mimetype: fn %s in stoplist (%s)\n", fn.c_str(),
|
||||||
it->c_str()));
|
it->c_str()));
|
||||||
return "";
|
return "";
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
#ifndef lint
|
#ifndef lint
|
||||||
static char rcsid[] = "@(#$Id: smallut.cpp,v 1.20 2006-12-07 07:07:18 dockes Exp $ (C) 2004 J.F.Dockes";
|
static char rcsid[] = "@(#$Id: smallut.cpp,v 1.21 2006-12-11 14:50:53 dockes Exp $ (C) 2004 J.F.Dockes";
|
||||||
#endif
|
#endif
|
||||||
/*
|
/*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
@ -120,6 +120,21 @@ int stringicmp(const string & s1, const string& s2)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extern int stringisuffcmp(const string& s1, const string& s2)
|
||||||
|
{
|
||||||
|
string::const_reverse_iterator r1 = s1.rbegin(), re1 = s1.rend(),
|
||||||
|
r2 = s2.rbegin(), re2 = s2.rend();
|
||||||
|
while (r1 != re1 && r2 != re2) {
|
||||||
|
char c1 = ::toupper(*r1);
|
||||||
|
char c2 = ::toupper(*r2);
|
||||||
|
if (c1 != c2) {
|
||||||
|
return c1 > c2 ? 1 : -1;
|
||||||
|
}
|
||||||
|
++r1; ++r2;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
// s1 is already lowercase
|
// s1 is already lowercase
|
||||||
int stringlowercmp(const string & s1, const string& s2)
|
int stringlowercmp(const string & s1, const string& s2)
|
||||||
{
|
{
|
||||||
@ -570,9 +585,22 @@ struct spair pairs[] = {
|
|||||||
{"a", "Ab"},
|
{"a", "Ab"},
|
||||||
};
|
};
|
||||||
int npairs = sizeof(pairs) / sizeof(struct spair);
|
int npairs = sizeof(pairs) / sizeof(struct spair);
|
||||||
|
struct spair suffpairs[] = {
|
||||||
|
{"", ""},
|
||||||
|
{"", "a"},
|
||||||
|
{"a", ""},
|
||||||
|
{"a", "a"},
|
||||||
|
{"toto.txt", ".txt"},
|
||||||
|
{"TXT", "toto.txt"},
|
||||||
|
{"toto.txt", ".txt1"},
|
||||||
|
{"toto.txt1", ".txt"},
|
||||||
|
};
|
||||||
|
int nsuffpairs = sizeof(suffpairs) / sizeof(struct spair);
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
|
#if 0
|
||||||
for (int i = 0; i < npairs; i++) {
|
for (int i = 0; i < npairs; i++) {
|
||||||
{
|
{
|
||||||
int c = stringicmp(pairs[i].s1, pairs[i].s2);
|
int c = stringicmp(pairs[i].s1, pairs[i].s2);
|
||||||
@ -591,6 +619,14 @@ int main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
for (int i = 0; i < nsuffpairs; i++) {
|
||||||
|
int c = stringisuffcmp(suffpairs[i].s1, suffpairs[i].s2);
|
||||||
|
printf("[%s] %s [%s] \n", suffpairs[i].s1,
|
||||||
|
c == 0 ? "matches" : c < 0 ? "<" : ">", suffpairs[i].s2);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -16,7 +16,7 @@
|
|||||||
*/
|
*/
|
||||||
#ifndef _SMALLUT_H_INCLUDED_
|
#ifndef _SMALLUT_H_INCLUDED_
|
||||||
#define _SMALLUT_H_INCLUDED_
|
#define _SMALLUT_H_INCLUDED_
|
||||||
/* @(#$Id: smallut.h,v 1.20 2006-12-07 07:07:18 dockes Exp $ (C) 2004 J.F.Dockes */
|
/* @(#$Id: smallut.h,v 1.21 2006-12-11 14:50:53 dockes Exp $ (C) 2004 J.F.Dockes */
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <map>
|
#include <map>
|
||||||
@ -31,6 +31,9 @@ extern int stringicmp(const string& s1, const string& s2);
|
|||||||
extern int stringlowercmp(const string& alreadylower, const string& s2);
|
extern int stringlowercmp(const string& alreadylower, const string& s2);
|
||||||
extern int stringuppercmp(const string& alreadyupper, const string& s2);
|
extern int stringuppercmp(const string& alreadyupper, const string& s2);
|
||||||
|
|
||||||
|
// Is one string the end part of the other ?
|
||||||
|
extern int stringisuffcmp(const string& s1, const string& s2);
|
||||||
|
|
||||||
// Compare charset names, removing the more common spelling variations
|
// Compare charset names, removing the more common spelling variations
|
||||||
extern bool samecharset(const string &cs1, const string &cs2);
|
extern bool samecharset(const string &cs1, const string &cs2);
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user