Skip to content

Commit 8d6d263

Browse files
add some comments
1 parent e8ca6f3 commit 8d6d263

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/Data/String/CodePoints.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ exports._count = function (isLead) {
7373
exports._fromCodePointArray = function (singleton) {
7474
return hasFromCodePoint
7575
? function (cps) {
76+
// Function.prototype.apply will fail for very large second parameters,
77+
// so we don't use it for arrays with 10KB or more entries.
7678
if (cps.length < 10240) {
7779
return String.fromCodePoint.apply(String, cps);
7880
}

src/Data/String/CodePoints.purs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
-- | These functions allow PureScript strings to be treated as if they were
2+
-- | sequences of Unicode code points instead of their true underlying
3+
-- | implementation (sequences of UTF-16 code units). For nearly all uses of
4+
-- | strings, these functions should be preferred over the ones in Data.String.
15
module Data.String.CodePoints
26
( module StringReExports
37
, CodePoint()
@@ -36,12 +40,17 @@ import Data.Tuple (Tuple(Tuple))
3640
import Data.Unfoldable (unfoldr)
3741

3842

43+
-- | CodePoint is an Int bounded between 0 and 0x10FFFF, corresponding to
44+
-- | Unicode code points.
3945
newtype CodePoint = CodePoint Int
4046

4147
derive instance eqCodePoint :: Eq CodePoint
4248
derive instance ordCodePoint :: Ord CodePoint
4349
derive instance newtypeCodePoint :: Newtype CodePoint _
4450

51+
-- I would prefer that this smart constructor not need to exist and instead
52+
-- CodePoint just implements Enum, but the Enum module already depends on this
53+
-- one. To avoid the circular dependency, we just expose these two functions.
4554
codePointFromInt :: Int -> Maybe CodePoint
4655
codePointFromInt n | 0 <= n && n <= 0x10FFFF = Just (CodePoint n)
4756
codePointFromInt n = Nothing

0 commit comments

Comments
 (0)