From c6dbf0450566c40efc4a26f4f0717452b6ef95cd Mon Sep 17 00:00:00 2001 From: Minteck Date: Wed, 10 Aug 2022 10:38:44 +0200 Subject: Initial commit --- node_modules/ua-parser/cpp/UaParser.h | 54 +++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 node_modules/ua-parser/cpp/UaParser.h (limited to 'node_modules/ua-parser/cpp/UaParser.h') diff --git a/node_modules/ua-parser/cpp/UaParser.h b/node_modules/ua-parser/cpp/UaParser.h new file mode 100644 index 0000000..ea34a8c --- /dev/null +++ b/node_modules/ua-parser/cpp/UaParser.h @@ -0,0 +1,54 @@ +#pragma once + +#include + +struct Device { + std::string family; +}; + +struct Agent : Device { + std::string major; + std::string minor; + std::string patch; + + std::string toString() const { + return family + " " + toVersionString(); + } + + std::string toVersionString() const { + return (major.empty() ? "0" : major) + "." + + (minor.empty() ? "0" : minor) + "." + + (patch.empty() ? "0" : patch); + } +}; + +typedef Agent Os; +typedef Agent Browser; + +struct UserAgent { + Device device; + + Os os; + Browser browser; + + std::string toFullString() const { + return browser.toString() + "/" + os.toString(); + } + + bool isSpider() const { + return device.family == "Spider"; + } +}; + +class UserAgentParser { + public: + explicit UserAgentParser(const std::string& regexes_file_path); + + UserAgent parse(const std::string&) const; + + ~UserAgentParser(); + + private: + const std::string regexes_file_path_; + const void* ua_store_; +}; -- cgit