Re: string-match and string-looking-at
- From: Christopher Roy Bratusek <zanghar freenet de>
- To: sawfish-list gnome org
- Subject: Re: string-match and string-looking-at
- Date: Sun, 29 Aug 2010 11:40:42 +0200
Am Sun, 29 Aug 2010 11:58:24 +0300
schrieb Timo Korvola <Timo Korvola iki fi>:
> On Sunday 29 August 2010 04:26:43 Matthew Love wrote:
> > I've noticed that 'string-match and 'string-looking-at both
> > return an error when one of the input strings is '(). 'string=
> > will return '() in such cases.
>
> That is because string= is defined only as an alias for equal.
>
> > It seems it would be better for 'string-match and 'string-looking-at
> > to also return '() if one of the input "strings" is not actually a
> > string, as in such cases the strings do not technically match.
>
> I think it would be better for all three functions to report type errors
> as errors.
>
Check the attached patch.
diff --git a/src/find.c b/src/find.c
index 5e88038..9525b30 100644
--- a/src/find.c
+++ b/src/find.c
@@ -174,7 +174,7 @@ release_cached_regexps(void)
/* Storing regexp context. */
-
+
/* Storage for remembering where the last match was.
last_match_data is the string or buffer that was matched against.
last_matches is a copy of the subexpression data of the last match. */
@@ -280,16 +280,21 @@ still case-significant.
{
rep_regexp *prog;
long xstart;
- if(rep_STRINGP(re) && rep_STRINGP(str))
- {
+
+ if (!rep_STRINGP(re))
+ {
+ return rep_signal_arg_error(re, 1);
+ }
+ else if (!rep_STRINGP(string))
+ {
+ return rep_signal_arg_error(string, 2);
+ }
+ else
+ {
rep_DECLARE1(re, rep_STRINGP);
rep_DECLARE2(str, rep_STRINGP);
- }
- else
- {
- fprintf (stderr, " ** only strings are allowed to be passed to `string-match'.");
- return Qnil;
- }
+ }
+
rep_DECLARE3_OPT(start, rep_INTP);
xstart = rep_INTP(start) ? rep_INT(start) : 0;
prog = rep_compile_regexp(re);
@@ -320,16 +325,21 @@ Updates the match data.
{
rep_regexp *prog;
long xstart;
+
+ if (!rep_STRINGP(re))
+ {
+ return rep_signal_arg_error(re, 1);
+ }
+ else if (!rep_STRINGP(string))
+ {
+ return rep_signal_arg_error(string, 2);
+ }
if(rep_STRINGP(re) && rep_STRINGP(string))
- {
+ {
rep_DECLARE1(re, rep_STRINGP);
rep_DECLARE2(string, rep_STRINGP);
- }
- else
- {
- fprintf (stderr, " ** only strings are allowed to be passed to `string-looking-at'.");
- return Qnil;
- }
+ }
+
rep_DECLARE3_OPT(start, rep_INTP);
xstart = rep_INTP(start) ? rep_INT(start) : 0;
prog = rep_compile_regexp(re);
@@ -409,7 +419,7 @@ buffer, or an integer if the last match was in a string (i.e. regexp-match).
return(rep_MAKE_INT(i));
}
}
-
+
DEFUN("match-end", Fmatch_end, Smatch_end, (repv exp), rep_Subr1) /*
::doc:rep.regexp#match-end::
match-end [EXPRESSION-INDEX]
@@ -544,7 +554,7 @@ Returns (SOFT-LIMIT CURRENT-SIZE CURRENT-ENTRIES HITS MISSES).
return rep_list_5(rep_MAKE_INT(regexp_cache_limit),
rep_MAKE_INT(current_size), rep_MAKE_INT(current_items),
rep_MAKE_INT(regexp_hits), rep_MAKE_INT(regexp_misses));
-}
+}
void
rep_regerror(char *err)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]