#ifndef HELPER_H #define HELPER_H // is_any_of(var,value1,value2,...); // For strings // is_any_ofnc(var,value1,value2,...); // is_not_in (var,value1,value2,...); // is_eq(value1,value2); // is_start_any_of(var,pointer,value1,value2,...); // is_start_any_of(var,NONEED,value1,value2,...); // is_start_any_ofnc(var,pointer,value1,value2,...); // is_start_any_ofnc(var,NONEED,value1,value2,...); // Replace a sequence of if (a==b || a==c || a==d ... // with is_any_of (a,b,c,d,...) inline bool is_any_of (const char *t, const char *t1){ return strcmp(t,t1)==0;} inline bool is_any_of (const char *t, char *t1){ return strcmp(t,t1)==0;} inline bool is_any_of (char *t, const char *t1){ return strcmp(t,t1)==0;} inline bool is_any_of (char *t, char *t1){ return strcmp(t,t1)==0;} template bool is_any_of(T &&t, T1 &&t1){ return t == t1; } template bool is_any_of(T &&t, T1 &&t1, Ts &&... ts){ return is_any_of(t,t1) || is_any_of(t,ts...); } inline bool is_any_ofnc (const char *t, const char *t1) { return strcasecmp(t,t1)==0; } inline bool is_any_ofnc (const std::string &t, const char *t1) { return strcasecmp(t.c_str(),t1)==0; } inline bool is_any_ofnc (const std::string &t, const std::string &t1) { return strcasecmp(t.c_str(),t1.c_str())==0; } inline bool is_any_ofnc (const char *t, const std::string &t1) { return strcasecmp(t,t1.c_str())==0; } template bool is_any_ofnc(T &&t, T1 &&t1, Ts &&... ts){ return is_any_ofnc(t,t1) || is_any_ofnc(t,ts...); } template bool is_eq(T &&t, T1 &&t1){ return is_any_of(t,t1); } // Replace a sequence of if (a!=b && a!=c && a==d ... // with is_not_in (a,b,c,d,...) inline bool is_not_in (const char *t, const char *t1){ return strcmp(t,t1)!=0;} inline bool is_not_in (const char *t, char *t1){ return strcmp(t,t1)!=0;} inline bool is_not_in (char *t, const char *t1){ return strcmp(t,t1)!=0;} inline bool is_not_in (char *t, char *t1){ return strcmp(t,t1)!=0;} template bool is_not_in(T &&t, T1 &&t1){ return t != t1; } template bool is_not_in(T &&t, T1 &&t1, Ts &&... ts){ return is_not_in(t,t1) && is_not_in(t,ts...); } enum class NONEED_T{noneed}; #define NONEED NONEED_T::noneed inline bool is_start_any_of (PARAM_STRING a, const char *&pt, const char *b) { bool ret = false; auto len = strlen(b); pt=nullptr; if (strncmp(a.ptr,b,len)==0){ ret = true; pt = a.ptr+len; } return ret; } inline bool is_start_any_of (PARAM_STRING a, NONEED_T, const char *b) { bool ret = false; auto len = strlen(b); if (strncmp(a.ptr,b,len)==0){ ret = true; } return ret; } template bool is_start_any_of(PARAM_STRING t, const char *&pt, T1 &&t1, Ts &&... ts){ return is_start_any_of(t,pt,t1) || is_start_any_of(t,pt,ts...); } template bool is_start_any_of(PARAM_STRING t, NONEED_T no, T1 &&t1, Ts &&... ts){ return is_start_any_of(t,no,t1) || is_start_any_of(t,no,ts...); } // Case insensitive inline bool is_start_any_ofnc (PARAM_STRING a, const char *&pt, const char *b) { bool ret = false; auto len = strlen(b); pt=nullptr; if (strncasecmp(a.ptr,b,len)==0){ ret = true; pt = a.ptr+len; } return ret; } inline bool is_start_any_ofnc (PARAM_STRING a, NONEED_T, const char *b) { bool ret = false; auto len = strlen(b); if (strncasecmp(a.ptr,b,len)==0){ ret = true; } return ret; } template bool is_start_any_ofnc(PARAM_STRING t, const char *&pt, T1 &&t1, Ts &&... ts){ return is_start_any_ofnc(t,pt,t1) || is_start_any_ofnc(t,pt,ts...); } template bool is_start_any_ofnc(PARAM_STRING t, NONEED_T no, T1 &&t1, Ts &&... ts){ return is_start_any_ofnc(t,no,t1) || is_start_any_ofnc(t,no,ts...); } #endif