Example #1
0
const Option& OptionSet::getOption(const std::string& name, bool matchShort) const
{
	const Option* pOption = 0;
	for (Iterator it = _options.begin(); it != _options.end(); ++it)
	{
		if ((matchShort && it->matchesShort(name)) || (!matchShort && it->matchesPartial(name)))
		{
			if (!pOption)
			{
				pOption = &*it;
				if (!matchShort && it->matchesFull(name))
					break;
			}
			else if (!matchShort && it->matchesFull(name))
			{
				pOption = &*it;
				break;
			}
			else throw AmbiguousOptionException(name);
		}
	}
	if (pOption)
		return *pOption;
	else
		throw UnknownOptionException(name);
}
Example #2
0
void HTTPBasicAuth::setOption(const std::string& name, const std::string& value) 
{
	if (name=="realm")
		m_realm = value;
	else
		throw UnknownOptionException(name);
}
Example #3
0
void HTTPCookieAuth::setOption(const std::string& name, const std::string& value) 
{
	if (name=="login")
		m_login = value;
	else if (name=="logout")
		m_logout = value;
	else if (name=="redirect")
		m_redirect = value;
	else
		throw UnknownOptionException(name);
}
Example #4
0
void Option::process(const std::string& option, std::string& arg) const
{
	std::string::size_type pos = option.find_first_of(":=");
	std::string::size_type len = pos == std::string::npos ? option.length() : pos;
	if (icompare(option, 0, len, _fullName, 0, len) == 0)
	{
		if (takesArgument())
		{
			if (argumentRequired() && pos == std::string::npos)
				throw MissingArgumentException(_fullName + " requires " + argumentName());
			if (pos != std::string::npos)
				arg.assign(option, pos + 1, option.length() - pos - 1);
			else
				arg.clear();
		}
		else if (pos != std::string::npos)
		{
			throw UnexpectedArgumentException(option);
		}
		else arg.clear();
	}
	else if (!_shortName.empty() && option.compare(0, _shortName.length(), _shortName) == 0)
	{
		if (takesArgument())
		{
			if (argumentRequired() && option.length() == _shortName.length())
				throw MissingArgumentException(_shortName + " requires " + argumentName());
			arg.assign(option, _shortName.length(), option.length() - _shortName.length());
		}
		else if (option.length() != _shortName.length())
		{
			throw UnexpectedArgumentException(option);
		}
		else arg.clear();
	}
	else throw UnknownOptionException(option);
}