Skip to content

Commit cde0d26

Browse files
bug fix for unsafeCodePointAt0Fallback
1 parent 7eac69e commit cde0d26

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/Data/String/CodePoints.purs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,13 @@ foreign import _unsafeCodePointAt0
7777
-> CodePoint
7878

7979
unsafeCodePointAt0Fallback :: String -> CodePoint
80-
unsafeCodePointAt0Fallback s | String.length s == 1 = CodePoint (Unsafe.charCodeAt 0 s)
81-
unsafeCodePointAt0Fallback s = CodePoint (unsurrogate lead trail)
80+
unsafeCodePointAt0Fallback s =
81+
if isLead cu0 && isTrail cu1
82+
then unsurrogate cu0 cu1
83+
else CodePoint cu0
8284
where
83-
lead = Unsafe.charCodeAt 0 s
84-
trail = Unsafe.charCodeAt 1 s
85+
cu0 = Unsafe.charCodeAt 0 s
86+
cu1 = Unsafe.charCodeAt 1 s
8587

8688

8789
codePointAt :: Int -> String -> Maybe CodePoint

0 commit comments

Comments
 (0)