diff --git a/lib/clixon/clixon_string.h b/lib/clixon/clixon_string.h index 689623e3..e1427863 100644 --- a/lib/clixon/clixon_string.h +++ b/lib/clixon/clixon_string.h @@ -100,7 +100,6 @@ int xml_chardata_encode(char **escp, const char *fmt, ...); #endif int xml_chardata_cbuf_append(cbuf *cb, char *str); int uri_percent_decode(char *enc, char **str); -int nonprint_encode(char *orig, char **encp); const char *clicon_int2str(const map_str2int *mstab, int i); int clicon_str2int(const map_str2int *mstab, char *str); diff --git a/lib/src/clixon_regex.c b/lib/src/clixon_regex.c index 60034ff4..73448bdc 100644 --- a/lib/src/clixon_regex.c +++ b/lib/src/clixon_regex.c @@ -89,6 +89,7 @@ * \p{Z} Separators [slp]? * \p{S} Symbols [mcko]? * \p{O} Other [cfon]? + * For non-printable, \n, \t, \r see https://www.regular-expressions.info/nonprint.html */ int regexp_xsd2posix(char *xsd, @@ -124,6 +125,9 @@ regexp_xsd2posix(char *xsd, case 'i': /* initial */ cprintf(cb, "[a-zA-Z_:]"); break; + case 'n': /* non-printable \n */ + cprintf(cb, "\n"); + break; case 'p': /* category escape: \p{IsCategory} */ j = i+1; if (j+2 < strlen(xsd) && @@ -161,12 +165,18 @@ regexp_xsd2posix(char *xsd, } /* if syntax error, just leave it */ break; + case 'r': /* non-printable */ + cprintf(cb, "\r"); + break; case 's': cprintf(cb, "[ \t\r\n]"); break; case 'S': cprintf(cb, "[^ \t\r\n]"); break; + case 't': /* non-printable */ + cprintf(cb, "\t"); + break; case 'w': /* word */ //cprintf(cb, "[0-9a-zA-Z_\\\\-]") cprintf(cb, "[^[:punct:][:space:][:cntrl:]]"); diff --git a/lib/src/clixon_string.c b/lib/src/clixon_string.c index 0e73b28a..d6004a32 100644 --- a/lib/src/clixon_string.c +++ b/lib/src/clixon_string.c @@ -646,83 +646,6 @@ uri_str2cvec(char *string, goto done; } -/*! Translate \n and others from \\n (two chars) to \n (one char) - * - * This is needed in yang regex it seems. - * It was triggered by eg draft-wwlh-netconf-list-pagination-00 module example-social tagline - * leaf tagline { - * type string { - * length "1..80"; - * pattern '.*[\n].*' { - * modifier invert-match; - * @param[in] orig Original string eg with \\n - * @param[out] enc Encoded string with \n, malloced. - * - * @see https://www.regular-expressions.info/nonprint.html - */ -int -nonprint_encode(char *orig, - char **encp) -{ - int retval = -1; - char *enc = NULL; - int i; - int j; - int esc = 0; - char c; - char c1; - - if (orig == NULL){ - clicon_err(OE_UNIX, EINVAL, "orig is NULL"); - goto done; - } - /* Encoded string is equal or shorter */ - if ((enc = malloc(strlen(orig)+1)) == NULL){ - clicon_err(OE_UNIX, errno, "strdup"); - goto done; - } - j = 0; - for (i=0; i