MCPcopy Create free account
hub / github.com/coreutils/coreutils / eval6

Function eval6

src/expr.c:669–741  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

667/* Handle match, substr, index, and length keywords, and quoting "+". */
668
669static VALUE *
670eval6 (bool evaluate)
671{
672#ifdef EVAL_TRACE
673 trace ("eval6");
674#endif
675 if (nextarg ("+"))
676 {
677 require_more_args ();
678 return str_value (*args++);
679 }
680 else if (nextarg ("length"))
681 {
682 VALUE *r = eval6 (evaluate);
683 tostring (r);
684 VALUE *v = int_value (mbslen (r->u.s));
685 freev (r);
686 return v;
687 }
688 else if (nextarg ("match"))
689 {
690 VALUE *l = eval6 (evaluate);
691 VALUE *r = eval6 (evaluate);
692 VALUE *v;
693 if (evaluate)
694 {
695 v = docolon (l, r);
696 freev (l);
697 }
698 else
699 v = l;
700 freev (r);
701 return v;
702 }
703 else if (nextarg ("index"))
704 {
705 VALUE *l = eval6 (evaluate);
706 VALUE *r = eval6 (evaluate);
707 tostring (l);
708 tostring (r);
709 size_t pos = mbs_logical_cspn (l->u.s, r->u.s);
710 VALUE *v = int_value (pos);
711 freev (l);
712 freev (r);
713 return v;
714 }
715 else if (nextarg ("substr"))
716 {
717 VALUE *l = eval6 (evaluate);
718 VALUE *i1 = eval6 (evaluate);
719 VALUE *i2 = eval6 (evaluate);
720 tostring (l);
721
722 VALUE *v;
723 if (!toarith (i1) || !toarith (i2))
724 v = str_value ("");
725 else
726 {

Callers 1

eval5Function · 0.85

Calls 13

traceFunction · 0.85
nextargFunction · 0.85
require_more_argsFunction · 0.85
str_valueFunction · 0.85
tostringFunction · 0.85
int_valueFunction · 0.85
freevFunction · 0.85
docolonFunction · 0.85
mbs_logical_cspnFunction · 0.85
toarithFunction · 0.85
getsizeFunction · 0.85
mbs_logical_substrFunction · 0.85

Tested by

no test coverage detected