1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-30 21:42:05 +03:00

I made the patch that implements regexp_replace again.

The specification of this function is as follows.

regexp_replace(source text, pattern text, replacement text, [flags
text])
returns text

Replace string that matches to regular expression in source text to
replacement text.

 - pattern is regular expression pattern.
 - replacement is replace string that can use '\1'-'\9', and '\&'.
    '\1'-'\9': back reference to the n'th subexpression.
    '\&'     : entire matched string.
 - flags can use the following values:
    g: global (replace all)
    i: ignore case
    When the flags is not specified, case sensitive, replace the first
    instance only.

Atsushi Ogawa
This commit is contained in:
Bruce Momjian
2005-07-10 04:54:33 +00:00
parent 73e2431817
commit 75a64eeb4b
10 changed files with 418 additions and 55 deletions

View File

@ -27,7 +27,7 @@
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* $PostgreSQL: pgsql/src/backend/regex/regexec.c,v 1.24 2003/11/29 19:51:55 pgsql Exp $
* $PostgreSQL: pgsql/src/backend/regex/regexec.c,v 1.25 2005/07/10 04:54:30 momjian Exp $
*
*/
@ -110,6 +110,7 @@ struct vars
regmatch_t *pmatch;
rm_detail_t *details;
chr *start; /* start of string */
chr *search_start; /* search start of string */
chr *stop; /* just past end of string */
int err; /* error code if any (0 none) */
regoff_t *mem; /* memory vector for backtracking */
@ -168,6 +169,7 @@ int
pg_regexec(regex_t *re,
const chr *string,
size_t len,
size_t search_start,
rm_detail_t *details,
size_t nmatch,
regmatch_t pmatch[],
@ -219,6 +221,7 @@ pg_regexec(regex_t *re,
v->pmatch = pmatch;
v->details = details;
v->start = (chr *) string;
v->search_start = (chr *) string + search_start;
v->stop = (chr *) string + len;
v->err = 0;
if (backref)
@ -288,7 +291,8 @@ find(struct vars * v,
NOERR();
MDEBUG(("\nsearch at %ld\n", LOFF(v->start)));
cold = NULL;
close = shortest(v, s, v->start, v->start, v->stop, &cold, (int *) NULL);
close = shortest(v, s, v->search_start, v->search_start, v->stop,
&cold, (int *) NULL);
freedfa(s);
NOERR();
if (v->g->cflags & REG_EXPECT)
@ -415,7 +419,7 @@ cfindloop(struct vars * v,
assert(d != NULL && s != NULL);
cold = NULL;
close = v->start;
close = v->search_start;
do
{
MDEBUG(("\ncsearch at %ld\n", LOFF(close)));