#ifndef NALL_STRING_STRPOS_HPP #define NALL_STRING_STRPOS_HPP //usage example: //if(auto pos = strpos(str, key)) print(pos(), "\n"); //prints position of key within str, only if it is found namespace nall { template optional ustrpos(const char *str, const char *key) { const char *base = str; while(*str) { if(quoteskip(str)) continue; for(unsigned n = 0;; n++) { if(key[n] == 0) return optional(true, (unsigned)(str - base)); if(str[n] == 0) return optional(false, 0); if(!chrequal(str[n], key[n])) break; } str++; } return optional(false, 0); } optional strpos(const char *str, const char *key) { return ustrpos(str, key); } optional istrpos(const char *str, const char *key) { return ustrpos(str, key); } optional qstrpos(const char *str, const char *key) { return ustrpos(str, key); } optional iqstrpos(const char *str, const char *key) { return ustrpos(str, key); } } #endif