Skip to content

Commit 71c5156

Browse files
use charCodeAt from Data.String.Unsafe
1 parent c59f340 commit 71c5156

File tree

2 files changed

+4
-11
lines changed

2 files changed

+4
-11
lines changed

src/Data/String/CodePoints.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,6 @@ var hasStringIterator =
1010
var hasFromCodePoint = typeof String.prototype.fromCodePoint === "function";
1111
var hasCodePointAt = typeof String.prototype.codePointAt === "function";
1212

13-
exports._unsafeCharCodeAt = function (i) {
14-
return function (str) {
15-
return str.charCodeAt(i);
16-
};
17-
};
18-
1913
exports._unsafeCodePointAt0 = function (fallback) {
2014
return hasCodePointAt
2115
? function (str) { return str.codePointAt(0); }

src/Data/String/CodePoints.purs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import Data.List (List(Cons, Nil), fromFoldable)
2727
import Data.Maybe (Maybe(Just, Nothing))
2828
import Data.Newtype (class Newtype)
2929
import Data.String as String
30+
import Data.String.Unsafe as Unsafe
3031
-- WARN: This list must be updated to re-export any exports added to Data.String. That makes me sad.
3132
import Data.String (Pattern(..), Replacement(..), charAt, charCodeAt, contains, fromCharArray, joinWith, localeCompare, null, replace, replaceAll, split, stripPrefix, stripSuffix, toChar, toCharArray, toLower, toUpper, trim) as StringReExports
3233
import Data.Tuple (Tuple(Tuple))
@@ -73,13 +74,11 @@ foreign import _unsafeCodePointAt0
7374
-> CodePoint
7475

7576
unsafeCodePointAt0Fallback :: String -> CodePoint
76-
unsafeCodePointAt0Fallback s | String.length s == 1 = CodePoint (_unsafeCharCodeAt 0 s)
77+
unsafeCodePointAt0Fallback s | String.length s == 1 = CodePoint (Unsafe.charCodeAt 0 s)
7778
unsafeCodePointAt0Fallback s = CodePoint (((lead - 0xD800) * 0x400) + (trail - 0xDC00) + 0x10000)
7879
where
79-
lead = _unsafeCharCodeAt 0 s
80-
trail = _unsafeCharCodeAt 1 s
81-
82-
foreign import _unsafeCharCodeAt :: Int -> String -> Int
80+
lead = Unsafe.charCodeAt 0 s
81+
trail = Unsafe.charCodeAt 1 s
8382

8483

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

0 commit comments

Comments
 (0)