FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
atom/src/text-utils.coffee at master · almoral/atom · GitHub
almoral
atom
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
atom
/
src
/
text-utils.coffee
Copy path
More file actions
More file actions
Latest commit
History
History
History
37 lines (32 loc) · 1.24 KB
Breadcrumbs
atom
/
src
/
text-utils.coffee
Copy path
File metadata and controls
37 lines (32 loc) · 1.24 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
isHighSurrogate
=
(
string
,
index
)
->
0xD800
<=
string
.
charCodeAt
(index)
<=
0xDBFF
isLowSurrogate
=
(
string
,
index
)
->
0xDC00
<=
string
.
charCodeAt
(index)
<=
0xDFFF
#
Is the character at the given index the start of a high/low surrogate pair?
#
#
string - The {String} to check for a surrogate pair.
#
index - The {Number} index to look for a surrogate pair at.
#
#
Return a {Boolean}.
isSurrogatePair
=
(
string
,
index
=
0
)
->
isHighSurrogate
(string, index)
and
isLowSurrogate
(string, index
+
1
)
#
Get the number of characters in the string accounting for surrogate pairs.
#
#
This method counts high/low surrogate pairs as a single character and will
#
always returns a value less than or equal to `string.length`.
#
#
string - The {String} to count the number of full characters in.
#
#
Returns a {Number}.
getCharacterCount
=
(
string
)
->
count
=
string
.
length
count
--
for
index
in
[
0
...
string
.
length
]
when
isSurrogatePair
(string, index)
count
#
Does the given string contain at least one surrogate pair?
#
#
string - The {String} to check for the presence of surrogate pairs.
#
#
Returns a {Boolean}.
hasSurrogatePair
=
(
string
)
->
string
.
length
isnt
getCharacterCount
(string)
module
.
exports
=
{getCharacterCount, isSurrogatePair, hasSurrogatePair}
Back
|
FazBrowse Home
|
New Git URL