Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 4 additions & 11 deletions src/Parse.flix
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
mod Json.Parse {
import java.lang.NumberFormatException
import java.lang.Integer
import java.lang.Character

use Json.JsonElement.{JsonObject, JsonArray, JsonString, JsonNumber, JsonBool, JsonNull}
use Json.JsonElement;
use Option.flatMap;
Expand Down Expand Up @@ -192,9 +188,10 @@ mod Json.Parse {
case '\\' :: 'u' :: c1 :: c2 :: c3 :: c4 :: tail =>
let charRes = forM (
string <- listToString(c1 :: c2 :: c3 :: c4 :: Nil) |> Some;
intVal <- hexToInt(string)
intVal <- hexToInt(string);
chars <- CodePoint.toChars(intVal)
) yield {
unsafe Character.toChars(intVal) |> Array.get(0)
unsafe chars[0]
};
match charRes {
case None => None
Expand All @@ -211,11 +208,7 @@ mod Json.Parse {
}

def hexToInt(hex: String): Option[Int32] = {
try {
Some(Integer.parseInt(hex, 16))
} catch {
case _: NumberFormatException => None
}
Int32.parse(16, hex) |> Result.toOption
}

def number(in: List[Char]): ParseMonad[JsonElement] = match in {
Expand Down
Loading