libyang REFACTOR avoid constant literals
Improve readability of the code.
Includes also unification of "no break in the case" comment to "fall
through".
diff --git a/src/tree_data.c b/src/tree_data.c
index f8a9775..8ea215a 100644
--- a/src/tree_data.c
+++ b/src/tree_data.c
@@ -275,11 +275,14 @@
/* ignore trailing whitespaces */
for ( ; len > 0 && isspace(path[len - 1]); len--) {}
- if ((len >= 5) && !strncmp(&path[len - 4], ".xml", 4)) {
+ if ((len >= LY_XML_SUFFIX_LEN + 1) &&
+ !strncmp(&path[len - LY_XML_SUFFIX_LEN], LY_XML_SUFFIX, LY_XML_SUFFIX_LEN)) {
format = LYD_XML;
- } else if ((len >= 6) && !strncmp(&path[len - 5], ".json", 5)) {
+ } else if ((len >= LY_JSON_SUFFIX_LEN + 1) &&
+ !strncmp(&path[len - LY_JSON_SUFFIX_LEN], LY_JSON_SUFFIX, LY_JSON_SUFFIX_LEN)) {
format = LYD_JSON;
- } else if ((len >= 5) && !strncmp(&path[len - 4], ".lyb", 4)) {
+ } else if ((len >= LY_LYB_SUFFIX_LEN + 1) &&
+ !strncmp(&path[len - LY_LYB_SUFFIX_LEN], LY_LYB_SUFFIX, LY_LYB_SUFFIX_LEN)) {
format = LYD_LYB;
} /* else still unknown */
}
@@ -1342,7 +1345,7 @@
}
break;
}
- /* fallthrough */
+ /* fall through */
case LYS_CONTAINER:
case LYS_NOTIF:
case LYS_RPC:
@@ -3000,7 +3003,7 @@
char quot;
val = LYD_CANON_VALUE(node);
- len = 4 + strlen(val) + 2;
+ len = 4 + strlen(val) + 2; /* "[.='" + val + "']" */
LY_CHECK_RET(lyd_path_str_enlarge(buffer, buflen, *bufused + len, is_static));
quot = '\'';