From 1ded19c5b2c00490c0f4f16c872e5a926d4f5b9f Mon Sep 17 00:00:00 2001 From: SASANO Takayoshi Date: Sat, 4 Jul 2020 17:58:00 +0900 Subject: [PATCH] permit inline comment (2) To implement this feature, using strtok() is not enough. This cannot handle this case: Key=#value#comment it will be #value is the contents of Key. And, Key=value #comment (there is a space and a tab between value and #comment) this will be value. Sometimes these trailing spaces and tabs makes thing wrong. Whether in-line comment is used or not, delete trailing space/tab after value. --- Conf.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Conf.cpp b/Conf.cpp index 6602b3c..d2ee258 100644 --- a/Conf.cpp +++ b/Conf.cpp @@ -391,8 +391,16 @@ bool CConf::read() value[len - 1U] = '\0'; value++; } else { + char *p; + // if value is not quoted, remove after # (to make comment) - strtok(value, "#"); + 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) {