/* * This file is copyright by Rebirth contributors and licensed as * described in COPYING.txt. * See COPYING.txt for license details. */ #pragma once #include #include #include #include #include #include #include #include "dxxsconf.h" #include "ntstring.h" template static inline bool cmp(const char *token, const char *equal, const char (&name)[N]) { return &token[N - 1] == equal && !strncmp(token, name, N - 1); } template static inline bool convert_integer(F *f, T &t, const char *value, int base) { char *e; auto r = (*f)(value, &e, base); if (*e) /* Trailing garbage found */ return false; T tr = static_cast(r); if (r != tr) /* Result truncated */ return false; t = tr; return true; } template static inline typename std::enable_if::value, bool>::type convert_integer(T &t, const char *value, int base = 10) { return convert_integer(strtol, t, value, base); } template static inline typename std::enable_if::value, bool>::type convert_integer(T &t, const char *value, int base = 10) { return convert_integer(strtoul, t, value, base); } template static inline void convert_string(ntstring &out, const char *const value, const char *eol) { assert(*eol == 0); const std::size_t i = std::distance(value, ++ eol); if (i > out.size()) /* Only if not truncated */ return; std::copy(value, eol, out.begin()); }