Re: Substring patch

From: David Fox <fox_at_remove.this.cat.nyu.edu>
Date: 04 Dec 1996 06:43:47 -0500

Erik Ostrom <eostrom_at_research.att.com> writes:

> Another approach would be to change the regexp interface. For example,
> regexps could operate on string ports--returning some sort of match
> structure and consuming the port as you go.

Simpler, if less elegant, would be to allow an offset argument to the
regexp apply operation. With this patch the resulting indexes are in
relation to the beginning of the string, not to the offset position.

diff -ru STk-3.1/Extensions/sregexp.c~ STk-3.1/Extensions/sregexp.c
--- STk-3.1/Extensions/sregexp.c~ Sun Jun 16 16:31:41 1996
+++ STk-3.1/Extensions/sregexp.c Wed Dec 4 05:54:22 1996
_at_@ -75,15 +75,23 @@
 static PRIMITIVE apply_regexp(SCM regexp, SCM l, SCM env)
 {
   SCM string;
+ int offset;
   char *the_chars;
 
- if (STk_llength (l) != 1) err ("apply: bad number of args", l);
- string = CAR (l);
-
+ if (STk_llength(l) < 1 || STk_llength(l) > 2)
+ err ("apply: bad number of args", l);
+ string = CAR(l); offset = 0;
   if (NSTRINGP (string)) err ("regexp: bad string", string);
+ if (STk_llength(l) == 2) {
+ if (NINTEGERP(CAR(CDR(l))))
+ err("regexp: bad offset", CAR(CDR(l)));
+ offset = INTEGER(CAR(CDR(l)));
+ if (offset < 0 || offset > STRSIZE(string))
+ err("regexp: offset out of bounds", CAR(CDR(l)));
+ }
   the_chars = CHARS (string);
   
- if (TclRegExec(REGEXP(regexp), the_chars, the_chars)) {
+ if (TclRegExec(REGEXP(regexp), &the_chars[offset], &the_chars[offset])) {
     struct regexp *r = REGEXP(regexp);
     SCM z = NIL;
     int i;

-- 
David Fox	    http://www.cat.nyu.edu/fox		 xoF divaD
NYU Media Research Lab   fox_at_cat.nyu.edu    baL hcraeseR aideM UYN
Received on Wed Dec 04 1996 - 12:35:36 CET

This archive was generated by hypermail 2.3.0 : Mon Jul 21 2014 - 19:38:59 CEST