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

Function regex_transform

v2/engine/modules/regex.c:139–203  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

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