| 83 | */ |
| 84 | |
| 85 | LIST * regex_replace( FRAME * frame, int flags ) |
| 86 | { |
| 87 | LIST * args = lol_get( frame->args, 0 ); |
| 88 | OBJECT * s; |
| 89 | OBJECT * match; |
| 90 | OBJECT * replacement; |
| 91 | regexp * re; |
| 92 | const char * pos; |
| 93 | string buf[ 1 ]; |
| 94 | LIST * result; |
| 95 | LISTITER iter = list_begin( args ); |
| 96 | s = list_item( iter ); |
| 97 | iter = list_next( iter ); |
| 98 | match = list_item( iter ); |
| 99 | iter = list_next( iter ); |
| 100 | replacement = list_item(iter ); |
| 101 | |
| 102 | re = regex_compile( match ); |
| 103 | |
| 104 | string_new( buf ); |
| 105 | |
| 106 | pos = object_str( s ); |
| 107 | while ( regexec( re, pos ) ) |
| 108 | { |
| 109 | string_append_range( buf, pos, re->startp[ 0 ] ); |
| 110 | string_append( buf, object_str( replacement ) ); |
| 111 | pos = re->endp[ 0 ]; |
| 112 | } |
| 113 | string_append( buf, pos ); |
| 114 | |
| 115 | result = list_new( object_new( buf->value ) ); |
| 116 | |
| 117 | string_free( buf ); |
| 118 | |
| 119 | return result; |
| 120 | } |
| 121 | |
| 122 | /* |
| 123 | rule transform ( list * : pattern : indices * ) |
nothing calls this directly
no test coverage detected