Skip to content

Commit

Permalink
String index (&sin) function returns unicode position.
Browse files Browse the repository at this point in the history
  • Loading branch information
rfivet committed Jun 25, 2020
1 parent cf823e2 commit c6baa2f
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions eval.c
Original file line number Diff line number Diff line change
Expand Up @@ -1384,24 +1384,30 @@ static int sindex( char *source, char *pattern) {

/* scanning through the source string */
sp = source;
int idx = 1 ;
int pos = 0 ;
int len = strlen( source) ;

while (*sp) {
char *csp; /* ptr to source string during comparison */
char *cp; /* ptr to place to check for equality */
char c ;
unicode_t uc ;

/* scan through the pattern */
cp = pattern;
csp = sp;
while (*cp) {
if (!eq(*cp, *csp))
break;
++cp;
++csp;
}

while( (c = *cp++) && eq( c, *csp))
csp++ ;

/* was it a match? */
if (*cp == 0)
return (int) (sp - source) + 1;
++sp;
if( c == 0)
return idx ;

idx += 1 ;
pos += utf8_to_unicode( source, pos, len, &uc) ;
sp = &source[ pos] ;
}

/* no match at all.. */
Expand Down

0 comments on commit c6baa2f

Please sign in to comment.