}
/* indexOf:
- * Return index of string s2 in string s1, or -1
+ * Return index of leftmost string s2 in string s1, or -1
*/
int indexOf(char *s1, char *s2)
{
return -1;
}
+/* rindexOf:
+ * Return index of rightmost string s2 in string s1, or -1
+ */
+int rindexOf(char *s1, char *s2)
+{
+ char c1 = *s2;
+ char c;
+ char *p;
+ int len1 = strlen(s1);
+ int len2 = strlen(s2);
+
+ if (c1 == '\0')
+ return (len1);
+ p = s1 + (len1 - len2);
+ while (p >= s1) {
+ c = *p;
+ if ((c == c1) && (strncmp(p+1, s2+1, len2-1) == 0))
+ return (p - s1);
+ else
+ p--;
+ }
+ return -1;
+}
+
/* match:
* Return index of pattern pat in string str, or -1
*/
extern Agobj_t *copy(Agraph_t * g, Agobj_t * obj);
extern int copyAttr(Agobj_t * obj, Agobj_t * obj1);
extern int indexOf(char *s1, char *s2);
+ extern int rindexOf(char *s1, char *s2);
extern int match(char *str, char *pat);
extern int lockGraph(Agraph_t * g, int);
extern Agraph_t *compOf(Agraph_t * g, Agnode_t * n);
case F_index:
v.integer = indexOf(args[0].string, args[1].string);
break;
+ case F_rindex:
+ v.integer = rindexOf(args[0].string, args[1].string);
+ break;
case F_match:
v.integer = match(args[0].string, args[1].string);
break;
F_compof "compOf" FUNCTION G|A(1,G)|A(2,V)
F_kindof "kindOf" FUNCTION S|A(1,O)
F_index "index" FUNCTION I|A(1,S)|A(2,S)
+F_rindex "rindex" FUNCTION I|A(1,S)|A(2,S)
F_isedge "isEdge" FUNCTION E|A(1,V)|A(2,V)|A(3,S)
F_isedgesg "isEdge_sg" FUNCTION E|A(1,G)|A(2,V)|A(3,V)|A(4,S)
F_issubedge "isSubedge" FUNCTION I|A(1,G)|A(2,E)
returns the length of the string \fIs\fP.
.TP
\fBindex\fP(\fIs\fP : \fBstring\fP, \fIt\fP : \fBstring\fP) : \fBint\fP
+.TP
+\fBrindex\fP(\fIs\fP : \fBstring\fP, \fIt\fP : \fBstring\fP) : \fBint\fP
returns the index of the character in string \fIs\fP where the leftmost
-copy of string \fIt\fP can be found, or \-1 if \fIt\fP is not a
+(rightmost) copy of string \fIt\fP can be found, or \-1 if \fIt\fP is not a
substring of \fIs\fP.
.TP
\fBmatch\fP(\fIs\fP : \fBstring\fP, \fIp\fP : \fBstring\fP) : \fBint\fP