chiark
/
gitweb
/
~mdw
/
disorder
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge branch 'master' of git.distorted.org.uk:~mdw/publish/public-git/disorder
[disorder]
/
lib
/
regsub.c
diff --git
a/lib/regsub.c
b/lib/regsub.c
index aab20e23f957c3429950554b94a78853381c0f00..d83a2ae11cdf4c9f5bc35182113c65c7bcd7c95c 100644
(file)
--- a/
lib/regsub.c
+++ b/
lib/regsub.c
@@
-15,11
+15,12
@@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-
+/** @file lib/regsub.c
+ * @brief Regexp substitution
+ */
#include "common.h"
#include "common.h"
-#include <pcre.h>
-
+#include "regexp.h"
#include "regsub.h"
#include "mem.h"
#include "vector.h"
#include "regsub.h"
#include "mem.h"
#include "vector.h"
@@
-28,9
+29,9
@@
#define PREMATCH (-1) /* fictitious pre-match substring */
#define POSTMATCH (-2) /* fictitious post-match substring */
#define PREMATCH (-1) /* fictitious pre-match substring */
#define POSTMATCH (-2) /* fictitious post-match substring */
-static inline
in
t substring_start(const char attribute((unused)) *subject,
-
const in
t *ovector,
-
in
t n) {
+static inline
size_
t substring_start(const char attribute((unused)) *subject,
+
const size_
t *ovector,
+
size_
t n) {
switch(n) {
case PREMATCH: return 0;
case POSTMATCH: return ovector[1];
switch(n) {
case PREMATCH: return 0;
case POSTMATCH: return ovector[1];
@@
-38,9
+39,9
@@
static inline int substring_start(const char attribute((unused)) *subject,
}
}
}
}
-static inline
in
t substring_end(const char *subject,
-
const in
t *ovector,
-
in
t n) {
+static inline
size_
t substring_end(const char *subject,
+
const size_
t *ovector,
+
size_
t n) {
switch(n) {
case PREMATCH: return ovector[0];
case POSTMATCH: return strlen(subject);
switch(n) {
case PREMATCH: return ovector[0];
case POSTMATCH: return strlen(subject);
@@
-50,8
+51,8
@@
static inline int substring_end(const char *subject,
static void transform_append(struct dynstr *d,
const char *subject,
static void transform_append(struct dynstr *d,
const char *subject,
- const
in
t *ovector,
-
in
t n) {
+ const
size_
t *ovector,
+
size_
t n) {
int start = substring_start(subject, ovector, n);
int end = substring_end(subject, ovector, n);
int start = substring_start(subject, ovector, n);
int end = substring_end(subject, ovector, n);
@@
-62,9
+63,9
@@
static void transform_append(struct dynstr *d,
static void replace_core(struct dynstr *d,
const char *subject,
const char *replace,
static void replace_core(struct dynstr *d,
const char *subject,
const char *replace,
-
in
t rc,
- const
in
t *ovector) {
-
in
t substr;
+
size_
t rc,
+ const
size_
t *ovector) {
+
size_
t substr;
while(*replace) {
if(*replace == '$')
while(*replace) {
if(*replace == '$')
@@
-111,20
+112,21
@@
int regsub_compile_options(unsigned flags) {
int options = 0;
if(flags & REGSUB_CASE_INDEPENDENT)
int options = 0;
if(flags & REGSUB_CASE_INDEPENDENT)
- options |=
PCRE
_CASELESS;
+ options |=
RXF
_CASELESS;
return options;
}
return options;
}
-const char *regsub(const pcre *re, const char *subject, const char *replace,
- unsigned flags) {
- int rc, ovector[99], matches;
+const char *regsub(const regexp *re, const char *subject,
+ const char *replace, unsigned flags) {
+ int rc, matches;
+ size_t ovector[99];
struct dynstr d;
dynstr_init(&d);
matches = 0;
/* find the next match */
struct dynstr d;
dynstr_init(&d);
matches = 0;
/* find the next match */
- while((rc =
pcre_exec(re, 0
, subject, strlen(subject), 0,
-
0, ovector, sizeof ovector / sizeof (int
))) > 0) {
+ while((rc =
regexp_match(re
, subject, strlen(subject), 0,
+
ovector, sizeof ovector / sizeof (ovector[0]
))) > 0) {
/* text just before the match */
if(!(flags & REGSUB_REPLACE))
transform_append(&d, subject, ovector, PREMATCH);
/* text just before the match */
if(!(flags & REGSUB_REPLACE))
transform_append(&d, subject, ovector, PREMATCH);
@@
-140,8
+142,8
@@
const char *regsub(const pcre *re, const char *subject, const char *replace,
if(!(flags & REGSUB_GLOBAL))
break;
}
if(!(flags & REGSUB_GLOBAL))
break;
}
- if(rc <= 0 && rc !=
PCRE_ERRO
R_NOMATCH) {
-
error(0, "pcre_exec
returned %d, subject '%s'", rc, subject);
+ if(rc <= 0 && rc !=
RXER
R_NOMATCH) {
+
disorder_error(0, "regexp_match
returned %d, subject '%s'", rc, subject);
return 0;
}
if((flags & REGSUB_MUST_MATCH) && matches == 0)
return 0;
}
if((flags & REGSUB_MUST_MATCH) && matches == 0)