mirror of
https://github.com/atom/atom.git
synced 2026-01-23 05:48:10 -05:00
Treat combined characters as paired characters
This commit is contained in:
@@ -7,6 +7,13 @@ isLowSurrogate = (string, index) ->
|
||||
isVariationSelector = (string, index) ->
|
||||
0xFE00 <= string.charCodeAt(index) <= 0xFE0F
|
||||
|
||||
isCombiningCharacter = (string, index) ->
|
||||
0x0300 <= string.charCodeAt(index) <= 0x036F or
|
||||
0x1AB0 <= string.charCodeAt(index) <= 0x1AFF or
|
||||
0x1DC0 <= string.charCodeAt(index) <= 0x1DFF or
|
||||
0x20D0 <= string.charCodeAt(index) <= 0x20FF or
|
||||
0xFE20 <= string.charCodeAt(index) <= 0xFE2F
|
||||
|
||||
# Is the character at the given index the start of a high/low surrogate pair?
|
||||
#
|
||||
# * `string` The {String} to check for a surrogate pair.
|
||||
@@ -25,6 +32,15 @@ isSurrogatePair = (string, index=0) ->
|
||||
isVariationSequence = (string, index=0) ->
|
||||
not isVariationSelector(string, index) and isVariationSelector(string, index + 1)
|
||||
|
||||
# Is the character at the given index the start of a combined character pair?
|
||||
#
|
||||
# * `string` The {String} to check for a combined character.
|
||||
# * `index` The {Number} index to look for a variation sequence at.
|
||||
#
|
||||
# Return a {Boolean}.
|
||||
isCombinedCharacter = (string, index=0) ->
|
||||
not isCombiningCharacter(string, index) and isCombiningCharacter(string, index + 1)
|
||||
|
||||
# Is the character at the given index the start of high/low surrogate pair
|
||||
# or a variation sequence?
|
||||
#
|
||||
@@ -33,7 +49,7 @@ isVariationSequence = (string, index=0) ->
|
||||
#
|
||||
# Return a {Boolean}.
|
||||
isPairedCharacter = (string, index=0) ->
|
||||
isSurrogatePair(string, index) or isVariationSequence(string, index)
|
||||
isSurrogatePair(string, index) or isVariationSequence(string, index) or isCombinedCharacter(string, index)
|
||||
|
||||
# Does the given string contain at least surrogate pair or variation sequence?
|
||||
#
|
||||
|
||||
Reference in New Issue
Block a user