7 #ifndef _MIMETIC_UTILS_H_
8 #define _MIMETIC_UTILS_H_
12 #include <mimetic/libconfig.h>
13 #include <mimetic/strutils.h>
18 std::ostream& crlf(std::ostream&);
19 std::ostream& nl(std::ostream&);
22 inline int isblank(
char c)
24 return c ==
' ' || c ==
'\t';
32 std::string extractFilename(
const std::string&);
35 std::string int2str(
int n);
38 bool string_is_blank(
const std::string&);
41 int str2int(
const std::string& s);
44 std::string int2hex(
unsigned int n);
47 template<
typename Iterator>
48 Iterator find_bm(Iterator bit, Iterator eit,
const std::string& word,
const std::random_access_iterator_tag&)
50 int bLen = word.length();
51 const char* pWord = word.c_str();
55 for(i = 0; i < 256; ++i)
58 for(i = 0; i < bLen; ++i)
59 shift[ (
unsigned char) pWord[i] ] = bLen -i - 1;
61 for(i = t = bLen-1; t >= 0; --i, --t)
66 while((c = *(bit + i)) != pWord[t])
68 i += std::max(bLen-t, shift[c]);
69 if((bit + i) >= eit)
return eit;
84 template<
typename Iterator>
85 Iterator find_bm(Iterator bit, Iterator eit,
const std::string& word)
87 return find_bm(bit, eit, word,
88 typename std::iterator_traits<Iterator>::iterator_category());