all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Juanma Barranquero <lekktu@gmail.com>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: Eli Zaretskii <eliz@gnu.org>, emacs-devel@gnu.org
Subject: Re: Inconsistency in `string-to-number'
Date: Fri, 4 Dec 2009 04:21:27 +0100	[thread overview]
Message-ID: <f7ccd24b0912031921q689d4c3fv8e8441a4559b5cd1@mail.gmail.com> (raw)
In-Reply-To: <jwvhbsabglv.fsf-monnier+emacs@gnu.org>

On Tue, Dec 1, 2009 at 21:15, Stefan Monnier <monnier@iro.umontreal.ca> wrote:

> Sorry, your email got misfiled.

No problem.

>>  3) Allow any trailing char.
>>      Pro: forgiving.
>>      Cons: (unlikely) incompatibility with uses of undocumented "1.2:" => 1
>
> That would be my choice.  The behavior is still fairly regular, so the
> doc shouldn't be too scary, and it works about as well as now.

OK.

> I'd need to see the patch to pronouce myself on the uncleanliness.

Attached.

    Juanma



diff --git a/src/lisp.h b/src/lisp.h
index 2052dfa..3bdecc5 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -2795,7 +2795,7 @@ extern Lisp_Object Vcurrent_load_list;
 extern Lisp_Object Vload_history, Vload_suffixes, Vload_file_rep_suffixes;
 extern int openp P_ ((Lisp_Object, Lisp_Object, Lisp_Object,
 		      Lisp_Object *, Lisp_Object));
-extern int isfloat_string P_ ((char *));
+extern int isfloat_string P_ ((char *, int));
 extern void map_obarray P_ ((Lisp_Object, void (*) (Lisp_Object, Lisp_Object),
 			     Lisp_Object));
 extern void dir_warning P_ ((char *, Lisp_Object));
diff --git a/src/lread.c b/src/lread.c
index 97b9410..f9b51a8 100644
--- a/src/lread.c
+++ b/src/lread.c
@@ -3026,7 +3026,7 @@ read1 (readcharfun, pch, first_in_list)
 		    }
 		  }
 	      }
-	    if (isfloat_string (read_buffer))
+	    if (isfloat_string (read_buffer, 0))
 	      {
 		/* Compute NaN and infinities using 0.0 in a variable,
 		   to cope with compilers that think they are smarter
@@ -3244,8 +3244,9 @@ substitute_in_interval (interval, arg)
 #define EXP_INT 16

 int
-isfloat_string (cp)
+isfloat_string (cp, ignore_trailing)
      register char *cp;
+     int ignore_trailing;
 {
   register int state;

@@ -3299,7 +3300,8 @@ isfloat_string (cp)
       cp += 3;
     }

-  return (((*cp == 0) || (*cp == ' ') || (*cp == '\t') || (*cp ==
'\n') || (*cp == '\r') || (*cp == '\f'))
+  return ((ignore_trailing
+           || (*cp == 0) || (*cp == ' ') || (*cp == '\t') || (*cp ==
'\n') || (*cp == '\r') || (*cp == '\f'))
 	  && (state == (LEAD_INT|DOT_CHAR|TRAIL_INT)
 	      || state == (DOT_CHAR|TRAIL_INT)
 	      || state == (LEAD_INT|E_CHAR|EXP_INT)
diff --git a/src/data.c b/src/data.c
index ce2d842..0f47556 100644
--- a/src/data.c
+++ b/src/data.c
@@ -2353,11 +2353,11 @@ digit_to_number (character, base)
 DEFUN ("string-to-number", Fstring_to_number, Sstring_to_number, 1, 2, 0,
        doc: /* Parse STRING as a decimal number and return the number.
 This parses both integers and floating point numbers.
-It ignores leading spaces and tabs.
+It ignores leading spaces and tabs, and all trailing chars.

 If BASE, interpret STRING as a number in that base.  If BASE isn't
 present, base 10 is used.  BASE must be between 2 and 16 (inclusive).
-If the base used is not 10, floating point is not recognized.  */)
+If the base used is not 10, STRING is always parsed as integer.  */)
      (string, base)
      register Lisp_Object string, base;
 {
@@ -2392,7 +2392,7 @@ If the base used is not 10, floating point is
not recognized.  */)
   else if (*p == '+')
     p++;

-  if (isfloat_string (p) && b == 10)
+  if (isfloat_string (p, 1) && b == 10)
     val = make_float (sign * atof (p));
   else
     {




  reply	other threads:[~2009-12-04  3:21 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-04-24  0:16 Inconsistency in `string-to-number' Davis Herring
2009-04-24 10:36 ` Eli Zaretskii
2009-04-24 11:45   ` Juanma Barranquero
2009-04-24 13:19     ` Eli Zaretskii
2009-04-24 14:13       ` Juanma Barranquero
2009-04-24 13:22     ` Stefan Monnier
2009-04-24 13:38       ` Juanma Barranquero
2009-04-24 14:06         ` Stefan Monnier
2009-04-24 14:16           ` Juanma Barranquero
2009-09-05  0:30           ` Juanma Barranquero
2009-12-01 20:15             ` Stefan Monnier
2009-12-04  3:21               ` Juanma Barranquero [this message]
2009-12-04  3:23                 ` Juanma Barranquero
2009-12-04 14:22                 ` Stefan Monnier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f7ccd24b0912031921q689d4c3fv8e8441a4559b5cd1@mail.gmail.com \
    --to=lekktu@gmail.com \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.