This repository was archived by the owner on Oct 5, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +14
-28
lines changed
Expand file tree Collapse file tree 1 file changed +14
-28
lines changed Original file line number Diff line number Diff line change @@ -468,34 +468,20 @@ literalChar =
468468unicode : Parser_ Char
469469unicode =
470470 P . getChompedString ( P . chompWhile Char . isHexDigit)
471- |> P . andThen codeToChar
472-
473-
474- codeToChar : String -> Parser_ Char
475- codeToChar str =
476- let
477- length = String . length str
478- code = String . foldl addHex 0 str
479- in
480- if length < 4 || length > 6 then
481- P . problem InvalidUnicodeCodePoint
482- else if 0 <= code && code <= 0x10FFFF then
483- P . succeed ( Char . fromCode code)
484- else
485- P . problem InvalidUnicodeCodePoint
486-
487-
488- addHex : Char -> Int -> Int
489- addHex char total =
490- let
491- code = Char . toCode char
492- in
493- if 0x30 <= code && code <= 0x39 then
494- 16 * total + ( code - 0x30)
495- else if 0x41 <= code && code <= 0x46 then
496- 16 * total + ( 10 + code - 0x41)
497- else
498- 16 * total + ( 10 + code - 0x61)
471+ |> P . andThen ( \ str ->
472+ let
473+ len = String . length str
474+ in
475+ if len < 4 || len > 6 then
476+ P . problem InvalidUnicodeCodePoint
477+ else
478+ str
479+ |> String . toLower
480+ |> Hex . fromString
481+ |> Result . map Char . fromCode
482+ |> Result . map P . succeed
483+ |> Result . withDefault ( P . problem InvalidUnicodeCodePoint )
484+ )
499485
500486
501487{- | TODO escapes
You can’t perform that action at this time.
0 commit comments