From d2f71c5ed69ff43090e81631a66bcee3023f8a45 Mon Sep 17 00:00:00 2001 From: SASANO Takayoshi Date: Wed, 9 Sep 2020 19:02:24 +0900 Subject: [PATCH] permit inline comment in-line comment enabled example: # conventional comment, the line starts with # [Section] Key=value # this is new style comment Key="quoted value # this is not comment" Key="quoted value" # this is prohibited (not comment) Whether in-line comment is used or not, delete trailing space/tab after value. --- Conf.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Conf.cpp b/Conf.cpp index 13d9a62..99f4009 100644 --- a/Conf.cpp +++ b/Conf.cpp @@ -240,6 +240,17 @@ bool CConf::read() if (len > 1U && *value == '"' && value[len - 1U] == '"') { value[len - 1U] = '\0'; value++; + } else { + char *p; + + // if value is not quoted, remove after # (to make comment) + if ((p = strchr(value, '#')) != NULL) + *p = '\0'; + + // remove trailing tab/space + for (p = value + strlen(value) - 1; + p >= value && (*p == '\t' || *p == ' '); p--) + *p = '\0'; } if (section == SECTION_GENERAL) {