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 bool string_is_blank(const std::string&);
00048
00049
00050 int str2int(const std::string& s);
00051
00052
00053 std::string int2hex(unsigned int n);
00054
00055
00056 template<typename Iterator>
00057 Iterator find_bm(Iterator bit, Iterator eit, const std::string& word, const std::random_access_iterator_tag&)
00058 {
00059 int bLen = word.length();
00060 const char* pWord = word.c_str();
00061 int i, t, shift[256];
00062 unsigned char c;
00063
00064 for(i = 0; i < 256; ++i)
00065 shift[i] = bLen;
00066
00067 for(i = 0; i < bLen; ++i)
00068 shift[ (int) pWord[i] ] = bLen -i - 1;
00069
00070 for(i = t = bLen-1; t >= 0; --i, --t)
00071 {
00072 if((bit + i) >= eit)
00073 return eit;
00074
00075 while((c = *(bit + i)) != pWord[t])
00076 {
00077 i += std::max(bLen-t, shift[c]);
00078 if((bit + i) >= eit) return eit;
00079 t = bLen-1;
00080 }
00081 }
00082
00083 return bit + i + 1;
00084 }
00085
00086
00087
00088
00089
00090
00091
00092
00093 template<typename Iterator>
00094 Iterator find_bm(Iterator bit, Iterator eit, const std::string& word)
00095 {
00096 return find_bm(bit, eit, word,
00097 typename std::iterator_traits<Iterator>::iterator_category());
00098 }
00099
00100
00101
00102 }
00103
00104 }
00105
00106 #endif