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

Function regex_transform

src/engine/modules/regex.cpp:152–216  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

150*/
151
152LIST * regex_transform( FRAME * frame, int flags )
153{
154 LIST * const l = lol_get( frame->args, 0 );
155 LIST * const pattern = lol_get( frame->args, 1 );
156 LIST * const indices_list = lol_get( frame->args, 2 );
157 int * indices = 0;
158 int size;
159 LIST * result = L0;
160
161 if ( !list_empty( indices_list ) )
162 {
163 int * p;
164 LISTITER iter = list_begin( indices_list );
165 LISTITER const end = list_end( indices_list );
166 size = list_length( indices_list );
167 indices = (int *)BJAM_MALLOC( size * sizeof( int ) );
168 for ( p = indices; iter != end; iter = list_next( iter ) )
169 *p++ = atoi( object_str( list_item( iter ) ) );
170 }
171 else
172 {
173 size = 1;
174 indices = (int *)BJAM_MALLOC( sizeof( int ) );
175 *indices = 1;
176 }
177
178 {
179 /* Result is cached and intentionally never freed */
180 regexp * const re = regex_compile( list_front( pattern ) );
181
182 LISTITER iter = list_begin( l );
183 LISTITER const end = list_end( l );
184
185 string buf[ 1 ];
186 string_new( buf );
187
188 for ( ; iter != end; iter = list_next( iter ) )
189 {
190 if ( regexec( re, object_str( list_item( iter ) ) ) )
191 {
192 int i = 0;
193 for ( ; i < size; ++i )
194 {
195 int const index = indices[ i ];
196 /* Skip empty submatches. Not sure it is right in all cases,
197 * but surely is right for the case for which this routine
198 * is optimized -- header scanning.
199 */
200 if ( re->startp[ index ] != re->endp[ index ] )
201 {
202 string_append_range( buf, re->startp[ index ],
203 re->endp[ index ] );
204 result = list_push_back( result, object_new( buf->value
205 ) );
206 string_truncate( buf, 0 );
207 }
208 }
209 }

Callers

nothing calls this directly

Calls 13

lol_getFunction · 0.85
list_beginFunction · 0.85
list_endFunction · 0.85
list_lengthFunction · 0.85
object_strFunction · 0.85
regex_compileFunction · 0.85
string_newFunction · 0.85
regexecFunction · 0.85
string_append_rangeFunction · 0.85
list_push_backFunction · 0.85
object_newFunction · 0.85
string_truncateFunction · 0.85

Tested by

no test coverage detected