Skip to content

Commit

Permalink
Improve support for scientific counting methods
Browse files Browse the repository at this point in the history
The - and + signs can be used after {E/e}, or directly followed by a number.
  • Loading branch information
rakuyoMo committed Apr 7, 2022
1 parent 62ad615 commit 83d2310
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 2 additions & 1 deletion JSONPreview/Core/JSONLexer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,9 @@ private extension JSONLexer {
} else if first.lowercased() == "e" {
let startIndex = tmpJSON.startIndex
let bounds = startIndex ..< tmpJSON.index(after: startIndex)
let next = tmpJSON[bounds]

if tmpJSON[bounds] == "+" {
if next == "+" || next == "-" || Int(next) != nil {
let second = tmpJSON.removeFirst()
number += (String(first) + String(second))
_first = tmpJSON.removeFirst()
Expand Down
4 changes: 3 additions & 1 deletion JSONPreview/Other/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,10 @@ class ViewController: UIViewController {
"exponential_value": [
1024e+23,
-25e+23,
3.1415926e+23,
-25e-23,
2.54e23,
3.1415926E+23,
3.1415926E-23,
]
},
{
Expand Down

0 comments on commit 83d2310

Please sign in to comment.