libsheepy

C lib for handling text files, strings and json like data structure with an object oriented system
git clone https://spartatek.se/git/libsheepy.git
Log | Files | Refs | README | LICENSE

commit 571d2960641e347e06b6950f1779d5c5bf01cdc1
parent b52a84631c9f551bf940f0318304a946ece0b33d
Author: Remy Noulin <loader2x@gmail.com>
Date:   Thu,  9 Sep 2021 21:29:29 +0200

stop printing error when a dict with an empty string is converted to json or yml string

release/libsheepy.h            |  2 +-
src/json/libsheepyCSmallJson.c | 17 +++++++++++++----
src/libsheepy.h                |  2 +-
3 files changed, 15 insertions(+), 6 deletions(-)

Diffstat:
Mrelease/libsheepy.h | 2+-
Msrc/json/libsheepyCSmallJson.c | 17+++++++++++++----
Msrc/libsheepy.h | 2+-
3 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/release/libsheepy.h b/release/libsheepy.h @@ -98,7 +98,7 @@ // version accoring to the version package: Release.Major.minor.patch // https://noulin.net/version/file/README.md.html -#define LIBSHEEPY_VERSION "2.2.6.1" +#define LIBSHEEPY_VERSION "2.2.6.2" #ifndef SH_PREFIX #define SH_PREFIX(NAME) NAME diff --git a/src/json/libsheepyCSmallJson.c b/src/json/libsheepyCSmallJson.c @@ -23389,7 +23389,10 @@ internal char** sDictToYMLForeach(sDictElemt *e, char *indentS2, int indent, int if (hasS(s, ":") || hasS(s, "{") || hasS(s, "}") || hasS(s, "[") || hasS(s, "]") || hasS(s, ",") || hasS(s, "&") || hasS(s, "*") || hasS(s, "#") || hasS(s, "?") || hasS(s, "|") || hasS(s, "-") || hasS(s, "<") || hasS(s, ">") || hasS(s, "==") || hasS(s, "!") || hasS(s, "%") || hasS(s, "@") || hasS(s, "\\") || hasS(s, "\"") || isBlankS(s) || isNumber(s)) { pErrorNULL(iAppendS(&line, ": \"")); char *q = replaceS_max(s, "\\", "\\\\"); - pErrorNULL(iReplaceS_max(&q, "\"", "\\\"")); + if (!isEmptyS(q)) { + // replace only when q is non empty, to avoid printing an error with pErrorNULL when q is empty + pErrorNULL(iReplaceS_max(&q, "\"", "\\\"")); + } pErrorNULL(iAppendNFreeS(&line, q)); free(s); pErrorNULL(iAppendS(&line, "\"\n")); @@ -23497,7 +23500,10 @@ internal char **sArrayToYML(sArrayt* array, int indent, int level) { // quote string if there are special characters if (hasS(s, ":") || hasS(s, "{") || hasS(s, "}") || hasS(s, "[") || hasS(s, "]") || hasS(s, ",") || hasS(s, "&") || hasS(s, "*") || hasS(s, "#") || hasS(s, "?") || hasS(s, "|") || hasS(s, "-") || hasS(s, "<") || hasS(s, ">") || hasS(s, "==") || hasS(s, "!") || hasS(s, "%") || hasS(s, "@") || hasS(s, "\\") || hasS(s, "\"") || isBlankS(s) || isNumber(s)) { char *q = replaceS_max(s, "\\", "\\\\"); - pErrorNULL(iReplaceS_max(&q, "\"", "\\\"")); + if (!isEmptyS(q)) { + // replace only when q is non empty, to avoid printing an error with pErrorNULL when q is empty + pErrorNULL(iReplaceS_max(&q, "\"", "\\\"")); + } line = catS(indentS2, "- \"", q, "\"\n");; free(q); } @@ -23573,8 +23579,11 @@ internal char* toYMLSmallJson(smallJsont *self, int indent) { return(r); case TOP_IS_STRING: s = sToString((smallt *)self->topS); - pErrorNULL(iReplaceS_max(&s, "\\", "\\\\")); - pErrorNULL(iReplaceS_max(&s, "\"", "\\\"")); + if (!isEmptyS(s)) { + // replace only when s is non empty, to avoid printing an error with pErrorNULL when s is empty + pErrorNULL(iReplaceS_max(&s, "\\", "\\\\")); + pErrorNULL(iReplaceS_max(&s, "\"", "\\\"")); + } r = catS("---\n \"", s, "\""); free(s); return(r); diff --git a/src/libsheepy.h b/src/libsheepy.h @@ -98,7 +98,7 @@ // version accoring to the version package: Release.Major.minor.patch // https://noulin.net/version/file/README.md.html -#define LIBSHEEPY_VERSION "2.2.6.1" +#define LIBSHEEPY_VERSION "2.2.6.2" #ifndef SH_PREFIX #define SH_PREFIX(NAME) NAME