Skip to content

Commit 4ad1ca9

Browse files
committed
tree data UPDATE option to compile pattern separately
1 parent 78b7795 commit 4ad1ca9

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/tree_data.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2735,6 +2735,17 @@ LIBYANG_API_DECL LY_ERR lyd_leafref_link_node_tree(const struct lyd_node *tree);
27352735
LIBYANG_API_DECL LY_ERR ly_pattern_match(const struct ly_ctx *ctx, const char *pattern, const char *string,
27362736
uint32_t str_len, pcre2_code **pcode);
27372737

2738+
/**
2739+
* @brief Compile an XML Schema regex pattern prior to matching.
2740+
*
2741+
* @param[in] ctx Optional context for storing errors.
2742+
* @param[in] pattern Regular expression pattern to use.
2743+
* @param[out] pcode Compiled @p pattern to be used by ::ly_pattern_match(). Free it using pcre2_code_free().
2744+
* @return LY_SUCCESS on success;
2745+
* @return LY_ERR on error.
2746+
*/
2747+
LIBYANG_API_DECL LY_ERR ly_pattern_compile(const struct ly_ctx *ctx, const char *pattern, pcre2_code **pcode);
2748+
27382749
#ifdef __cplusplus
27392750
}
27402751
#endif

src/tree_data_common.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1910,3 +1910,14 @@ ly_pattern_match(const struct ly_ctx *ctx, const char *pattern, const char *stri
19101910
}
19111911
return r;
19121912
}
1913+
1914+
LIBYANG_API_DEF LY_ERR
1915+
ly_pattern_compile(const struct ly_ctx *ctx, const char *pattern, pcre2_code **pcode)
1916+
{
1917+
LY_CHECK_ARG_RET(ctx, pattern, pcode, LY_EINVAL);
1918+
1919+
*pcode = NULL;
1920+
1921+
/* compile the pattern */
1922+
return lys_compile_type_pattern_check(ctx, pattern, pcode);
1923+
}

0 commit comments

Comments
 (0)