Rename hasSurrogatePairs() to hasSurrogatePair()

This commit is contained in:
Kevin Sawicki 2013-06-04 12:12:14 -07:00
parent 7dec3866cf
commit f63866b2a2
3 changed files with 12 additions and 7 deletions

View File

@ -7,6 +7,12 @@ describe 'text utilities', ->
expect(textUtils.getCharacterCount('a\uD835\uDF97b\uD835\uDF97c')).toBe 5
expect(textUtils.getCharacterCount('\uD835\uDF97')).toBe 1
describe '.hasSurrogatePair(string)', ->
it 'returns true when the string contains a surrogate pair', ->
expect(textUtils.hasSurrogatePair('abc')).toBe false
expect(textUtils.hasSurrogatePair('a\uD835\uDF97b\uD835\uDF97c')).toBe true
expect(textUtils.hasSurrogatePair('\uD835\uDF97')).toBe true
describe '.isSurrogatePair(string, index)', ->
it 'returns true when the index is the start of a high/low surrogate pair', ->
expect(textUtils.isSurrogatePair('a\uD835\uDF97b\uD835\uDF97c', 0)).toBe false

View File

@ -4,7 +4,7 @@ textUtils = require 'text-utils'
module.exports =
class Token
value: null
hasSurrogatePairs: false
hasSurrogatePair: false
scopes: null
isAtomic: null
isHardTab: null
@ -14,7 +14,7 @@ class Token
constructor: ({@value, @scopes, @isAtomic, @bufferDelta, @isHardTab}) ->
@screenDelta = @value.length
@bufferDelta ?= @screenDelta
@hasSurrogatePairs = textUtils.hasSurrogatePairs(@value)
@hasSurrogatePair = textUtils.hasSurrogatePair(@value)
### Public ###
@ -30,7 +30,7 @@ class Token
[new Token(value: value1, scopes: @scopes), new Token(value: value2, scopes: @scopes)]
breakOutAtomicTokens: (tabLength, breakOutLeadingWhitespace) ->
if @hasSurrogatePairs
if @hasSurrogatePair
outputTokens = []
for token in @breakOutSurrogatePairs()

View File

@ -27,8 +27,7 @@ isSurrogatePair = (string, index) ->
# Returns a {Number}.
getCharacterCount = (string) ->
count = string.length
for index in [0...string.length] when isSurrogatePair(string, index)
count--
count-- for index in [0...string.length] when isSurrogatePair(string, index)
count
# Does the given string contain at least one surrogate pair?
@ -36,7 +35,7 @@ getCharacterCount = (string) ->
# string - The {String} to check for the presence of surrogate pairs.
#
# Returns a {Boolean}.
hasSurrogatePairs = (string) ->
hasSurrogatePair = (string) ->
string.length isnt getCharacterCount(string)
module.exports = {getCharacterCount, isSurrogatePair, hasSurrogatePairs}
module.exports = {getCharacterCount, isSurrogatePair, hasSurrogatePair}