diff options
author | A. Wilcox <AWilcox@Wilcox-Tech.com> | 2019-10-07 19:07:27 -0500 |
---|---|---|
committer | A. Wilcox <AWilcox@Wilcox-Tech.com> | 2019-10-07 19:07:27 -0500 |
commit | 39c57ed759c3b3bb008b0d1b3661bd364712807d (patch) | |
tree | b5a2403bd5157e0d615fbe51cb2f03aff3b289c3 /hscript/key.cc | |
parent | f6b34aac6e19d8f58131f2171c1ad5a7e966dbc4 (diff) | |
download | horizon-39c57ed759c3b3bb008b0d1b3661bd364712807d.tar.gz horizon-39c57ed759c3b3bb008b0d1b3661bd364712807d.tar.bz2 horizon-39c57ed759c3b3bb008b0d1b3661bd364712807d.tar.xz horizon-39c57ed759c3b3bb008b0d1b3661bd364712807d.zip |
hscript: Fix up Key class, add BooleanKey class
Diffstat (limited to 'hscript/key.cc')
-rw-r--r-- | hscript/key.cc | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/hscript/key.cc b/hscript/key.cc new file mode 100644 index 0000000..74406f6 --- /dev/null +++ b/hscript/key.cc @@ -0,0 +1,33 @@ +/* + * key.cc - Implementation of common routines for the base Key classes + * libhscript, the HorizonScript library for + * Project Horizon + * + * Copyright (c) 2019 Adélie Linux and contributors. All rights reserved. + * This code is licensed under the AGPL 3.0 license, as noted in the + * LICENSE-code file in the root directory of this repository. + * + * SPDX-License-Identifier: AGPL-3.0-only + */ + +#include <algorithm> +#include "key.hh" + +bool Horizon::Keys::BooleanKey::parse(const std::string what, bool *out) { + std::string lower; + std::transform(what.begin(), what.end(), lower.begin(), ::tolower); + + if(lower == "true" || lower == "yes" || lower == "1") { + *out = true; + } else if(lower == "false" || lower == "no" || lower == "0") { + *out = false; + } else { + return false; + } + return true; +} + +bool Horizon::Keys::BooleanKey::validate() { + /* Key will fail init if it is not valid, so this is always a no-op. */ + return true; +} |