diff --git a/src/text-utils.coffee b/src/text-utils.coffee index 90bf220ff..f83864106 100644 --- a/src/text-utils.coffee +++ b/src/text-utils.coffee @@ -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? #