fix queryBuildAbstract option functionality. Allow substituting %(fieldname) in reslist paragraph format

This commit is contained in:
dockes
2009-10-21 12:02:59 +00:00
parent 0cf33ede6b
commit fb2994ea74
8 changed files with 121 additions and 37 deletions
+5 -3
View File
@@ -72,12 +72,14 @@ trmimeparse.o : mimeparse.cpp
$(CXX) $(ALL_CXXFLAGS) -DTEST_MIMEPARSE -c -o trmimeparse.o \
mimeparse.cpp
SMALLUT_OBJS= trsmallut.o $(BIGLIB)
smallut : $(SMALLUT_OBJS)
SMALLUT_OBJS= trsmallut.o ../lib/smallut.o
smallut : $(SMALLUT_OBJS) smallut.h
$(CXX) $(ALL_CXXFLAGS) -o smallut $(SMALLUT_OBJS) $(LIBICONV)
trsmallut.o : smallut.cpp
trsmallut.o : smallut.cpp smallut.h
$(CXX) $(ALL_CXXFLAGS) -DTEST_SMALLUT -c -o trsmallut.o \
smallut.cpp
../lib/smallut.o: smallut.cpp smallut.h
cd ../lib;make smallut.o
WIPEDIR_OBJS= trwipedir.o $(BIGLIB)
wipedir : $(WIPEDIR_OBJS)
+72 -2
View File
@@ -492,7 +492,8 @@ bool pcSubst(const string& in, string& out, map<char, string>& subs)
if ((tr = subs.find(*it)) != subs.end()) {
out += tr->second;
} else {
out += *it;
// We used to do "out += *it;" here but this does not make
// sense
}
} else {
out += *it;
@@ -501,6 +502,52 @@ bool pcSubst(const string& in, string& out, map<char, string>& subs)
return true;
}
bool pcSubst(const string& in, string& out, map<string, string>& subs)
{
out.erase();
string::size_type i;
for (i = 0; i < in.size(); i++) {
if (in[i] == '%') {
if (++i == in.size()) {
out += '%';
break;
}
if (in[i] == '%') {
out += '%';
continue;
}
string key = "";
if (in[i] == '(') {
if (++i == in.size()) {
out += string("%(");
break;
}
string::size_type j = in.find_first_of(")", i);
if (j == string::npos) {
// ??concatenate remaining part and stop
out += in.substr(i-2);
break;
}
key = in.substr(i, j-i);
i = j;
} else {
key = in[i];
}
map<string,string>::iterator tr;
if ((tr = subs.find(key)) != subs.end()) {
out += tr->second;
} else {
// Substitute to nothing, that's the reasonable thing to do
// instead of keeping the %(key)
// out += key.size()==1? key : string("(") + key + string(")");
}
} else {
out += in[i];
}
}
return true;
}
// Convert byte count into unit (KB/MB...) appropriate for display
string displayableBytes(long size)
{
@@ -712,11 +759,34 @@ int main(int argc, char **argv)
utf8truncate(testit, sz);
cout << testit << endl;
}
#elif 1
#elif 0
std::string testit("ligne\ndeuxieme ligne\r3eme ligne\r\n");
cout << "[" << neutchars(testit, "\r\n") << "]" << endl;
string i, o;
cout << "neutchars(null) is [" << neutchars(i, "\r\n") << "]" << endl;
#elif 1
map<string, string> substs;
substs["a"] = "A_SUBST";
substs["title"] = "TITLE_SUBST";
string in = "a: %a title: %(title) pcpc: %% %";
string out;
pcSubst(in, out, substs);
cout << in << " => " << out << endl;
in = "unfinished: %(unfinished";
pcSubst(in, out, substs);
cout << in << " => " << out << endl;
in = "unfinished: %(";
pcSubst(in, out, substs);
cout << in << " => " << out << endl;
in = "empty: %()";
pcSubst(in, out, substs);
cout << in << " => " << out << endl;
substs.clear();
in = "a: %a title: %(title) pcpc: %% %";
pcSubst(in, out, substs);
cout << "After map clear: " << in << " => " << out << endl;
#endif
}
+2
View File
@@ -102,6 +102,8 @@ string breakIntoLines(const string& in, unsigned int ll = 100,
unsigned int maxlines= 50);
/** Small utility to substitute printf-like percents cmds in a string */
bool pcSubst(const string& in, string& out, map<char, string>& subs);
/** Substitute printf-like percents and also %(key) */
bool pcSubst(const string& in, string& out, map<string, string>& subs);
class Chrono {
public: