/* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "toml_internal.h" static bool is_value_end(cstr expected_value_end, cstr input_end){ if(expected_value_end == input_end) return true; char next_ch = *expected_value_end; return isspace(next_ch) || next_ch == ',' || next_ch == ']' || next_ch == '}'; } Result(void) toml_parse_bool(TomlParser* self, TomlValue* out_value) { Deferral(1); cstr val_end = self->ptr + 4; if(val_end <= self->end && strncmp(self->ptr, "true", 4) == 0) { if(is_value_end(val_end, self->end)) { toml_next_n(self, 4); *out_value = TomlValue_new_bool(true); Return RESULT_VOID; } } val_end = self->ptr + 5; if(val_end <= self->end && strncmp(self->ptr, "false", 5) == 0) { if(is_value_end(val_end, self->end)) { toml_next_n(self, 5); *out_value = TomlValue_new_bool(false); Return RESULT_VOID; } } Return RESULT_ERROR_CODE_FMT(TLIBTOML, TLIBTOML_ERR_SYNTAX, "%s:%d:%d: value of unknown type", self->filename, self->lineno, self->colno); }