"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "utils/smallut.h" between
recoll-1.27.11.tar.gz and recoll-1.27.12.tar.gz

About: Recoll is a personal full text search tool based on Xapian as back-end (with Qt GUI).

smallut.h  (recoll-1.27.11):smallut.h  (recoll-1.27.12)
skipping to change at line 26 skipping to change at line 26
* 02110-1301 USA * 02110-1301 USA
*/ */
#ifndef _SMALLUT_H_INCLUDED_ #ifndef _SMALLUT_H_INCLUDED_
#define _SMALLUT_H_INCLUDED_ #define _SMALLUT_H_INCLUDED_
#include <stdint.h> #include <stdint.h>
#include <time.h> #include <time.h>
#include <string> #include <string>
#include <vector> #include <vector>
#include <map> #include <map>
#include <set>
// Miscellaneous mostly string-oriented small utilities // Miscellaneous mostly string-oriented small utilities
// Note that none of the following code knows about utf-8. // Note that none of the following code knows about utf-8.
// Call this before going multithread. // Call this before going multithread.
void smallut_init_mt(); void smallut_init_mt();
#ifndef SMALLUT_DISABLE_MACROS #ifndef SMALLUT_DISABLE_MACROS
#ifndef MIN #ifndef MIN
#define MIN(A,B) (((A)<(B)) ? (A) : (B)) #define MIN(A,B) (((A)<(B)) ? (A) : (B))
skipping to change at line 74 skipping to change at line 73
const std::string& s2); const std::string& s2);
extern int stringuppercmp(const std::string& s1, // already upper extern int stringuppercmp(const std::string& s1, // already upper
const std::string& s2); const std::string& s2);
extern void stringtolower(std::string& io); extern void stringtolower(std::string& io);
extern std::string stringtolower(const std::string& io); extern std::string stringtolower(const std::string& io);
extern void stringtoupper(std::string& io); extern void stringtoupper(std::string& io);
extern std::string stringtoupper(const std::string& io); extern std::string stringtoupper(const std::string& io);
extern bool beginswith(const std::string& bg, const std::string& sml); extern bool beginswith(const std::string& bg, const std::string& sml);
// Is one string the end part of the other ?
extern int stringisuffcmp(const std::string& s1, const std::string& s2);
// Divine language from locale
extern std::string localelang();
// Divine 8bit charset from language
extern std::string langtocode(const std::string& lang);
// Compare charset names, removing the more common spelling variations
extern bool samecharset(const std::string& cs1, const std::string& cs2);
// Parse date interval specifier into pair of y,m,d dates. The format // Parse date interval specifier into pair of y,m,d dates. The format
// for the time interval is based on a subset of iso 8601 with // for the time interval is based on a subset of iso 8601 with
// the addition of open intervals, and removal of all time indications. // the addition of open intervals, and removal of all time indications.
// 'P' is the Period indicator, it's followed by a length in // 'P' is the Period indicator, it's followed by a length in
// years/months/days (or any subset thereof) // years/months/days (or any subset thereof)
// Dates: YYYY-MM-DD YYYY-MM YYYY // Dates: YYYY-MM-DD YYYY-MM YYYY
// Periods: P[nY][nM][nD] where n is an integer value. // Periods: P[nY][nM][nD] where n is an integer value.
// At least one of YMD must be specified // At least one of YMD must be specified
// The separator for the interval is /. Interval examples // The separator for the interval is /. Interval examples
// YYYY/ (from YYYY) YYYY-MM-DD/P3Y (3 years after date) etc. // YYYY/ (from YYYY) YYYY-MM-DD/P3Y (3 years after date) etc.
skipping to change at line 107 skipping to change at line 95
int y1; int y1;
int m1; int m1;
int d1; int d1;
int y2; int y2;
int m2; int m2;
int d2; int d2;
}; };
extern bool parsedateinterval(const std::string& s, DateInterval *di); extern bool parsedateinterval(const std::string& s, DateInterval *di);
extern int monthdays(int mon, int year); extern int monthdays(int mon, int year);
/** Note for all templated functions:
* By default, smallut.cpp has explicit instantiations for common
* containers (list, vector, set, etc.). If this is not enough, or
* conversely, if you want to minimize the module size, you can chose
* the instantiations by defining the SMALLUT_EXTERNAL_INSTANTIATIONS
* compilation flag, and defining the instances in a file named
* smallut_instantiations.h
*/
/** /**
* Parse input string into list of strings. * Parse input string into list of strings. See instantiation note above.
* *
* Token delimiter is " \t\n" except inside dquotes. dquote inside * Token delimiter is " \t\n" except inside dquotes. dquote inside
* dquotes can be escaped with \ etc... * dquotes can be escaped with \ etc...
* Input is handled a byte at a time, things will work as long as * Input is handled a byte at a time, things will work as long as
* space tab etc. have the ascii values and can't appear as part of a * space tab etc. have the ascii values and can't appear as part of a
* multibyte char. utf-8 ok but so are the iso-8859-x and surely * multibyte char. utf-8 ok but so are the iso-8859-x and surely
* others. addseps do have to be single-bytes * others. addseps do have to be single-bytes
*/ */
template <class T> bool stringToStrings(const std::string& s, T& tokens, template <class T> bool stringToStrings(const std::string& s, T& tokens,
const std::string& addseps = ""); const std::string& addseps = "");
/** /**
* Inverse operation: * Inverse operation. See instantiation note above.
*/ */
template <class T> void stringsToString(const T& tokens, std::string& s); template <class T> void stringsToString(const T& tokens, std::string& s);
template <class T> std::string stringsToString(const T& tokens); template <class T> std::string stringsToString(const T& tokens);
/** /**
* Strings to CSV string. tokens containing the separator are quoted (") * Strings to CSV string. tokens containing the separator are quoted (")
* " inside tokens is escaped as "" ([word "quote"] =>["word ""quote"""] * " inside tokens is escaped as "" ([word "quote"] =>["word ""quote"""]
* See instantiation note above.
*/ */
template <class T> void stringsToCSV(const T& tokens, std::string& s, template <class T> void stringsToCSV(const T& tokens, std::string& s,
char sep = ','); char sep = ',');
/** /**
* Split input string. No handling of quoting * Split input string. No handling of quoting.
*/ */
extern void stringToTokens(const std::string& s, extern void stringToTokens(const std::string& s,
std::vector<std::string>& tokens, std::vector<std::string>& tokens,
const std::string& delims = " \t", const std::string& delims = " \t",
bool skipinit = true); bool skipinit = true);
/** Like toTokens but with multichar separator */ /** Like toTokens but with multichar separator */
extern void stringSplitString(const std::string& str, extern void stringSplitString(const std::string& str,
std::vector<std::string>& tokens, std::vector<std::string>& tokens,
const std::string& sep); const std::string& sep);
skipping to change at line 214 skipping to change at line 212
{ {
if (s.length() && s.length() < len) { if (s.length() && s.length() < len) {
s = s.insert(0, len - s.length(), '0'); s = s.insert(0, len - s.length(), '0');
} }
} }
// Print binary string in hexa, separate bytes with character separ if not zero // Print binary string in hexa, separate bytes with character separ if not zero
// (e.g. ac:23:0c:4f:46:fd) // (e.g. ac:23:0c:4f:46:fd)
extern std::string hexprint(const std::string& in, char separ= 0); extern std::string hexprint(const std::string& in, char separ= 0);
#ifndef SMALLUT_NO_REGEX
// A class to solve platorm/compiler issues for simple regex // A class to solve platorm/compiler issues for simple regex
// matches. Uses the appropriate native lib under the hood. // matches. Uses the appropriate native lib under the hood.
// This always uses extended regexp syntax. // This always uses extended regexp syntax.
class SimpleRegexp { class SimpleRegexp {
public: public:
enum Flags {SRE_NONE = 0, SRE_ICASE = 1, SRE_NOSUB = 2}; enum Flags {SRE_NONE = 0, SRE_ICASE = 1, SRE_NOSUB = 2};
/// @param nmatch must be >= the number of parenthesed subexp in exp /// @param nmatch must be >= the number of parenthesed subexp in exp
SimpleRegexp(const std::string& exp, int flags, int nmatch = 0); SimpleRegexp(const std::string& exp, int flags, int nmatch = 0);
~SimpleRegexp(); ~SimpleRegexp();
/// Match input against exp, return true if matches /// Match input against exp, return true if matches
bool simpleMatch(const std::string& val) const; bool simpleMatch(const std::string& val) const;
/// After simpleMatch success, get nth submatch, 0 is the whole /// After simpleMatch success, get nth submatch, 0 is the whole
/// match, 1 first parentheses, etc. /// match, 1 first parentheses, etc.
std::string getMatch(const std::string& val, int i) const; std::string getMatch(const std::string& val, int i) const;
/// Calls simpleMatch() /// Calls simpleMatch()
bool operator() (const std::string& val) const; bool operator() (const std::string& val) const;
/// Replace the first occurrence of regexp.
std::string simpleSub(const std::string& input, const std::string& repl);
/// Check after construction /// Check after construction
bool ok() const; bool ok() const;
class Internal; class Internal;
private: private:
Internal *m; Internal *m;
}; };
#endif // SMALLUT_NO_REGEX
/// Utilities for printing names for defined values (Ex: O_RDONLY->"O_RDONLY") /// Utilities for printing names for defined values (Ex: O_RDONLY->"O_RDONLY")
/// Entries for the descriptive table /// Entries for the descriptive table
struct CharFlags { struct CharFlags {
CharFlags(int v, const char *y, const char *n=nullptr) CharFlags(int v, const char *y, const char *n=nullptr)
: value(v), yesname(y), noname(n) {} : value(v), yesname(y), noname(n) {}
unsigned int value; // Flag or value unsigned int value; // Flag or value
const char *yesname;// String to print if flag set or equal const char *yesname;// String to print if flag set or equal
const char *noname; // String to print if flag not set (unused for values) const char *noname; // String to print if flag not set (unused for values)
skipping to change at line 260 skipping to change at line 264
/// flag/value defined name /// flag/value defined name
#define CHARFLAGENTRY(NM) {NM, #NM} #define CHARFLAGENTRY(NM) {NM, #NM}
/// Translate a bitfield into string description /// Translate a bitfield into string description
extern std::string flagsToString(const std::vector<CharFlags>&, extern std::string flagsToString(const std::vector<CharFlags>&,
unsigned int val); unsigned int val);
/// Translate a value into a name /// Translate a value into a name
extern std::string valToString(const std::vector<CharFlags>&, unsigned int val); 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_ */
 End of changes. 11 change blocks. 
20 lines changed or deleted 19 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)