mirror of
https://github.com/atom/atom.git
synced 2026-02-18 10:31:54 -05:00
Doc text-utils.coffee
This commit is contained in:
@@ -1,18 +1,41 @@
|
||||
### Internal ###
|
||||
|
||||
isHighSurrogate = (string, index) ->
|
||||
0xD800 <= string.charCodeAt(index) <= 0xDBFF
|
||||
|
||||
isLowSurrogate = (string, index) ->
|
||||
0xDC00 <= string.charCodeAt(index) <= 0xDFFF
|
||||
|
||||
### Public ###
|
||||
|
||||
# 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) ->
|
||||
isHighSurrogate(string, index) and isLowSurrogate(string, index + 1)
|
||||
|
||||
# Get the number of characters in the string accounting for surrogate pairs.
|
||||
#
|
||||
# This 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
|
||||
for index in [0...string.length] when isSurrogatePair(string, index)
|
||||
count--
|
||||
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}.
|
||||
hasSurrogatePairs = (string) ->
|
||||
string.length isnt getCharacterCount(string)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user