Better handling of parsing integer and float values

This commit is contained in:
David Botton 2024-02-06 20:00:42 -05:00
parent f631a43059
commit d07b41dd73
10 changed files with 155 additions and 132 deletions

View file

@ -135,6 +135,38 @@ CLOG-OBJ unless :NAME is set and is used instead."))
"on"
"off"))
;;;;;;;;;;;;;;;;;;;
;; js-to-integer ;;
;;;;;;;;;;;;;;;;;;;
(defun js-to-integer (value &key (default 0))
"Returns two values first as an integer and second the original value"
(cond ((typep value 'integer)
(values value value))
((typep value 'string)
(let ((r (parse-integer value :junk-allowed t)))
(if r
(values r value)
(values default value))))
(t
(values default value))))
;;;;;;;;;;;;;;;;;
;; js-to-float ;;
;;;;;;;;;;;;;;;;;
(defun js-to-float (value &key (default 0.0d0))
"Returns two values first as a float and second the original value"
(cond ((typep value 'float)
(values value value))
((typep value 'string)
(let ((r (parse-float value :type 'double-float :junk-allowed t)))
(if r
(values r value)
(values default value))))
(t
(values default value))))
;;;;;;;;;;;;;;;;;;;
;; escape-string ;;
;;;;;;;;;;;;;;;;;;;