mirror of
https://github.com/boostorg/build.git
synced 2026-02-15 13:02:11 +00:00
63 lines
1.3 KiB
C
63 lines
1.3 KiB
C
|
|
#include "../native.h"
|
|
#include "../timestamp.h"
|
|
#include "../newstr.h"
|
|
#include "../strings.h"
|
|
#include "../regexp.h"
|
|
#include "../compile.h"
|
|
|
|
/*
|
|
rule transform ( list * : pattern )
|
|
{
|
|
local result ;
|
|
for local e in $(list)
|
|
{
|
|
local m = [ MATCH $(pattern) : $(e) ] ;
|
|
if $(m)
|
|
{
|
|
result += $(m[1]) ;
|
|
}
|
|
}
|
|
return $(result) ;
|
|
}
|
|
*/
|
|
LIST *regex_transform( PARSE *parse, FRAME *frame )
|
|
{
|
|
LIST* l = lol_get( frame->args, 0 );
|
|
LIST* pattern = lol_get( frame->args, 1 );
|
|
LIST* result = 0;
|
|
|
|
string buf[1];
|
|
string_new(buf);
|
|
|
|
|
|
/* Result is cached and intentionally never freed */
|
|
{
|
|
regexp *re = regex_compile( pattern->string );
|
|
|
|
for(; l; l = l->next)
|
|
{
|
|
if( regexec( re, l->string ) )
|
|
{
|
|
if (re->startp[1])
|
|
{
|
|
string_append_range( buf, re->startp[1], re->endp[1] );
|
|
result = list_new( result, newstr( buf->value ) );
|
|
string_truncate( buf, 0 );
|
|
}
|
|
}
|
|
}
|
|
string_free( buf );
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
void init_regex()
|
|
{
|
|
{
|
|
char* args[] = { "list", "*", ":", "pattern", 0 };
|
|
declare_native_rule("regex", "transform", args, regex_transform);
|
|
}
|
|
}
|