#include // TODO // 1. Consider removing the utf-8 bom (https://github.com/zer4tul/utf8-bom-strip) namespace ot { // Function: to_lower std::string to_lower(std::string s) { std::transform(s.begin(), s.end(), s.begin(), [] (auto c) { return std::tolower(c); }); return s; } // Function: to_upper std::string to_upper(std::string s) { std::transform(s.begin(), s.end(), s.begin(), [] (auto c) { return std::toupper(c); }); return s; } // Functon : remove_quote std::string remove_quote(std::string s) { s.erase(std::remove( s.begin(), s.end(), '\"'), s.end()); return s; } // Function: unquoted std::string unquoted(std::string s) { if(s.size() >= 2 && s.front() == '\"' && s.back() == '\"') { return s.substr(1, s.size() - 2); } else return s; } // Function: is_numeric bool is_numeric(const std::string& token) { return std::regex_match(token, std::regex("(\\+|-)?[0-9]*(\\.?([0-9]+))$")); } // Function: is_array bool is_array(const std::string& token) { return std::regex_match(token, std::regex("[a-zA-Z_][a-zA-Z_0-9]*(\\[[0-9]+\\])+")); } // Function: is_word bool is_word(const std::string& token) { return std::regex_match(token, std::regex("[a-zA-Z_][a-zA-Z_0-9]*")); } // ------------------------------------------------------------------------------------------------ // Function: tokenize std::vector split(const std::string& str, std::string_view dels) { // Parse the token. std::string token; std::vector tokens; for(size_t i=0; i tokenize( const std::filesystem::path& path, std::string_view dels, std::string_view exps ) { using namespace std::literals::string_literals; std::ifstream ifs(path, std::ios::ate); if(!ifs.good()) { //throw std::invalid_argument("failed to open the file '"s + path.c_str() + '\''); return {}; } // Read the file to a local buffer. size_t fsize = ifs.tellg(); ifs.seekg(0, std::ios::beg); std::vector buffer(fsize + 1); ifs.read(buffer.data(), fsize); buffer[fsize] = 0; // Mart out the comment for(size_t i=0; i tokens; for(size_t i=0; i