| 32 | */ |
| 33 | |
| 34 | LIST * regex_split( FRAME * frame, int flags ) |
| 35 | { |
| 36 | LIST * args = lol_get( frame->args, 0 ); |
| 37 | OBJECT * s; |
| 38 | OBJECT * separator; |
| 39 | regexp * re; |
| 40 | const char * pos, * prev; |
| 41 | LIST * result = L0; |
| 42 | LISTITER iter = list_begin( args ); |
| 43 | s = list_item( iter ); |
| 44 | separator = list_item( list_next( iter ) ); |
| 45 | |
| 46 | re = regex_compile( separator ); |
| 47 | |
| 48 | prev = pos = object_str( s ); |
| 49 | while ( regexec( re, pos ) ) |
| 50 | { |
| 51 | result = list_push_back( result, object_new_range( prev, int32_t(re->startp[ 0 ] - prev) ) ); |
| 52 | prev = re->endp[ 0 ]; |
| 53 | /* Handle empty matches */ |
| 54 | if ( *pos == '\0' ) |
| 55 | break; |
| 56 | else if ( pos == re->endp[ 0 ] ) |
| 57 | pos++; |
| 58 | else |
| 59 | pos = re->endp[ 0 ]; |
| 60 | } |
| 61 | |
| 62 | result = list_push_back( result, object_new( pos ) ); |
| 63 | |
| 64 | return result; |
| 65 | } |
| 66 | |
| 67 | /* |
| 68 | rule replace ( |
nothing calls this directly
no test coverage detected