Revision 2415
Added by stephane over 13 years ago
scol_glib_pregex.c | ||
---|---|---|
302 | 302 |
|
303 | 303 |
int SCOL_pcreNormalReplace (mmachine m) |
304 | 304 |
{ |
305 |
int mpattern, mstring, mreplace, mcompile, mstart, mmatch; |
|
306 |
gchar *pattern, *string, *replace, *result; |
|
307 |
GRegex *regex; |
|
308 |
GError *error = NULL; |
|
309 |
|
|
310 |
MMechostr (MSKDEBUG, "SCOL_pcreNormalReplace : entering\n"); |
|
311 |
|
|
312 |
mmatch = MMpull (m); |
|
313 |
mstart = MTOI (MMpull (m)); |
|
314 |
mcompile = MMpull (m); |
|
315 |
mreplace = MTOP (MMpull (m)); |
|
316 |
mstring = MTOP (MMpull (m)); |
|
317 |
mpattern = MTOP (MMpull (m)); |
|
318 |
|
|
319 |
if(mstring == NIL) |
|
320 |
{ |
|
321 |
MMechostr (0, "SCOL_pcreNormalReplace error : string is nil"); |
|
322 |
MMpush (m, NIL); |
|
323 |
return 0; |
|
324 |
} |
|
325 |
if ((mreplace == NIL) || (mpattern == NIL)) |
|
326 |
{ |
|
327 |
Mpushstrbloc (m, MMstartstr (m, mstring)); |
|
328 |
return 0; |
|
329 |
} |
|
330 |
|
|
331 |
if (mstart < 0) |
|
332 |
mstart = 0; |
|
333 |
if (mcompile == NIL) |
|
334 |
mcompile = 0; |
|
335 |
if (mmatch == NIL) |
|
336 |
mmatch = 0; |
|
337 |
|
|
338 |
pattern = SCOLUTF8 (MMstartstr (m, mpattern), MMsizestr (m, mpattern)); |
|
339 |
string = SCOLUTF8 (MMstartstr (m, mstring), MMsizestr (m, mstring)); |
|
340 |
replace = SCOLUTF8 (MMstartstr (m, mreplace), MMsizestr (m, mreplace)); |
|
341 |
|
|
342 |
regex = scol_pcre_regex_new (pattern, mcompile, mmatch); |
|
343 |
result = g_regex_replace (regex, string, strlen (string), mstart, replace, mmatch, &error); |
|
344 |
g_regex_unref (regex); |
|
345 |
if (error != NULL) |
|
346 |
{ |
|
347 |
MMechostr (0, "SCOL_pcreNormalReplace error : %s\n", error->message); |
|
348 |
MMpush (m, NIL); |
|
349 |
g_error_free (error); |
|
350 |
} |
|
351 |
Mpushstrbloc (m, UTF8SCOL (result, strlen (result))); |
|
352 |
g_free (result); |
|
353 |
g_free (string); |
|
354 |
g_free (pattern); |
|
305 | 355 |
return 0; |
306 | 356 |
} |
307 | 357 |
|
... | ... | |
440 | 490 |
"_pcreEasyReplace", |
441 | 491 |
|
442 | 492 |
"_pcreNormalMatch", |
443 |
"_pcreNormalSplit" |
|
493 |
"_pcreNormalSplit", |
|
494 |
"_pcreNormalReplace" |
|
444 | 495 |
}; |
445 | 496 |
|
446 | 497 |
int (*glib_pcre_fun[GLIB_PCRE_PKG_NB])(mmachine m)= |
... | ... | |
462 | 513 |
SCOL_pcreEasyReplace, |
463 | 514 |
|
464 | 515 |
SCOL_pcreNormalMatch, |
465 |
SCOL_pcreNormalSplit |
|
516 |
SCOL_pcreNormalSplit, |
|
517 |
SCOL_pcreNormalReplace |
|
466 | 518 |
}; |
467 | 519 |
|
468 | 520 |
int glib_pcre_narg[GLIB_PCRE_PKG_NB]= |
... | ... | |
484 | 536 |
3, |
485 | 537 |
|
486 | 538 |
6, |
539 |
6, |
|
487 | 540 |
6 |
488 | 541 |
}; |
489 | 542 |
|
... | ... | |
506 | 559 |
"fun [S S S] S", |
507 | 560 |
|
508 | 561 |
"fun [S S I I I I] [[S I I] r1]", |
509 |
"fun [S S I I I I] [S r1]" |
|
562 |
"fun [S S I I I I] [S r1]", |
|
563 |
"fun [S S S I I I] S" |
|
510 | 564 |
}; |
511 | 565 |
|
512 | 566 |
/** |
Also available in: Unified diff
UTILS_G
- PCRE (regex)
- - add _pcreNormalReplace