Move Yang patterns: \n match from yang parse to regex compile stage
This commit is contained in:
parent
3ed41c5a04
commit
9aad253f1e
4 changed files with 10 additions and 90 deletions
|
|
@ -100,7 +100,6 @@ int xml_chardata_encode(char **escp, const char *fmt, ...);
|
||||||
#endif
|
#endif
|
||||||
int xml_chardata_cbuf_append(cbuf *cb, char *str);
|
int xml_chardata_cbuf_append(cbuf *cb, char *str);
|
||||||
int uri_percent_decode(char *enc, 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);
|
const char *clicon_int2str(const map_str2int *mstab, int i);
|
||||||
int clicon_str2int(const map_str2int *mstab, char *str);
|
int clicon_str2int(const map_str2int *mstab, char *str);
|
||||||
|
|
|
||||||
|
|
@ -89,6 +89,7 @@
|
||||||
* \p{Z} Separators [slp]?
|
* \p{Z} Separators [slp]?
|
||||||
* \p{S} Symbols [mcko]?
|
* \p{S} Symbols [mcko]?
|
||||||
* \p{O} Other [cfon]?
|
* \p{O} Other [cfon]?
|
||||||
|
* For non-printable, \n, \t, \r see https://www.regular-expressions.info/nonprint.html
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
regexp_xsd2posix(char *xsd,
|
regexp_xsd2posix(char *xsd,
|
||||||
|
|
@ -124,6 +125,9 @@ regexp_xsd2posix(char *xsd,
|
||||||
case 'i': /* initial */
|
case 'i': /* initial */
|
||||||
cprintf(cb, "[a-zA-Z_:]");
|
cprintf(cb, "[a-zA-Z_:]");
|
||||||
break;
|
break;
|
||||||
|
case 'n': /* non-printable \n */
|
||||||
|
cprintf(cb, "\n");
|
||||||
|
break;
|
||||||
case 'p': /* category escape: \p{IsCategory} */
|
case 'p': /* category escape: \p{IsCategory} */
|
||||||
j = i+1;
|
j = i+1;
|
||||||
if (j+2 < strlen(xsd) &&
|
if (j+2 < strlen(xsd) &&
|
||||||
|
|
@ -161,12 +165,18 @@ regexp_xsd2posix(char *xsd,
|
||||||
}
|
}
|
||||||
/* if syntax error, just leave it */
|
/* if syntax error, just leave it */
|
||||||
break;
|
break;
|
||||||
|
case 'r': /* non-printable */
|
||||||
|
cprintf(cb, "\r");
|
||||||
|
break;
|
||||||
case 's':
|
case 's':
|
||||||
cprintf(cb, "[ \t\r\n]");
|
cprintf(cb, "[ \t\r\n]");
|
||||||
break;
|
break;
|
||||||
case 'S':
|
case 'S':
|
||||||
cprintf(cb, "[^ \t\r\n]");
|
cprintf(cb, "[^ \t\r\n]");
|
||||||
break;
|
break;
|
||||||
|
case 't': /* non-printable */
|
||||||
|
cprintf(cb, "\t");
|
||||||
|
break;
|
||||||
case 'w': /* word */
|
case 'w': /* word */
|
||||||
//cprintf(cb, "[0-9a-zA-Z_\\\\-]")
|
//cprintf(cb, "[0-9a-zA-Z_\\\\-]")
|
||||||
cprintf(cb, "[^[:punct:][:space:][:cntrl:]]");
|
cprintf(cb, "[^[:punct:][:space:][:cntrl:]]");
|
||||||
|
|
|
||||||
|
|
@ -646,83 +646,6 @@ uri_str2cvec(char *string,
|
||||||
goto done;
|
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<strlen(orig); i++){
|
|
||||||
c = orig[i];
|
|
||||||
switch (c){
|
|
||||||
case '\\':
|
|
||||||
/* Look ahead */
|
|
||||||
if (i+1 < strlen(orig)){
|
|
||||||
c1 = orig[i+1];
|
|
||||||
switch (c1){
|
|
||||||
case 'n':
|
|
||||||
enc[j++] = '\n';
|
|
||||||
esc++;
|
|
||||||
break;
|
|
||||||
case 't':
|
|
||||||
enc[j++] = '\t';
|
|
||||||
esc++;
|
|
||||||
break;
|
|
||||||
case 'r':
|
|
||||||
enc[j++] = '\r';
|
|
||||||
esc++;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
enc[j++] = c;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
if (esc)
|
|
||||||
esc = 0;
|
|
||||||
else
|
|
||||||
enc[j++] = c;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
enc[j++] = '\0';
|
|
||||||
*encp = enc;
|
|
||||||
retval = 0;
|
|
||||||
done:
|
|
||||||
return retval;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*! Map from int to string using str2int map
|
/*! Map from int to string using str2int map
|
||||||
* @param[in] ms String, integer map
|
* @param[in] ms String, integer map
|
||||||
* @param[in] i Input integer
|
* @param[in] i Input integer
|
||||||
|
|
|
||||||
|
|
@ -1896,18 +1896,6 @@ ys_parse_sub(yang_stmt *ys,
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Y_PATTERN:{
|
|
||||||
char *s0;
|
|
||||||
char *s1 = NULL;
|
|
||||||
/* Replace \\n with \n */
|
|
||||||
s0 = yang_argument_get(ys);
|
|
||||||
if (nonprint_encode(s0, &s1) < 0)
|
|
||||||
goto done;
|
|
||||||
yang_argument_set(ys, s1);
|
|
||||||
if (s0)
|
|
||||||
free(s0);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case Y_UNKNOWN:{ /* save (optional) argument in ys_cv */
|
case Y_UNKNOWN:{ /* save (optional) argument in ys_cv */
|
||||||
if (extra == NULL)
|
if (extra == NULL)
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue