/* Test une facon de simnplier, uniformer l'inspection d'une chaine */ #include #include #include #include #include "getnow.h" using namespace std; struct copybuf{ const char *pt; string buf; bool end = false; bool skipped = false; copybuf(PARAM_STRING p){ pt = p.ptr; } void stop(){ end = true; } void insert (const char car){ buf += car; } void insert (const char *str){ buf += str; } void replace(unsigned nbskip, const char car){ buf += car; skip(nbskip); } void replace(unsigned nbskip, const char *str){ buf += str; skip(nbskip); } void replace(unsigned nbskip, const std::string str){ buf += str; skip(nbskip); } void skip (unsigned n){ skipped=true; while (*pt != '\0' && n > 0){ pt++; n--; } } void clear(){ buf.clear(); } }; string copystring(PARAM_STRING p,std::function func) { copybuf buf(p); while (!buf.end && *buf.pt != '\0'){ buf.skipped = false; func(buf,buf.pt); if (!buf.skipped){ buf.buf += *buf.pt; buf.pt++; } } return buf.buf; }; int main () { const char *test = "allo comment ca va"; bool debug = false; int nb = debug ? 1 : 1000000; { long long start = getnow(); size_t size = 0; for (int i=0; i