pcSubst()
This commit is contained in:
parent
06abe1ec2f
commit
974f731f9b
@ -1,5 +1,5 @@
|
||||
#ifndef lint
|
||||
static char rcsid[] = "@(#$Id: smallut.cpp,v 1.17 2006-10-11 14:16:26 dockes Exp $ (C) 2004 J.F.Dockes";
|
||||
static char rcsid[] = "@(#$Id: smallut.cpp,v 1.18 2006-11-10 13:30:03 dockes Exp $ (C) 2004 J.F.Dockes";
|
||||
#endif
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@ -403,6 +403,33 @@ string escapeHtml(const string &in)
|
||||
return out;
|
||||
}
|
||||
|
||||
// Small utility to substitute printf-like percents cmds in a string
|
||||
bool pcSubst(const string& in, string& out, map<char, string>& subs)
|
||||
{
|
||||
string::const_iterator it;
|
||||
for (it = in.begin(); it != in.end();it++) {
|
||||
if (*it == '%') {
|
||||
if (++it == in.end()) {
|
||||
out += '%';
|
||||
break;
|
||||
}
|
||||
if (*it == '%') {
|
||||
out += '%';
|
||||
continue;
|
||||
}
|
||||
map<char,string>::iterator tr;
|
||||
if ((tr = subs.find(*it)) != subs.end()) {
|
||||
out += tr->second;
|
||||
} else {
|
||||
out += *it;
|
||||
}
|
||||
} else {
|
||||
out += *it;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
////////////////////
|
||||
// Internal redefinition of system time interface to help with dependancies
|
||||
struct m_timespec {
|
||||
|
||||
@ -16,13 +16,15 @@
|
||||
*/
|
||||
#ifndef _SMALLUT_H_INCLUDED_
|
||||
#define _SMALLUT_H_INCLUDED_
|
||||
/* @(#$Id: smallut.h,v 1.17 2006-10-11 14:16:26 dockes Exp $ (C) 2004 J.F.Dockes */
|
||||
/* @(#$Id: smallut.h,v 1.18 2006-11-10 13:30:03 dockes Exp $ (C) 2004 J.F.Dockes */
|
||||
#include <string>
|
||||
#include <list>
|
||||
#include <map>
|
||||
|
||||
#ifndef NO_NAMESPACES
|
||||
using std::string;
|
||||
using std::list;
|
||||
using std::map;
|
||||
#endif /* NO_NAMESPACES */
|
||||
|
||||
extern int stringicmp(const string& s1, const string& s2);
|
||||
@ -67,6 +69,9 @@ extern string neutchars(const string &str, string chars);
|
||||
* if reasonably possible. */
|
||||
extern string truncate_to_word(string &input, string::size_type maxlen);
|
||||
|
||||
/** Small utility to substitute printf-like percents cmds in a string */
|
||||
bool pcSubst(const string& in, string& out, map<char, string>& subs);
|
||||
|
||||
class Chrono {
|
||||
public:
|
||||
Chrono();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user