00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef _MIMETIC_UTILS_H_
00017 #define _MIMETIC_UTILS_H_
00018 #include <iostream>
00019 #include <string>
00020 #include <ctype.h>
00021 #include <mimetic/libconfig.h>
00022 #include <mimetic/strutils.h>
00023
00024 namespace mimetic
00025 {
00026
00027 std::ostream& crlf(std::ostream&);
00028 std::ostream& nl(std::ostream&);
00029
00030 #ifndef isblank
00031 inline int isblank(char c)
00032 {
00033 return c == ' ' || c == '\t';
00034 }
00035 #endif
00036
00037 namespace utils
00038 {
00039
00040
00041 std::string extractFilename(const std::string&);
00042
00043
00044 std::string int2str(int n);
00045
00046
00047 int str2int(const std::string& s);
00048
00049
00050 std::string int2hex(unsigned int n);
00051
00052
00053 template<typename Iterator>
00054 Iterator find_bm(Iterator bit, Iterator eit, const std::string& word, const std::random_access_iterator_tag&)
00055 {
00056 int bLen = word.length();
00057 const char* pWord = word.c_str();
00058 int i, t, shift[256];
00059 unsigned char c;
00060
00061 for(i = 0; i < 256; ++i)
00062 shift[i] = bLen;
00063
00064 for(i = 0; i < bLen; ++i)
00065 shift[ (int) pWord[i] ] = bLen -i - 1;
00066
00067 for(i = t = bLen-1; t >= 0; --i, --t)
00068 {
00069 if((bit + i) >= eit)
00070 return eit;
00071
00072 while((c = *(bit + i)) != pWord[t])
00073 {
00074 i += std::max(bLen-t, shift[c]);
00075 if((bit + i) >= eit) return eit;
00076 t = bLen-1;
00077 }
00078 }
00079
00080 return bit + i + 1;
00081 }
00082
00083
00084
00085
00086
00087
00088
00089
00090 template<typename Iterator>
00091 Iterator find_bm(Iterator bit, Iterator eit, const std::string& word)
00092 {
00093 return find_bm(bit, eit, word,
00094 typename std::iterator_traits<Iterator>::iterator_category());
00095 }
00096
00097
00098
00099 }
00100
00101 }
00102
00103 #endif