MCPcopy Create free account
hub / github.com/boostorg/build / regex_replace

Function regex_replace

src/engine/modules/regex.cpp:92–133  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

90*/
91
92LIST * regex_replace( FRAME * frame, int flags )
93{
94 LIST * args = lol_get( frame->args, 0 );
95 OBJECT * s;
96 OBJECT * match;
97 OBJECT * replacement;
98 regexp * re;
99 const char * pos;
100 string buf[ 1 ];
101 LIST * result;
102 LISTITER iter = list_begin( args );
103 s = list_item( iter );
104 iter = list_next( iter );
105 match = list_item( iter );
106 iter = list_next( iter );
107 replacement = list_item(iter );
108
109 re = regex_compile( match );
110
111 string_new( buf );
112
113 pos = object_str( s );
114 while ( regexec( re, pos ) )
115 {
116 string_append_range( buf, pos, re->startp[ 0 ] );
117 string_append( buf, object_str( replacement ) );
118 /* Handle empty matches */
119 if ( *pos == '\0' )
120 break;
121 else if ( pos == re->endp[ 0 ] )
122 string_push_back( buf, *pos++ );
123 else
124 pos = re->endp[ 0 ];
125 }
126 string_append( buf, pos );
127
128 result = list_new( object_new( buf->value ) );
129
130 string_free( buf );
131
132 return result;
133}
134
135/*
136rule transform ( list * : pattern : indices * )

Callers

nothing calls this directly

Calls 12

lol_getFunction · 0.85
list_beginFunction · 0.85
regex_compileFunction · 0.85
string_newFunction · 0.85
object_strFunction · 0.85
regexecFunction · 0.85
string_append_rangeFunction · 0.85
string_appendFunction · 0.85
string_push_backFunction · 0.85
list_newFunction · 0.85
object_newFunction · 0.85
string_freeFunction · 0.85

Tested by

no test coverage detected