<commit_before>/*
 * ArgumentList.cpp
 * 
 * This file is part of the XShaderCompiler project (Copyright (c) 2014-2017 by <NAME>)
 * See "LICENSE.txt" for license information.
 */

#include "CommandLine.h"
#include <stdexcept>
#include <algorithm>
#include <cctype>


namespace Xsc
{

namespace Util
{


CommandLine::CommandLine(int argc, char** argv)
{
    for (int i = 0; i < argc; ++i)
        args_.push_back(std::string(argv[i]));
}

CommandLine::CommandLine(const std::vector<std::string>& args)
{
    args_.insert(args_.end(), args.begin(), args.end());
}

CommandLine::CommandLine(const std::string& line)
{
    /* Parse command line arguments */
    std::size_t start = 0, end = 0;
    while (start < line.size())
    {
        start = line.find_first_not_of(' ', end);
        if (start >= line.size())
            break;

        if (line[start] == '\"')
        {
            end = line.find('\"', start + 1);
            if (end != std::string::npos)
            {
                args_.push_back(line.substr(start + 1, end - start - 1));
                ++end;
            }
        }
        else
        {
            end = line.find(' ', start + 1);
            if (end != std::string::npos)
                args_.push_back(line.substr(start, end - start));
            else
                args_.push_back(line.substr(start));
        }
    }
}

std::string CommandLine::Get() const
{
    return (args_.empty() ? "" : args_.front());
}

std::string CommandLine::Accept()
{
    if (args_.empty())
        throw std::invalid_argument("unexpected end of command line arguments");
    auto arg = Get();
    args_.pop_front();
    return arg;
}

bool CommandLine::AcceptBoolean()
{
    auto arg = Accept();
    if (arg == CommandLine::GetBooleanTrue())
        return true;
    if (arg == CommandLine::GetBooleanFalse())
        return false;
    throw std::invalid_argument(
        "expected '" + CommandLine::GetBooleanTrue() + "' or '" +
        CommandLine::GetBooleanFalse() + "', but got '" + arg + "'"
    );
}

bool CommandLine::AcceptBoolean(bool defaultValue)
{
    auto arg = Get();
    std::transform(arg.begin(), arg.end(), arg.begin(), std::toupper);

    if (arg == CommandLine::GetBooleanTrue())
    {
        Accept();
        return true;
    }
    if (arg == CommandLine::GetBooleanFalse())
    {
        Accept();
        return false;
    }<commit_msg>Fixed upper case transform on Linux port.<commit_after>/*
 * ArgumentList.cpp
 * 
 * This file is part of the XShaderCompiler project (Copyright (c) 2014-2017 by <NAME>)
 * See "LICENSE.txt" for license information.
 */

#include "CommandLine.h"
#include <stdexcept>
#include <algorithm>
#include <cctype>


namespace Xsc
{

namespace Util
{


CommandLine::CommandLine(int argc, char** argv)
{
    for (int i = 0; i < argc; ++i)
        args_.push_back(std::string(argv[i]));
}

CommandLine::CommandLine(const std::vector<std::string>& args)
{
    args_.insert(args_.end(), args.begin(), args.end());
}

CommandLine::CommandLine(const std::string& line)
{
    /* Parse command line arguments */
    std::size_t start = 0, end = 0;
    while (start < line.size())
    {
        start = line.find_first_not_of(' ', end);
        if (start >= line.size())
            break;

        if (line[start] == '\"')
        {
            end = line.find('\"', start + 1);
            if (end != std::string::npos)
            {
                args_.push_back(line.substr(start + 1, end - start - 1));
                ++end;
            }
        }
        else
        {
            end = line.find(' ', start + 1);
            if (end != std::string::npos)
                args_.push_back(line.substr(start, end - start));
            else
                args_.push_back(line.substr(start));
        }
    }
}

std::string CommandLine::Get() const
{
    return (args_.empty() ? "" : args_.front());
}

std::string CommandLine::Accept()
{
    if (args_.empty())
        throw std::invalid_argument("unexpected end of command line arguments");
    auto arg = Get();
    args_.pop_front();
    return arg;
}

bool CommandLine::AcceptBoolean()
{
    auto arg = Accept();
    if (arg == CommandLine::GetBooleanTrue())
        return true;
    if (arg == CommandLine::GetBooleanFalse())
        return false;
    throw std::invalid_argument(
        "expected '" + CommandLine::GetBooleanTrue() + "' or '" +
        CommandLine::GetBooleanFalse() + "', but got '" + arg + "'"
    );
}

bool CommandLine::AcceptBoolean(bool defaultValue)
{
    auto arg = Get();
    std::transform(arg.begin(), arg.end(), arg.begin(), ::toupper);

    if (arg == CommandLine::GetBooleanTrue())
    {
        Accept();
        return true;
    }
    if (arg == CommandLine::GetBooleanFalse())
    {
        Accept();
        return false;
    }
{'fraction_non_alphanumeric': 0.16107522400500104, 'fraction_numerical': 0.0062513023546572205, 'mean_word_length': 2.3755274261603376, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6115766', 'n_tokens_mistral': 1504, 'n_tokens_neox': 1454, 'n_words': 344}