@@ -2605,6 +2605,26 @@ warn_is_numeric_type_base(LY_DATA_TYPE base)
26052605 }
26062606}
26072607
2608+ /**
2609+ * @brief Test whether a type base is string-like - no integers, decimal64 or binary.
2610+ *
2611+ * @return 1 if string, 0 otherwise.
2612+ */
2613+ static int
2614+ warn_is_string_type_base (LY_DATA_TYPE base )
2615+ {
2616+ switch (base & LY_DATA_TYPE_MASK ) {
2617+ case LY_TYPE_BITS :
2618+ case LY_TYPE_ENUM :
2619+ case LY_TYPE_IDENT :
2620+ case LY_TYPE_INST :
2621+ case LY_TYPE_STRING :
2622+ return 1 ;
2623+ default :
2624+ return 0 ;
2625+ }
2626+ }
2627+
26082628/**
26092629 * @brief Check both operands of comparison operators.
26102630 *
@@ -2749,8 +2769,8 @@ xpath_bit_is_set(struct lyxp_set **args, uint16_t UNUSED(arg_count), struct lyd_
27492769 if (!(sleaf -> nodetype & (LYS_LEAF | LYS_LEAFLIST ))) {
27502770 LOGWRN ("Argument #2 of %s is a %s node \"%s\"." , __func__ , strnodetype (sleaf -> nodetype ), sleaf -> name );
27512771 ret = EXIT_FAILURE ;
2752- } else if (sleaf -> type .base != LY_TYPE_STRING ) {
2753- LOGWRN ("Argument #2 of %s is node \"%s\", not of type \" string\" ." , __func__ , sleaf -> name );
2772+ } else if (! warn_is_string_type_base ( sleaf -> type .base ) ) {
2773+ LOGWRN ("Argument #2 of %s is node \"%s\", not of string-type ." , __func__ , sleaf -> name );
27542774 ret = EXIT_FAILURE ;
27552775 }
27562776 }
@@ -2886,8 +2906,8 @@ xpath_concat(struct lyxp_set **args, uint16_t arg_count, struct lyd_node *cur_no
28862906 LOGWRN ("Argument #%u of %s is a %s node \"%s\"." ,
28872907 i + 1 , __func__ , strnodetype (sleaf -> nodetype ), sleaf -> name );
28882908 ret = EXIT_FAILURE ;
2889- } else if (sleaf -> type .base != LY_TYPE_STRING ) {
2890- LOGWRN ("Argument #%u of %s is node \"%s\", not of type \" string\" ." , __func__ , i + 1 , sleaf -> name );
2909+ } else if (! warn_is_string_type_base ( sleaf -> type .base ) ) {
2910+ LOGWRN ("Argument #%u of %s is node \"%s\", not of string-type ." , __func__ , i + 1 , sleaf -> name );
28912911 ret = EXIT_FAILURE ;
28922912 }
28932913 }
@@ -2941,8 +2961,8 @@ xpath_contains(struct lyxp_set **args, uint16_t UNUSED(arg_count), struct lyd_no
29412961 if (!(sleaf -> nodetype & (LYS_LEAF | LYS_LEAFLIST ))) {
29422962 LOGWRN ("Argument #1 of %s is a %s node \"%s\"." , __func__ , strnodetype (sleaf -> nodetype ), sleaf -> name );
29432963 ret = EXIT_FAILURE ;
2944- } else if (sleaf -> type .base != LY_TYPE_STRING ) {
2945- LOGWRN ("Argument #1 of %s is node \"%s\", not of type \" string\" ." , __func__ , sleaf -> name );
2964+ } else if (! warn_is_string_type_base ( sleaf -> type .base ) ) {
2965+ LOGWRN ("Argument #1 of %s is node \"%s\", not of string-type ." , __func__ , sleaf -> name );
29462966 ret = EXIT_FAILURE ;
29472967 }
29482968 }
@@ -2951,8 +2971,8 @@ xpath_contains(struct lyxp_set **args, uint16_t UNUSED(arg_count), struct lyd_no
29512971 if (!(sleaf -> nodetype & (LYS_LEAF | LYS_LEAFLIST ))) {
29522972 LOGWRN ("Argument #2 of %s is a %s node \"%s\"." , __func__ , strnodetype (sleaf -> nodetype ), sleaf -> name );
29532973 ret = EXIT_FAILURE ;
2954- } else if (sleaf -> type .base != LY_TYPE_STRING ) {
2955- LOGWRN ("Argument #2 of %s is node \"%s\", not of type \" string\" ." , __func__ , sleaf -> name );
2974+ } else if (! warn_is_string_type_base ( sleaf -> type .base ) ) {
2975+ LOGWRN ("Argument #2 of %s is node \"%s\", not of string-type ." , __func__ , sleaf -> name );
29562976 ret = EXIT_FAILURE ;
29572977 }
29582978 }
@@ -3185,8 +3205,8 @@ xpath_derived_from(struct lyxp_set **args, uint16_t UNUSED(arg_count), struct ly
31853205 if (!(sleaf -> nodetype & (LYS_LEAF | LYS_LEAFLIST ))) {
31863206 LOGWRN ("Argument #2 of %s is a %s node \"%s\"." , __func__ , strnodetype (sleaf -> nodetype ), sleaf -> name );
31873207 ret = EXIT_FAILURE ;
3188- } else if (sleaf -> type .base != LY_TYPE_STRING ) {
3189- LOGWRN ("Argument #2 of %s is node \"%s\", not of type \" string\" ." , __func__ , sleaf -> name );
3208+ } else if (! warn_is_string_type_base ( sleaf -> type .base ) ) {
3209+ LOGWRN ("Argument #2 of %s is node \"%s\", not of string-type ." , __func__ , sleaf -> name );
31903210 ret = EXIT_FAILURE ;
31913211 }
31923212 }
@@ -3263,8 +3283,8 @@ xpath_derived_from_or_self(struct lyxp_set **args, uint16_t UNUSED(arg_count), s
32633283 if (!(sleaf -> nodetype & (LYS_LEAF | LYS_LEAFLIST ))) {
32643284 LOGWRN ("Argument #2 of %s is a %s node \"%s\"." , __func__ , strnodetype (sleaf -> nodetype ), sleaf -> name );
32653285 ret = EXIT_FAILURE ;
3266- } else if (sleaf -> type .base != LY_TYPE_STRING ) {
3267- LOGWRN ("Argument #2 of %s is node \"%s\", not of type \" string\" ." , __func__ , sleaf -> name );
3286+ } else if (! warn_is_string_type_base ( sleaf -> type .base ) ) {
3287+ LOGWRN ("Argument #2 of %s is node \"%s\", not of string-type ." , __func__ , sleaf -> name );
32683288 ret = EXIT_FAILURE ;
32693289 }
32703290 }
@@ -3437,8 +3457,8 @@ xpath_lang(struct lyxp_set **args, uint16_t UNUSED(arg_count), struct lyd_node *
34373457 if (!(sleaf -> nodetype & (LYS_LEAF | LYS_LEAFLIST ))) {
34383458 LOGWRN ("Argument #1 of %s is a %s node \"%s\"." , __func__ , strnodetype (sleaf -> nodetype ), sleaf -> name );
34393459 ret = EXIT_FAILURE ;
3440- } else if (sleaf -> type .base != LY_TYPE_STRING ) {
3441- LOGWRN ("Argument #1 of %s is node \"%s\", not of type \" string\" ." , __func__ , sleaf -> name );
3460+ } else if (! warn_is_string_type_base ( sleaf -> type .base ) ) {
3461+ LOGWRN ("Argument #1 of %s is node \"%s\", not of string-type ." , __func__ , sleaf -> name );
34423462 ret = EXIT_FAILURE ;
34433463 }
34443464 }
@@ -3792,8 +3812,8 @@ xpath_normalize_space(struct lyxp_set **args, uint16_t arg_count, struct lyd_nod
37923812 if (!(sleaf -> nodetype & (LYS_LEAF | LYS_LEAFLIST ))) {
37933813 LOGWRN ("Argument #1 of %s is a %s node \"%s\"." , __func__ , strnodetype (sleaf -> nodetype ), sleaf -> name );
37943814 ret = EXIT_FAILURE ;
3795- } else if (sleaf -> type .base != LY_TYPE_STRING ) {
3796- LOGWRN ("Argument #1 of %s is node \"%s\", not of type \" string\" ." , __func__ , sleaf -> name );
3815+ } else if (! warn_is_string_type_base ( sleaf -> type .base ) ) {
3816+ LOGWRN ("Argument #1 of %s is node \"%s\", not of string-type ." , __func__ , sleaf -> name );
37973817 ret = EXIT_FAILURE ;
37983818 }
37993819 }
@@ -3990,8 +4010,8 @@ xpath_re_match(struct lyxp_set **args, uint16_t UNUSED(arg_count), struct lyd_no
39904010 if (!(sleaf -> nodetype & (LYS_LEAF | LYS_LEAFLIST ))) {
39914011 LOGWRN ("Argument #1 of %s is a %s node \"%s\"." , __func__ , strnodetype (sleaf -> nodetype ), sleaf -> name );
39924012 ret = EXIT_FAILURE ;
3993- } else if (sleaf -> type .base != LY_TYPE_STRING ) {
3994- LOGWRN ("Argument #1 of %s is node \"%s\", not of type \" string\" ." , __func__ , sleaf -> name );
4013+ } else if (! warn_is_string_type_base ( sleaf -> type .base ) ) {
4014+ LOGWRN ("Argument #1 of %s is node \"%s\", not of string-type ." , __func__ , sleaf -> name );
39954015 ret = EXIT_FAILURE ;
39964016 }
39974017 }
@@ -4000,8 +4020,8 @@ xpath_re_match(struct lyxp_set **args, uint16_t UNUSED(arg_count), struct lyd_no
40004020 if (!(sleaf -> nodetype & (LYS_LEAF | LYS_LEAFLIST ))) {
40014021 LOGWRN ("Argument #2 of %s is a %s node \"%s\"." , __func__ , strnodetype (sleaf -> nodetype ), sleaf -> name );
40024022 ret = EXIT_FAILURE ;
4003- } else if (sleaf -> type .base != LY_TYPE_STRING ) {
4004- LOGWRN ("Argument #2 of %s is node \"%s\", not of type \" string\" ." , __func__ , sleaf -> name );
4023+ } else if (! warn_is_string_type_base ( sleaf -> type .base ) ) {
4024+ LOGWRN ("Argument #2 of %s is node \"%s\", not of string-type ." , __func__ , sleaf -> name );
40054025 ret = EXIT_FAILURE ;
40064026 }
40074027 }
@@ -4107,8 +4127,8 @@ xpath_starts_with(struct lyxp_set **args, uint16_t UNUSED(arg_count), struct lyd
41074127 if (!(sleaf -> nodetype & (LYS_LEAF | LYS_LEAFLIST ))) {
41084128 LOGWRN ("Argument #1 of %s is a %s node \"%s\"." , __func__ , strnodetype (sleaf -> nodetype ), sleaf -> name );
41094129 ret = EXIT_FAILURE ;
4110- } else if (sleaf -> type .base != LY_TYPE_STRING ) {
4111- LOGWRN ("Argument #1 of %s is node \"%s\", not of type \" string\" ." , __func__ , sleaf -> name );
4130+ } else if (! warn_is_string_type_base ( sleaf -> type .base ) ) {
4131+ LOGWRN ("Argument #1 of %s is node \"%s\", not of string-type ." , __func__ , sleaf -> name );
41124132 ret = EXIT_FAILURE ;
41134133 }
41144134 }
@@ -4117,8 +4137,8 @@ xpath_starts_with(struct lyxp_set **args, uint16_t UNUSED(arg_count), struct lyd
41174137 if (!(sleaf -> nodetype & (LYS_LEAF | LYS_LEAFLIST ))) {
41184138 LOGWRN ("Argument #2 of %s is a %s node \"%s\"." , __func__ , strnodetype (sleaf -> nodetype ), sleaf -> name );
41194139 ret = EXIT_FAILURE ;
4120- } else if (sleaf -> type .base != LY_TYPE_STRING ) {
4121- LOGWRN ("Argument #2 of %s is node \"%s\", not of type \" string\" ." , __func__ , sleaf -> name );
4140+ } else if (! warn_is_string_type_base ( sleaf -> type .base ) ) {
4141+ LOGWRN ("Argument #2 of %s is node \"%s\", not of string-type ." , __func__ , sleaf -> name );
41224142 ret = EXIT_FAILURE ;
41234143 }
41244144 }
@@ -4201,17 +4221,17 @@ xpath_string_length(struct lyxp_set **args, uint16_t arg_count, struct lyd_node
42014221 if (!(sleaf -> nodetype & (LYS_LEAF | LYS_LEAFLIST ))) {
42024222 LOGWRN ("Argument #1 of %s is a %s node \"%s\"." , __func__ , strnodetype (sleaf -> nodetype ), sleaf -> name );
42034223 ret = EXIT_FAILURE ;
4204- } else if (sleaf -> type .base != LY_TYPE_STRING ) {
4205- LOGWRN ("Argument #1 of %s is node \"%s\", not of type \" string\" ." , __func__ , sleaf -> name );
4224+ } else if (! warn_is_string_type_base ( sleaf -> type .base ) ) {
4225+ LOGWRN ("Argument #1 of %s is node \"%s\", not of string-type ." , __func__ , sleaf -> name );
42064226 ret = EXIT_FAILURE ;
42074227 }
42084228 }
42094229 if (!arg_count && (set -> type == LYXP_SET_SNODE_SET ) && (sleaf = (struct lys_node_leaf * )warn_get_snode_in_ctx (set ))) {
42104230 if (!(sleaf -> nodetype & (LYS_LEAF | LYS_LEAFLIST ))) {
42114231 LOGWRN ("Argument #0 of %s is a %s node \"%s\"." , __func__ , strnodetype (sleaf -> nodetype ), sleaf -> name );
42124232 ret = EXIT_FAILURE ;
4213- } else if (sleaf -> type .base != LY_TYPE_STRING ) {
4214- LOGWRN ("Argument #0 of %s is node \"%s\", not of type \" string\" ." , __func__ , sleaf -> name );
4233+ } else if (! warn_is_string_type_base ( sleaf -> type .base ) ) {
4234+ LOGWRN ("Argument #0 of %s is node \"%s\", not of string-type ." , __func__ , sleaf -> name );
42154235 ret = EXIT_FAILURE ;
42164236 }
42174237 }
@@ -4262,8 +4282,8 @@ xpath_substring(struct lyxp_set **args, uint16_t arg_count, struct lyd_node *cur
42624282 if (!(sleaf -> nodetype & (LYS_LEAF | LYS_LEAFLIST ))) {
42634283 LOGWRN ("Argument #1 of %s is a %s node \"%s\"." , __func__ , strnodetype (sleaf -> nodetype ), sleaf -> name );
42644284 ret = EXIT_FAILURE ;
4265- } else if (sleaf -> type .base != LY_TYPE_STRING ) {
4266- LOGWRN ("Argument #1 of %s is node \"%s\", not of type \" string\" ." , __func__ , sleaf -> name );
4285+ } else if (! warn_is_string_type_base ( sleaf -> type .base ) ) {
4286+ LOGWRN ("Argument #1 of %s is node \"%s\", not of string-type ." , __func__ , sleaf -> name );
42674287 ret = EXIT_FAILURE ;
42684288 }
42694289 }
@@ -4366,8 +4386,8 @@ xpath_substring_after(struct lyxp_set **args, uint16_t UNUSED(arg_count), struct
43664386 if (!(sleaf -> nodetype & (LYS_LEAF | LYS_LEAFLIST ))) {
43674387 LOGWRN ("Argument #1 of %s is a %s node \"%s\"." , __func__ , strnodetype (sleaf -> nodetype ), sleaf -> name );
43684388 ret = EXIT_FAILURE ;
4369- } else if (sleaf -> type .base != LY_TYPE_STRING ) {
4370- LOGWRN ("Argument #1 of %s is node \"%s\", not of type \" string\" ." , __func__ , sleaf -> name );
4389+ } else if (! warn_is_string_type_base ( sleaf -> type .base ) ) {
4390+ LOGWRN ("Argument #1 of %s is node \"%s\", not of string-type ." , __func__ , sleaf -> name );
43714391 ret = EXIT_FAILURE ;
43724392 }
43734393 }
@@ -4376,8 +4396,8 @@ xpath_substring_after(struct lyxp_set **args, uint16_t UNUSED(arg_count), struct
43764396 if (!(sleaf -> nodetype & (LYS_LEAF | LYS_LEAFLIST ))) {
43774397 LOGWRN ("Argument #2 of %s is a %s node \"%s\"." , __func__ , strnodetype (sleaf -> nodetype ), sleaf -> name );
43784398 ret = EXIT_FAILURE ;
4379- } else if (sleaf -> type .base != LY_TYPE_STRING ) {
4380- LOGWRN ("Argument #2 of %s is node \"%s\", not of type \" string\" ." , __func__ , sleaf -> name );
4399+ } else if (! warn_is_string_type_base ( sleaf -> type .base ) ) {
4400+ LOGWRN ("Argument #2 of %s is node \"%s\", not of string-type ." , __func__ , sleaf -> name );
43814401 ret = EXIT_FAILURE ;
43824402 }
43834403 }
@@ -4428,8 +4448,8 @@ xpath_substring_before(struct lyxp_set **args, uint16_t UNUSED(arg_count), struc
44284448 if (!(sleaf -> nodetype & (LYS_LEAF | LYS_LEAFLIST ))) {
44294449 LOGWRN ("Argument #1 of %s is a %s node \"%s\"." , __func__ , strnodetype (sleaf -> nodetype ), sleaf -> name );
44304450 ret = EXIT_FAILURE ;
4431- } else if (sleaf -> type .base != LY_TYPE_STRING ) {
4432- LOGWRN ("Argument #1 of %s is node \"%s\", not of type \" string\" ." , __func__ , sleaf -> name );
4451+ } else if (! warn_is_string_type_base ( sleaf -> type .base ) ) {
4452+ LOGWRN ("Argument #1 of %s is node \"%s\", not of string-type ." , __func__ , sleaf -> name );
44334453 ret = EXIT_FAILURE ;
44344454 }
44354455 }
@@ -4438,8 +4458,8 @@ xpath_substring_before(struct lyxp_set **args, uint16_t UNUSED(arg_count), struc
44384458 if (!(sleaf -> nodetype & (LYS_LEAF | LYS_LEAFLIST ))) {
44394459 LOGWRN ("Argument #2 of %s is a %s node \"%s\"." , __func__ , strnodetype (sleaf -> nodetype ), sleaf -> name );
44404460 ret = EXIT_FAILURE ;
4441- } else if (sleaf -> type .base != LY_TYPE_STRING ) {
4442- LOGWRN ("Argument #2 of %s is node \"%s\", not of type \" string\" ." , __func__ , sleaf -> name );
4461+ } else if (! warn_is_string_type_base ( sleaf -> type .base ) ) {
4462+ LOGWRN ("Argument #2 of %s is node \"%s\", not of string-type ." , __func__ , sleaf -> name );
44434463 ret = EXIT_FAILURE ;
44444464 }
44454465 }
@@ -4626,8 +4646,8 @@ xpath_translate(struct lyxp_set **args, uint16_t UNUSED(arg_count), struct lyd_n
46264646 if (!(sleaf -> nodetype & (LYS_LEAF | LYS_LEAFLIST ))) {
46274647 LOGWRN ("Argument #1 of %s is a %s node \"%s\"." , __func__ , strnodetype (sleaf -> nodetype ), sleaf -> name );
46284648 ret = EXIT_FAILURE ;
4629- } else if (sleaf -> type .base != LY_TYPE_STRING ) {
4630- LOGWRN ("Argument #1 of %s is node \"%s\", not of type \" string\" ." , __func__ , sleaf -> name );
4649+ } else if (! warn_is_string_type_base ( sleaf -> type .base ) ) {
4650+ LOGWRN ("Argument #1 of %s is node \"%s\", not of string-type ." , __func__ , sleaf -> name );
46314651 ret = EXIT_FAILURE ;
46324652 }
46334653 }
@@ -4636,8 +4656,8 @@ xpath_translate(struct lyxp_set **args, uint16_t UNUSED(arg_count), struct lyd_n
46364656 if (!(sleaf -> nodetype & (LYS_LEAF | LYS_LEAFLIST ))) {
46374657 LOGWRN ("Argument #2 of %s is a %s node \"%s\"." , __func__ , strnodetype (sleaf -> nodetype ), sleaf -> name );
46384658 ret = EXIT_FAILURE ;
4639- } else if (sleaf -> type .base != LY_TYPE_STRING ) {
4640- LOGWRN ("Argument #2 of %s is node \"%s\", not of type \" string\" ." , __func__ , sleaf -> name );
4659+ } else if (! warn_is_string_type_base ( sleaf -> type .base ) ) {
4660+ LOGWRN ("Argument #2 of %s is node \"%s\", not of string-type ." , __func__ , sleaf -> name );
46414661 ret = EXIT_FAILURE ;
46424662 }
46434663 }
@@ -4646,8 +4666,8 @@ xpath_translate(struct lyxp_set **args, uint16_t UNUSED(arg_count), struct lyd_n
46464666 if (!(sleaf -> nodetype & (LYS_LEAF | LYS_LEAFLIST ))) {
46474667 LOGWRN ("Argument #3 of %s is a %s node \"%s\"." , __func__ , strnodetype (sleaf -> nodetype ), sleaf -> name );
46484668 ret = EXIT_FAILURE ;
4649- } else if (sleaf -> type .base != LY_TYPE_STRING ) {
4650- LOGWRN ("Argument #3 of %s is node \"%s\", not of type \" string\" ." , __func__ , sleaf -> name );
4669+ } else if (! warn_is_string_type_base ( sleaf -> type .base ) ) {
4670+ LOGWRN ("Argument #3 of %s is node \"%s\", not of string-type ." , __func__ , sleaf -> name );
46514671 ret = EXIT_FAILURE ;
46524672 }
46534673 }
0 commit comments