aboutsummaryrefslogtreecommitdiff
path: root/any_ini.h
diff options
context:
space:
mode:
authorFederico Angelilli <code@fedang.net>2024-05-22 00:37:58 +0200
committerFederico Angelilli <code@fedang.net>2024-05-22 00:37:58 +0200
commitf83f21f98069c3267725c640f090feb6a2628894 (patch)
tree6a7a8cc6d8e67f1fcbf677de764c80de9c0d2180 /any_ini.h
parent2881783a6d7bc37e03c8639caf8ac0b0876a01c6 (diff)
Add multiline ini parsing
Diffstat (limited to 'any_ini.h')
-rw-r--r--any_ini.h21
1 files changed, 20 insertions, 1 deletions
diff --git a/any_ini.h b/any_ini.h
index 8efce03..dff8a7c 100644
--- a/any_ini.h
+++ b/any_ini.h
@@ -113,7 +113,21 @@ static char *any_ini_copy(const char *start, size_t length)
{
char *string = ANY_INI_MALLOC(length + 1);
if (string) {
+#ifdef ANY_INI_NO_MULTILINE
memcpy(string, start, length);
+#else
+ size_t i, size = length;
+ for (i = 0, length = 0; i < size; i++) {
+ if (start[i] == '\\') {
+ if (i + 1 < size && start[i + 1] == '\n')
+ i++;
+ else if (i + 2 < size && start[i + 1] == '\r' && start[i + 2] == '\\')
+ i += 2;
+ continue;
+ }
+ string[length++] = start[i];
+ }
+#endif
string[length] = '\0';
}
return string;
@@ -152,6 +166,11 @@ static bool any_ini_skip_pair(const char *source, size_t cursor, bool key)
{
switch (source[cursor]) {
case '\n':
+#ifndef ANY_INI_NO_MULTILINE
+ if ((cursor > 2 && source[cursor - 1] == '\r' && source[cursor - 2] == '\\') ||
+ (cursor > 1 && source[cursor - 1] == '\\'))
+ return true;
+#endif
return false;
#ifndef ANY_INI_NO_INLINE_COMMENT
@@ -159,7 +178,7 @@ static bool any_ini_skip_pair(const char *source, size_t cursor, bool key)
#ifdef ANY_INI_DELIM_COMMENT2
case ANY_INI_DELIM_COMMENT2:
#endif
- if (isspace(source[cursor - 1]))
+ if (cursor != 0 && isspace(source[cursor - 1]))
return false;
// fallthrough
#endif