diff --git a/src/file_io.cpp b/src/file_io.cpp index a5be9c3..374d90c 100644 --- a/src/file_io.cpp +++ b/src/file_io.cpp @@ -38,7 +38,7 @@ namespace gz { getline(file, line); // ignore commented lines - if (line.find("#") != std::string::npos) { continue; } + if (line.starts_with('#')) { continue; } // if "=" in line: split into key - value pair and store in map if (line.find("=") != std::string::npos) { diff --git a/src/file_io.hpp b/src/file_io.hpp index b43ce67..a05c521 100644 --- a/src/file_io.hpp +++ b/src/file_io.hpp @@ -11,6 +11,7 @@ namespace gz { * @details * This template function is instantiated for the default unordered_map and the util::string_map from util/string.hpp * @throws FileIOError + * @see @ref fio_t_key_value "Key-Value filetype" */ template bool writeKeyValueFile(const std::string& filepath, const std::unordered_map& content); @@ -18,7 +19,27 @@ namespace gz { /** * @brief Read a file that contains key = value pairs * @throws FileIOError + * @see @ref fio_t_key_value "Key-Value filetype" */ std::unordered_map readKeyValueFile(const std::string& filepath, bool removeSpaces=false); - } + +/** + * @file + * @brief Contains file reading/writing utility + */ +/** + * @page FileIO + * @section fio_filetypes Filetypes + * @subsection fio_t_key_value Simple Key-Value file + * A file that contains key - value pairs in each line, separated with "=". + * Any number of whitespaces around the separator is allowed. + * If the first character of a line is "#", the whole line is a comment. + * Example: + * @code + * key1 = value1 + * # this is a comment + * key2= #this_is_value_not_a_comment + * arr = val1, val2, val3 + * @endcode + */