From: Jean Louis <bugs@gnu.support>
To: Robert Pluim <rpluim@gmail.com>
Cc: Eli Zaretskii <eliz@gnu.org>,
59531@debbugs.gnu.org,
Ramesh Nedunchezian <rameshnedunchezian@outlook.com>
Subject: bug#59531: 29.0.50: An alternative to `string-to-number` which throws an error (or returns a NIL value) when input is non-parseable as number
Date: Fri, 16 Dec 2022 09:28:14 +0300 [thread overview]
Message-ID: <Y5wP/tuTriNPv8ZE@protected.localdomain> (raw)
In-Reply-To: <87zgbqndl3.fsf@gmail.com>
(defun string-is-number-p (s)
"Return number only if string is actual number, otherwise NIL."
(let* ((s (string-trim s)))
(cond ((seq-empty-p s) nil)
((string-match "[^0123456789\\.-]" s) nil)
((string-match "-" s 1) nil)
((numberp (string-to-number s)) (string-to-number s)))))
I use this function to make sure string is number and it
returns either the number of nil, and function is not
exhaustive.
Jean
Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns
In support of Richard M. Stallman
https://stallmansupport.org/
next prev parent reply other threads:[~2022-12-16 6:28 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-24 6:14 bug#59531: 29.0.50: An alternative to `string-to-number` which throws an error (or returns a NIL value) when input is non-parseable as number Ramesh Nedunchezian
2022-11-24 8:00 ` Eli Zaretskii
2022-12-14 16:40 ` Robert Pluim
2022-12-16 6:28 ` Jean Louis [this message]
2022-11-24 10:08 ` Jean Louis
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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Y5wP/tuTriNPv8ZE@protected.localdomain \
--to=bugs@gnu.support \
--cc=59531@debbugs.gnu.org \
--cc=eliz@gnu.org \
--cc=rameshnedunchezian@outlook.com \
--cc=rpluim@gmail.com \
/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 public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).