43 lines
775 B
C++
43 lines
775 B
C++
// TJP COPYRIGHT HEADER
|
|
|
|
#ifdef TJP_CORE_HEADER_ONLY
|
|
#pragma once
|
|
#endif
|
|
#include <tjp/core/header_only/compile.h>
|
|
|
|
#include "Args.h"
|
|
#include <tjp/core/string/starts_with.hpp>
|
|
|
|
namespace tjp::core {
|
|
|
|
TJP_CORE_HEADER_ONLY_INLINE
|
|
std::map<std::string, std::string> mapArgs(int argc, const char *argv[])
|
|
{
|
|
std::map<std::string, std::string> mapped;
|
|
static const std::string prefix = "--";
|
|
for (int i=1; i<argc; ++i)
|
|
{
|
|
std::string s = argv[i];
|
|
if (starts_with(s, prefix))
|
|
{
|
|
bool hasValue = (i+1)<argc && !starts_with(std::string(argv[i+1]), prefix);
|
|
std::string key = s.substr(2);
|
|
if (hasValue)
|
|
{
|
|
std::string value = argv[i+1];
|
|
mapped[key] = value;
|
|
i++;
|
|
}
|
|
else
|
|
{
|
|
mapped[key] = "";
|
|
}
|
|
}
|
|
}
|
|
|
|
return mapped;
|
|
}
|
|
|
|
|
|
} // namespace
|