mirror of
https://gitea.sffempire.ru/Kolyah35/minecraft-pe-0.6.1.git
synced 2026-03-19 22:43:32 +00:00
52 lines
1.0 KiB
C++
52 lines
1.0 KiB
C++
#include "Option.h"
|
|
#include <sstream>
|
|
#include <cstdio>
|
|
|
|
Option::~Option() {}
|
|
|
|
bool Option::parse_bool_like(const std::string& value, bool& out) {
|
|
if (value == "true" || value == "YES") {
|
|
out = true;
|
|
return true;
|
|
}
|
|
|
|
if (value == "false" || value == "NO") {
|
|
out = false;
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
bool OptionFloat::parse(const std::string& value) {
|
|
bool b;
|
|
|
|
if (parse_bool_like(value, b)) {
|
|
m_value = b ? 1.f : 0.f;
|
|
return true;
|
|
}
|
|
|
|
return sscanf(value.c_str(), "%f", &m_value) == 1;
|
|
}
|
|
bool OptionInt::parse(const std::string& value) {
|
|
bool b;
|
|
if (parse_bool_like(value, b)) {
|
|
m_value = b ? 1 : 0;
|
|
return true;
|
|
}
|
|
|
|
return sscanf(value.c_str(), "%d", &m_value) == 1;
|
|
}
|
|
bool OptionBool::parse(const std::string& value) {
|
|
if (value == "0") {
|
|
m_value = false;
|
|
return true;
|
|
}
|
|
|
|
if (value == "1") {
|
|
m_value = true;
|
|
return true;
|
|
}
|
|
|
|
return parse_bool_like(value, m_value);
|
|
} |