[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/tomelr a676192b43 81/84: fix: Integer coercing of a num
From: |
ELPA Syncer |
Subject: |
[elpa] externals/tomelr a676192b43 81/84: fix: Integer coercing of a number strings with underscores |
Date: |
Tue, 3 May 2022 09:58:16 -0400 (EDT) |
branch: externals/tomelr
commit a676192b435474fbff53fe361dbf983e3b8ac799
Author: Kaushal Modi <kaushal.modi@gmail.com>
Commit: Kaushal Modi <kaushal.modi@gmail.com>
fix: Integer coercing of a number strings with underscores
---
test/tcoerce.el | 8 ++++++++
tomelr.el | 64 ++++++++++++++++++++++++++-------------------------------
2 files changed, 37 insertions(+), 35 deletions(-)
diff --git a/test/tcoerce.el b/test/tcoerce.el
index 9b5295adef..f2c91c3199 100644
--- a/test/tcoerce.el
+++ b/test/tcoerce.el
@@ -70,12 +70,16 @@
;; (fixnump (string-to-number "10040216507682529280")) ;=> nil
;; So this number won't be coerced.
((key . "10040216507682529280"))
+ ((key . ("123" "-5" "17" "1_234")))
+ ((key . (123 -5 17 1_234)))
))
(ref '(
"key = -123"
"key = 0"
"key = 123"
"key = \"10040216507682529280\""
+ "key = [123, -5, 17, 1_234]"
+ "key = [123, -5, 17, 1_234]"
))
out)
(dolist (el inp)
@@ -87,10 +91,14 @@
(inp '(
((key . "123"))
((key . "10040216507682529280"))
+ ((key . ("123" "-5" "17" "1_234")))
+ ((key . (123 -5 17 1_234)))
))
(ref '(
"key = \"123\""
"key = \"10040216507682529280\""
+ "key = [\"123\", \"-5\", \"17\", \"1_234\"]"
+ "key = [123, -5, 17, 1_234]"
))
out)
(dolist (el inp)
diff --git a/tomelr.el b/tomelr.el
index 1bd2de3ead..650328e5ce 100644
--- a/tomelr.el
+++ b/tomelr.el
@@ -187,17 +187,6 @@ Return the same STRING passed as input."
(and end-q (insert end-q))
string))
-(defun tomelr--quote-string-maybe (str)
- "Return STR wrapped in quotes if it's not already."
- (let ((quoted-str (or str "")))
- (unless (or ;; RFC 3339 formatted date-time with offset.
- (string-match-p tomelr--date-time-regexp str)
- ;; str is already wrapped with quotes.
- (and (string= (substring str 0 1) "\"")
- (string= (substring str -1) "\"")))
- (setq quoted-str (format "\"%s\"" quoted-str)))
- quoted-str))
-
(defun tomelr--print-stringlike (object &optional key-type)
"Insert OBJECT encoded as a TOML string at point.
@@ -230,10 +219,10 @@ Return nil if OBJECT cannot be encoded as a TOML string."
;; Cases where object is a key value.
((symbolp object)
- (tomelr--quote-string-maybe (symbol-name object)))
+ (symbol-name object))
((stringp object)
object))))
-
+ ;; (message "[tomelr--print-stringlike DBG] str = %S" str)
(when (member key-type '(table-key table-array-key))
;; (message "[tomelr--print-stringlike DBG] %S is symbol, type = %S,
depth = %d"
;; object type tomelr--print-indentation-depth)
@@ -261,29 +250,34 @@ Return nil if OBJECT cannot be encoded as a TOML string."
;; Normal keys (Alist and Plist keys)
((equal key-type 'normal-key)
(princ str))
- ;; Date/Time
- ((and (stringp object)
- (string-match-p tomelr--date-time-regexp object))
- (princ object))
+ ;; Coercing
+ ((and (stringp str)
+ (or
+ ;; RFC 3339 Date/Time
+ (string-match-p tomelr--date-time-regexp str)
+
+ ;; Integer that can be stored in the system as a fixnum.
+ ;; For example, if `object' is "10040216507682529280" that
+ ;; needs more than 64 bits to be stored as a signed
+ ;; integer, it will be automatically stored as a float.
+ ;; So (integerp (string-to-number object)) will return nil
+ ;; [or `fixnump' instead of `integerp' in Emacs 27 or
+ ;; newer].
+ ;; https://github.com/toml-lang/toml#integer
+ ;; Integer examples: 7, +7, -7, 7_000
+ (and (or (symbolp object)
+ (member 'integer tomelr-coerce-to-types))
+ (string-match-p "\\`[+-]?[[:digit:]_]+\\'" str)
+ (if (functionp #'fixnump) ;`fixnump' and `bignump' get
introduced in Emacs 27.x
+ (fixnump (string-to-number str))
+ ;; On older Emacsen, `integerp' behaved the same as the
+ ;; new `fixnump'.
+ (integerp (string-to-number str))))))
+ (princ str))
+ ((symbolp object)
+ (princ (format "%S" str)))
((stringp object)
- (cond
- ;; If it an integer that can be stored in the system as a
- ;; fixnum. For example, if `object' is "10040216507682529280"
- ;; that needs more than 64 bits to be stored as a signed
- ;; integer, it will be automatically stored as a float. So
- ;; (integerp (string-to-number object)) will return nil [or
- ;; `fixnump' instead of `integerp' in Emacs 27 or newer]
- ;; https://github.com/toml-lang/toml#integer
- ;; Integer examples: 7, +7, -7, 7_000
- ((and (member 'integer tomelr-coerce-to-types)
- (string-match-p "\\`[+-]?[[:digit:]_]+\\'" object)
- (if (functionp #'fixnump) ;`fixnump' and `bignump' get introduced
in Emacs 27.x
- (fixnump (string-to-number object))
- (integerp (string-to-number object)))) ;On older Emacsen,
`integerp' behaved the same as the new `fixnump'
- (princ object))
- (t
- ;; (message "[tomelr--print-stringlike DBG] %S is string" object)
- (tomelr--print-string str))))
+ (tomelr--print-string str))
(str
(princ str)))))
- [elpa] externals/tomelr 41ccea4ebe 64/84: refactor: Remove unnecessary tomelr-encode-keyword, (continued)
- [elpa] externals/tomelr 41ccea4ebe 64/84: refactor: Remove unnecessary tomelr-encode-keyword, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr 406f4922a8 58/84: test: Add tests for json.el functions used in tomelr, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr b3b6a28d15 68/84: doc: Add more examples, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr f9d670e165 56/84: refactor: Clean up unused code, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr 511240765b 71/84: chore: Ignore .elc files, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr ed13b73e9b 74/84: feat: Support string keys, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr de661716af 72/84: style: Remove space from after and before [ and ] brackets, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr 334b7cba54 76/84: refactor: Don't attempt to triple-quote TOML keys, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr c2d1328c44 80/84: fix: Boolean coercing when value is a symbol true or false, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr ebe5959174 75/84: feat: Auto-coerce string to boolean, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr a676192b43 81/84: fix: Integer coercing of a number strings with underscores,
ELPA Syncer <=
- [elpa] externals/tomelr 8da825067b 15/84: chore(readme): Update, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr 65653d53ee 30/84: chore(doc): M-x checkdoc fixes, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr bcaea16ec0 39/84: chore(doc): Clean up old code block, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr 45542fb234 67/84: chore: Bump version, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr 7c004af90d 66/84: style: Remove unnecessary tomelr-encode-* functions, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr 568de5efb2 83/84: chore: Bump version, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr 0d4674f782 42/84: test: Test `tomelr--toml-table-p`, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr 0eb4fa04ac 43/84: fix: Don't let array of TOML tables be recognized as TOML tables, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr a33dbd1286 50/84: fix: Detect nested TTA correctly when not present in first TT key, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr dc9b2a63f8 60/84: doc: Remove an invalid example, ELPA Syncer, 2022/05/03