Skip to content

Commit

Permalink
Preliminary optimization algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
rakuyoMo committed Apr 7, 2022
1 parent bdbfe5d commit a5b23b0
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions JSONPreview/Core/JSONLexer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -280,21 +280,15 @@ private extension JSONLexer {
if first.isNumber || first == "." {
number += String(first)
_first = tmpJSON.removeFirst()
}

// Scientific counting support
else if first.lowercased() == "e",
let next = tmpJSON.first,
(next == "+" || next == "-" || next.isNumber) {

} else if first.lowercased() == "e" {
let startIndex = tmpJSON.startIndex
let bounds = startIndex ..< tmpJSON.index(after: startIndex)
let next = tmpJSON[bounds]

if next == "+" || next == "-" || Int(next) != nil {
let second = tmpJSON.removeFirst()
number += (String(first) + String(second))
_first = tmpJSON.removeFirst()

} else {
tmpJSON = String(first) + tmpJSON
_first = nil
}
number += (String(first) + String(tmpJSON.removeFirst()))
_first = tmpJSON.removeFirst()

} else {
tmpJSON = String(first) + tmpJSON
Expand Down

0 comments on commit a5b23b0

Please sign in to comment.