sync with common
This commit is contained in:
parent
ee58aabdbe
commit
c03bd1b91a
2 changed files with 92 additions and 16 deletions
|
@ -14,12 +14,6 @@
|
||||||
* Free Software Foundation, Inc.,
|
* Free Software Foundation, Inc.,
|
||||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
*/
|
*/
|
||||||
#ifdef BUILDING_RECOLL
|
|
||||||
#include "autoconfig.h"
|
|
||||||
#else
|
|
||||||
#include "config.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
@ -523,16 +517,13 @@ string escapeHtml(const string& in)
|
||||||
{
|
{
|
||||||
string out;
|
string out;
|
||||||
for (string::size_type pos = 0; pos < in.length(); pos++) {
|
for (string::size_type pos = 0; pos < in.length(); pos++) {
|
||||||
switch (in.at(pos)) {
|
switch(in.at(pos)) {
|
||||||
case '<':
|
case '<': out += "<"; break;
|
||||||
out += "<";
|
case '>': out += ">"; break;
|
||||||
break;
|
case '&': out += "&"; break;
|
||||||
case '&':
|
case '"': out += """; break;
|
||||||
out += "&";
|
default: out += in.at(pos); break;
|
||||||
break;
|
}
|
||||||
default:
|
|
||||||
out += in.at(pos);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
@ -1323,6 +1314,66 @@ bool SimpleRegexp::operator() (const string& val) const
|
||||||
return simpleMatch(val);
|
return simpleMatch(val);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
string flagsToString(const vector<CharFlags>& flags, unsigned int val)
|
||||||
|
{
|
||||||
|
const char *s;
|
||||||
|
string out;
|
||||||
|
for (auto& flag : flags) {
|
||||||
|
if ((val & flag.value) == flag.value) {
|
||||||
|
s = flag.yesname;
|
||||||
|
} else {
|
||||||
|
s = flag.noname;
|
||||||
|
}
|
||||||
|
if (s && *s) {
|
||||||
|
/* We have something to write */
|
||||||
|
if (out.length()) {
|
||||||
|
// If not first, add '|' separator
|
||||||
|
out.append("|");
|
||||||
|
}
|
||||||
|
out.append(s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
string valToString(const vector<CharFlags>& flags, unsigned int val)
|
||||||
|
{
|
||||||
|
string out;
|
||||||
|
for (auto& flag : flags) {
|
||||||
|
if (flag.value == val) {
|
||||||
|
out = flag.yesname;
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
{
|
||||||
|
char mybuf[100];
|
||||||
|
sprintf(mybuf, "Unknown Value 0x%x", val);
|
||||||
|
out = mybuf;
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int stringToFlags(const vector<CharFlags>& flags,
|
||||||
|
const string& input, const char *sep)
|
||||||
|
{
|
||||||
|
unsigned int out = 0;
|
||||||
|
|
||||||
|
vector<string> toks;
|
||||||
|
stringToTokens(input, toks, sep);
|
||||||
|
for (auto& tok: toks) {
|
||||||
|
trimstring(tok);
|
||||||
|
for (auto& flag : flags) {
|
||||||
|
if (!tok.compare(flag.yesname)) {
|
||||||
|
/* Note: we don't break: the same name could conceivably
|
||||||
|
set several flags. */
|
||||||
|
out |= flag.value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Initialization for static stuff to be called from main thread before going
|
// Initialization for static stuff to be called from main thread before going
|
||||||
// multiple
|
// multiple
|
||||||
void smallut_init_mt()
|
void smallut_init_mt()
|
||||||
|
|
|
@ -218,4 +218,29 @@ private:
|
||||||
Internal *m;
|
Internal *m;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// Utilities for printing names for defined values (Ex: O_RDONLY->"O_RDONLY")
|
||||||
|
|
||||||
|
/// Entries for the descriptive table
|
||||||
|
struct CharFlags {
|
||||||
|
unsigned int value; // Flag or value
|
||||||
|
const char *yesname;// String to print if flag set or equal
|
||||||
|
const char *noname; // String to print if flag not set (unused for values)
|
||||||
|
};
|
||||||
|
|
||||||
|
/// Helper macro for the common case where we want to print the
|
||||||
|
/// flag/value defined name
|
||||||
|
#define CHARFLAGENTRY(NM) {NM, #NM}
|
||||||
|
|
||||||
|
/// Translate a bitfield into string description
|
||||||
|
extern std::string flagsToString(const std::vector<CharFlags>&,
|
||||||
|
unsigned int flags);
|
||||||
|
|
||||||
|
/// Translate a value into a name
|
||||||
|
extern std::string valToString(const std::vector<CharFlags>&, unsigned int val);
|
||||||
|
|
||||||
|
/// Reverse operation: translate string into bitfield
|
||||||
|
extern unsigned int
|
||||||
|
stringToFlags(const std::vector<CharFlags>&, const std::string& input,
|
||||||
|
const char *sep = "|");
|
||||||
|
|
||||||
#endif /* _SMALLUT_H_INCLUDED_ */
|
#endif /* _SMALLUT_H_INCLUDED_ */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue