Browse Source

use case-insensitive containers for app_parameters

master
Jessica James 3 years ago
parent
commit
bf2bcd55e2
  1. 9
      src/common/app_parameters.cpp
  2. 14
      src/include/jessilib/app_parameters.hpp

9
src/common/app_parameters.cpp

@ -159,7 +159,7 @@ app_parameters::app_parameters(std::vector<std::u8string> in_args, std::vector<s
flush_value(); flush_value();
// Populate m_switches_set from m_switches // Populate m_switches_set from m_switches
m_switches_set = std::unordered_set<std::u8string>{ m_switches.begin(), m_switches.end() }; m_switches_set = { m_switches.begin(), m_switches.end() };
} }
std::u8string_view app_parameters::path() const { std::u8string_view app_parameters::path() const {
@ -174,11 +174,11 @@ const std::vector<std::u8string>& app_parameters::switches() const {
return m_switches; return m_switches;
} }
const std::unordered_set<std::u8string>& app_parameters::switches_set() const { const app_parameters::set_type& app_parameters::switches_set() const {
return m_switches_set; return m_switches_set;
} }
const std::unordered_map<std::u8string, std::u8string>& app_parameters::values() const { const app_parameters::map_type& app_parameters::values() const {
return m_arg_values; return m_arg_values;
} }
@ -196,7 +196,8 @@ object app_parameters::as_object() const {
{ u8"Path"s, m_path }, { u8"Path"s, m_path },
{ u8"Args"s, m_args }, { u8"Args"s, m_args },
{ u8"Switches"s, m_switches }, { u8"Switches"s, m_switches },
{ u8"Values"s, m_arg_values } { u8"Values"s, m_arg_values },
{ u8"Env"s, m_env_values }
}; };
} }

14
src/include/jessilib/app_parameters.hpp

@ -17,11 +17,15 @@
*/ */
#include "object.hpp" #include "object.hpp"
#include "unicode_compare.hpp"
namespace jessilib { namespace jessilib {
class app_parameters { class app_parameters {
public: public:
using set_type = std::unordered_set<std::u8string, jessilib::text_hashi, jessilib::text_equali>;
using map_type = std::unordered_map<std::u8string, std::u8string, jessilib::text_hashi, jessilib::text_equali>;
app_parameters(int in_argc, char** in_argv, char** in_envp = nullptr); app_parameters(int in_argc, char** in_argv, char** in_envp = nullptr);
app_parameters(int in_argc, const char** in_argv, const char** in_envp = nullptr); app_parameters(int in_argc, const char** in_argv, const char** in_envp = nullptr);
app_parameters(int in_argc, wchar_t** in_argv, wchar_t** in_envp = nullptr); app_parameters(int in_argc, wchar_t** in_argv, wchar_t** in_envp = nullptr);
@ -32,8 +36,8 @@ public:
const std::vector<std::u8string>& arguments() const; const std::vector<std::u8string>& arguments() const;
const std::vector<std::u8string>& switches() const; const std::vector<std::u8string>& switches() const;
const std::unordered_set<std::u8string>& switches_set() const; const set_type& switches_set() const;
const std::unordered_map<std::u8string, std::u8string>& values() const; const map_type& values() const;
jessilib::object as_object() const; jessilib::object as_object() const;
bool has_switch(std::u8string_view in_switch) const; bool has_switch(std::u8string_view in_switch) const;
@ -47,9 +51,9 @@ private:
std::u8string m_path; std::u8string m_path;
std::vector<std::u8string> m_args; std::vector<std::u8string> m_args;
std::vector<std::u8string> m_switches; std::vector<std::u8string> m_switches;
std::unordered_set<std::u8string> m_switches_set; set_type m_switches_set;
std::unordered_map<std::u8string, std::u8string> m_arg_values; map_type m_arg_values;
std::unordered_map<std::u8string, std::u8string> m_env_values; map_type m_env_values;
}; };
} // namespace jessilib } // namespace jessilib

Loading…
Cancel
Save